LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use the Variant Attribute Get Function

Solved!
Go to solution

Hi,

I would like to know how to use the get variant attributes function.

 

When I run the attached vi, I expect to see the contents of the "cluster" controller in the "name" and "value" indicators.

But nothing is displayed.

 

Expected value

Name"→{"Numeric", "Boolean", "String"}

Value"→{0,FALSE,""}

 

■Reference

What I would like to do eventually is to read/write values via reference to controllers in other VIs.

However, in the case of clusters, I am having trouble obtaining what the constituent elements are.

(except for clusters, I get the class name of the controller to check)

 

The flattened string seems to give me the information I need, but the internal representation seems a bit unwieldy.

I think it would be easier if I could get the information in the same way as it is displayed in the "variant" indicator.

I thought that the Variant Attribute Get function could do such a thing, but I don't know how to use it, so I am asking this question.

 

I would appreciate it if you could tell me if there is a better way other than using the function to get variant attributes.
Thank you in advance.

0 Kudos
Message 1 of 19
(3,008 Views)

Here is a screenshot of the block diagram and front panel.
Thanks in advance.

cluster2variant.png

0 Kudos
Message 2 of 19
(2,979 Views)

There are no variant attributes in your variant... What you see is values.

 

There won't be any variant attributes in a variant, unless you put them there with set variant attribute.

 

If you want the data elements of a cluster use this:

wiebeCARYA_0-1663059132045.png

Be warned: going back (data elements to a cluster) is a very more difficult...  

Message 3 of 19
(2,965 Views)
Solution
Accepted by yuma_ysd

Hi yuma,

 

Variant attributes are a way of storing a key-value map inside a variant, which has nothing to do with cluster elements. So this is why you see empty arrays out of the "Get Variant Attribute" function.

 

To generically access the elements of a variant cluster, you can use the function "Cluster to Array of VData" from the VIPM toolkit "OpenG Toolkit":

 

raphschru_1-1663059611968.png

raphschru_0-1663059566964.png

0 Kudos
Message 4 of 19
(2,960 Views)

->wiebe@CARYA

 

Thank you for your detailed explanation.

Your advice helped me to do the readout.
I really appreciate it.

 

But I also want to write.
Am I correct in recognizing that it is difficult but possible?
Can you tell me about writing as well?

 

Thank you in advance.

0 Kudos
Message 5 of 19
(2,950 Views)

Hi raphschru,

 

Thank you for the information which looks very useful.
I will give it a try.
I will report back if I make any progress.

 

Thank you.

0 Kudos
Message 6 of 19
(2,943 Views)

You can use the function "Array of VData to VCluster" from the same toolkit to recompose the variant cluster.

0 Kudos
Message 7 of 19
(2,934 Views)

Without that toolkit, you need to concatenate flattened data of the individual elements:

 

wiebeCARYA_0-1663062605967.png

 

Message 8 of 19
(2,930 Views)

What specific problem are you trying to solve? For the moment forget about clusters or variants and simply describe what exactly you are trying to accomplish with your code. There may be more appropriate ways to accomplish your end goal than the path you are currently taking.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 9 of 19
(2,885 Views)

Thanks for your reply.
It certainly sounds like a lot of work.
I will try the toolkit first.

0 Kudos
Message 10 of 19
(2,860 Views)