LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Iterating through unknown cluster attributes

Solved!
Go to solution

Hi,

I'm trying to write a VI that revieces an unkown cluster (it should work with any cluster) and iterates through it's attributes,

for each attribute I execute different commands depending on the type.

I have tried to work with variants but I couldn't get the actual values of the cluster attributes (only type and name).

What would you recommend using for a VI like that?

Thank you!

0 Kudos
Message 1 of 21
(5,316 Views)

I am not sure if your question makes sense for LV. You are aware that a cluster is container for elements which defined during edit time, but static for execution? That means that you cannot encounter "an unknown cluster" in your application.

 

That being said, i assume that you try to create a flexible data type which can have different configurations of elements (not attributes!).

My feeling is that you are essentially looking for LVOOP, however, you have to implement all kinds of possible data structure setups beforehand.

 

The question implies that you store everything in variants currently and use variant attributes to extend the data set. This is unique to variants (unless looking into some custom data frameworks). What is your motiviation to get away from that if you look for exactly this flexibility?

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 2 of 21
(5,308 Views)

Hi Guym,

 

- Why is the cluster "unknown" to your VI?

- What are "attributes" of the cluster? Clusters have elements and properties, variants have attributes…

- What is the "type of the attribute"?

 

I have tried to work with variants but I couldn't get the actual values of the cluster attributes (only type and name).

So you already got the "attribute type and name"? What else do you need according to your description?

 

As you see your message raises more questions as we can answer!

Please provide an example (VI!) and explain as best as possible, what you really want to achieve!

 

Edit:

You see Norbert has the very same questions on your post than me. Guess why…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 21
(5,306 Views)

It appears that I didn't describe the problem correctly.

I will start from the beggining,

I have a few statecharts and each of them has an output cluster which contains data about it's internal operations.

I want to take this cluster and send it's elements (sorry for that) through network tables. (The actual sending is not the problem)

The problem is that the VIs that send the data are each for a specific type so I need to unbundle the cluster and send them one by one depending on the type of each element.

I thought that it would be very nice to have a vi that can handle any type of cluster and just send the elements by their name.

 

My lastest try was to convert the clusters to variants and go on from there but the actual values get lost in the way (I guess I don't understand what variants are supposed to do).

 

If it helps I have a type definition for each of those clusters, but I'm looking for a generic solution so that it would send any new element that is added to the cluster without any special care to the sending VI.

 

Thank you 🙂

 

0 Kudos
Message 4 of 21
(5,293 Views)

One of the reasons it is so helpful (for us to help you) to have you post code is it tells us (among other things) what Version of LabVIEW you are using.  In LabVIEW 2015, for example, in the Variant Palette is the Get Cluster Information function that returns an Array of Variants for the elements in the Cluster.  You can use Get Type Information on this Array to get the Types of all of the Cluster Elements, as well as their Names and whether or not they have an associated Type Def.

 

If you have an earlier Version of LabVIEW (I don't think this was in LabVIEW 2014), see if Hidden Gems in VILib is available for your LabVIEW Version on the NI Tools Network -- it provides access to these "hidden" functions.

 

Bob Schor

0 Kudos
Message 5 of 21
(5,276 Views)

I do have LabVIEW 2015 and I have tried to use the VI you mentioned but I couldn't get the values of the elements with it.

I have attached the code,

I get the right name of the element but the value is always zero,

when probing I noticed that the "Get cluster Information" doesn't pass the values and resets every value to default.

Is there a way to use the original variant in order to get the original value?

 

0 Kudos
Message 6 of 21
(5,266 Views)

I think I have manged to make a working solution using refrences,

Can you please take a look and tell me if this is the right way to do it? Is there a way to make it more "clean"?

 

In the caller vi I make an indicator of the cluster and then create a refrence to it, this is passed to the vi for processing.

both are attached.

 

Thank you

Download All
0 Kudos
Message 7 of 21
(5,260 Views)

You may want to review this Nugget and the thread that follows that Nugget.

 

That Nugget was written for LV 8.2 but in theory should still be valid. It ws written prior to the new addtions mentioned above to query cluster elemements. The follow-up posts also suggests alternative add-ons you can use.

 

Finally...

 

If the network comm is between LV applications, VI Server will allow invoking a target VI on one from a VI running on another node. In that case the work required to transfer the cluster contents is built into LV and we do not have to deal with changes to the data structures when code is updated.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 8 of 21
(5,242 Views)

Maybe this will help

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 9 of 21
(5,231 Views)

Sorry I didn't get back to you earlier (work intruded).

 

By now, you've probably figured out how to use the 2015 Variant functions to learn the Type of each Cluster element and the Name of the Element.  Just in case, here's a snippet:

Cluster Explorer.png

If you now want to get the value of each Cluster element, you need to be able to deal with the fact that each element may be a different type, so your output will need to be something that is "type-invariant", such as a Variant or a string representation.  Your PNG (oooh, I hate "pictures" of code -- why not post a Snippet, which is at least executable, or the VI itself?) shows you are more-or-less on the right track.

 

But it isn't simple -- there are about forty different Types in the Type Enum.  I presume you know that if you wire an Enum to a Case selector, you can tell the Case Statement to "Add Case for Every Value" and auto-populate the Case choices, right?  Then it is simply a matter of putting 40 or so Variant to Data functions and doing something with the 40 different values that are allowed.

Variant Decode.png

Bob Schor

Message 10 of 21
(5,203 Views)