LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Variant to integer or double

Solved!
Go to solution

Hello!

 

I want to construct a subvi which takes an arbitrary number of parameters of varying data types. My current approach is to let the parameters be bundled into a cluster that is then parsed in a loop:

 

 

 

SubVI taking arbitrary parameters

 

"Cluster" is a test cluster, "String" and "Digital" are indicators for checking values. The event structure is there for stepping through the loop.

 

My problem is that I need a way to discern between integers and doubles, but when I extract them from the cluster they're both represented as "digital".

 

Is there an easier solution that I've missed?

 

 

Lars Melander
Uppsala Database Laboratory, Uppsala University
0 Kudos
Message 1 of 6
(9,389 Views)

LabVIEW is a strictly-typed language so there's no good way to handle generic data.

 

That said, you can determine the type of data stored in a variant using the tools found in vi.lib\utility\VariantDataType\VariantType.lib (available since LabVIEW 8.2 or so).  Instead of using a reference to get at the controls in the cluster, you use GetClusterInfo to get an array of variants, each representing one item in the cluster, then loop through that array and use GetTypeInfo to determine the type of data it contains.

Message 2 of 6
(9,380 Views)
Solution
Accepted by topic author LarsM

Use type descriptors. Look up type descriptors in labview help. Then use properties nodes to get the type descriptors for each control.

 

Example.png

 

Tim
GHSP
Message 3 of 6
(9,368 Views)

Thank you for your quick answers. I couldn't get the GetClusterInfo VI to work, but using type descriptors sort of worked. Since there are so many different descriptors, I chose to adapt my current version. It's not perfect but does the job:

 

New solution

 

This way I don't have to do a bunch of manual, cryptic decoding. If the class is "Digital", I check the type string.

 

If you have any more comments, they're much appreciated. Otherwise I have a solution now that I'm happy with.

Lars Melander
Uppsala Database Laboratory, Uppsala University
Message 4 of 6
(9,344 Views)

I should have checked a bit more carefully - I didn't realize that going through GetClusterInfo you lose the values and only have the data type.  However, you might find it easier to use GetTypeInfo on the variant coming out of the property node to determine its type.

 

Also, check out the Read/Write Anything VIs from Moore Good Ideas, which includes code that converts a cluster into an array of variants with data.  A few of the VIs are password protected but appear to duplicate functions found in the VariantDataType library.

Message 5 of 6
(9,328 Views)

OK, thank you.

Lars Melander
Uppsala Database Laboratory, Uppsala University
0 Kudos
Message 6 of 6
(9,323 Views)