From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to write/read ENUM as TDMS Property?

Solved!
Go to solution

LV2103, Win7

 

Old hand at LabVIEW, brand new to DIAdem.

 

I need to convert a structure of arbitrary complexity into properties, suitable for writing to a TDMS file, in such a way as to be retrievable, and (hopefully) to be human-readable, such as whn the file is loaded into DIAdem.

 

I have most of it working just fine, but I have trouble with ENUMs.

 

An ENUM can be converted to a VARIANT just fine, but writing that variant to a file produces error -68007.

A simple test shows this:

Snag.PNG

 

 

The encoding process is fairly simple - given a generic control Ref, just look at its CLASS ID.

If the ID is one of the basic ones, just get its value as a variant, and append to the NAME and PROPERTY arrays:

Encode 1.PNG

 

 

If the item is a CLUSTER, then just get the controls within it, and do them one by one:

Encode 2.PNG

 

 

If the control is an ARRAY, then it's a bit more trouble.  Since there is no way to get a reference to an arbitrary reference, you have to use the one reference to an element that you have.  To use that, you have to be showing one and only one element.  So this code does that, while restoring the original view:

Encode 3.PNG

 

 

HOWEVER

 

 

The ENUM, as I said earler, converts to VARIANT just fine, but TDMS will not accept it.

 

Here's one technique that works, sort of:

Encode 4.PNG

 

By converting the enum to an I32, you get the numeric value of its current setting, and can put that into a variant.

 

When reading, the numeric value will set the ENUM control correctly, so that's good.

 

The trouble is, in DIAdem, the property will look like:

Whatever_Engine_Cycle        2

 

While that is true, and will read back OK, it doesn't tell the user what kind of cycle it was.

 

The point of ENUMS was to put names on specific numbers.

 

I tried converting the variant to a STRING instead of an I32, but error 1057 (IIRC) happens: "cannot convert variant to specified type".

 

 

A similar issue exists for TEXT RING controls - although they will go through the process without error, what shows up is a number.

 

Any ideas for making DIAdem display the ENUM's string value, instead of a number?

 

The error says "not recognized by this version of LabVIEW" - is LV2015 any smarter about this?

 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 1 of 8
(4,425 Views)
Solution
Accepted by topic author CoastalMaineBird

Nice clear post! let's try for a elegant solution.  I think you are half-way there!

 

You know from the Class ID its an enum  so cast the generic to enum

Example_VI.png

 

This may not work with type-defs I'll leave that to you.  Rings and text rings can be handled simillar

 

Edit: Obviously cast string to variant 


"Should be" isn't "Is" -Jay
Message 2 of 8
(4,410 Views)

I take what I said about rings  They will be tougher since you will also need to find the display format to wire to the Variant to Data function. (Yeah, Rings can be floating point so an I32 ins't always right)


"Should be" isn't "Is" -Jay
0 Kudos
Message 3 of 8
(4,402 Views)

You know from the Class ID its an enum  so cast the generic to enum

 

DUH !  ( slaps head )

 

I danced around with that earlier, but I was thinking that the strings wouldn't survive a downcast from ENUM ref to CONTROL ref.

 

Of course, that's not the case - It's just the REFERENCE that changes.   If you convert it back to generic ENUM, then you can treat it like a generic ENUM.

 

Thanks, Jeff !

 

For completeness, here is my ENCODING code (enum ---> property):

Encode 7.PNG

 

 

On the other side, we do something similar:

Decode 1.PNG

 

Works like a charm.

 

Thanks again, Jeff!

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 4 of 8
(4,385 Views)

For the record, the VALUE variant of an enum includes the possible strings, as evidenced in the original post above.

If you FLATTEN that into a STRING, you also get a DATA TYPE output (array of U16).

If you case THAT into [U8}, and then into STRING, you can see that all the possible strings are in there.

The DATA STRING out of the unflatten encodes the current value.

 

Still, using that would involve parsing out the TYPE STRING stuff, probably not a good plan.  Unless that's documented by NI somewhere.

 

 

 Encode 6.PNG

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 5 of 8
(4,376 Views)

Just as an asside

This might help too

Capture.PNG

The hidden gems variant sub-pallate may have a few more tricks for you Steve.


"Should be" isn't "Is" -Jay
0 Kudos
Message 6 of 8
(4,367 Views)

Another tip:

 

Instead of casting to an ENUM, or to a RING, cast to a NAMED NUMERIC, which is a parent class of those two.

Then the same code can handle both ENUM and RING.

 

 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 7 of 8
(4,351 Views)

Old thread I know, but I have a need to read and write Enums to TDMS Properties and was surprised to see that wasn't supported so I made an Idea Exchange post asking for native support.  Over there I gave a basic example on how this can be done by setting/getting the string value.  Go vote for it if you want this feature implemented.

0 Kudos
Message 8 of 8
(2,861 Views)