From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

Get a cluster element value from a variant

Solved!
Go to solution

Hi

 

I am trying to get a cluster element value from its variant form

 

GetElementValues.png

 

If I look at the variant indicator, the elements and their values are displayed. However, after Get Cluster Information.vi, which I expect to break up the cluster into its individual elements, all I get is the type information, not the value of the element. That is, looking at the Elements array, all that is displayed are 0's, I was expecting values and element names.

 

GetClusterElement_FP.PNG

 

So my question is, how do I get the cluster element values?

 

Thanks

0 Kudos
Message 1 of 16
(9,158 Views)
Solution
Accepted by topic author c_chip

One of my pet peeves is that Flattened String to Variant function does provide the remainder string, but with a bit of ugliness it can be worked around.

 

ClusterValsFromVariant.png

Message 2 of 16
(9,149 Views)

Autotestware Cluster Toolkit 2.0.0.4. You can granulate the 'Variant Data' output to your specificity with the 'Grains' input control. Or use Index Cluster (by Name).vi to return a single element.

 

Get a cluster element value from a variant.png

0 Kudos
Message 3 of 16
(9,135 Views)

Thanks Darin,

 

Unfortunately, I am not able to duplicate your results with the Variant/Flatten kludge. Does the LV 2015 Get Cluster Information.vi differ from your LV 2014 Cluster Info VI?

 

GetElementValues2.png 

 

On a side note, why are variants treated like a secret shame? They are a fundamental part of LV and its only been recently that VIs to handle them were added to the official pallette. It seems to me that my application of them, getting the value from them, seems pretty basic yet the process seems like a kludge. Is there something fundamental in the background that prevents a native implementation of this?

0 Kudos
Message 4 of 16
(9,113 Views)

To AutoTestWare,

 

Thanks for your reply, but I am trying to get a value from a cluster variant not create a variant from a cluster. I looked at your set of cluster tools and did not see one that accomplished this. It is a nice set of tools but not appropriate for this application.

0 Kudos
Message 5 of 16
(9,112 Views)

Is there a reason you wish to avoid the OpenG tools that have been long available?

 

The OpenG LabVIEW Data package contains a VI entitled "Get Cluster Element by Name" (and a LOT of other VIs covering almost any need to handle varying datatypes at runtime).

 

The VIs found in <vi.lib>\Utility\VariantDataType may allow you to get there, though I've far less experience with using them, so I'd need to puzzle through them - they are somewhat "late to the party" vs. the OpenG implementation.  Of course, they are NI-written vs. community-written, so draw your own conclusions.

 

But my first advice would be to fire up your VIPM and grab several of the workhorse OpenG packages.

 

Dave

David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer
Message 6 of 16
(9,107 Views)

@c_chip wrote:

Thanks Darin,

 

Unfortunately, I am not able to duplicate your results with the Variant/Flatten kludge. Does the LV 2015 Get Cluster Information.vi differ from your LV 2014 Cluster Info VI?

 

GetElementValues2.png 

 

On a side note, why are variants treated like a secret shame? They are a fundamental part of LV and its only been recently that VIs to handle them were added to the official pallette. It seems to me that my application of them, getting the value from them, seems pretty basic yet the process seems like a kludge. Is there something fundamental in the background that prevents a native implementation of this?


You need to wire the original variant to the flatten function instead of the output of 'Get Cluster Information'.

0 Kudos
Message 7 of 16
(9,103 Views)

You need to wire the original variant to the flatten function instead of the output of 'Get Cluster Information'.


Aargh! Of course. Thank you. It now works.

0 Kudos
Message 8 of 16
(9,096 Views)

Is there a reason you wish to avoid the OpenG tools that have been long available?

 

The OpenG LabVIEW Data package contains a VI entitled "Get Cluster Element by Name" (and a LOT of other VIs covering almost any need to handle varying datatypes at runtime).


I did look and there wasn't an obvious solution (to me, maybe to others) but after your post, I played with them a bit and found the "Cluster To Array of VData" is a more appropriate choice for my application.

 

Thanks for the input.

0 Kudos
Message 9 of 16
(9,090 Views)

Basically a newbie question but what function do you use to display the values of variant data and element in that rectangle area on the block diagram?

0 Kudos
Message 10 of 16
(8,132 Views)