LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Selecting a specific cluster from an array of clusters

Hi all,

 

New user and first time poster.

 

The problem:

 

I'm attempting to use the "build cluster array" VI and then using the "index array" VI to retrieve a specific cluster, thus acting as a multiplexer of sorts. BUT my clusters are of multiple data types, and it seems that only the last cluster inserted into the array is stored or available. I feel like there should be an easy way to accomplish this task, perhaps with varients but I'm not seeing it. Any help - hopefully in as descriptive and step-by-step way as possible because im very new to this language - would be greatly appreciated,

 

Thanks,

 

Kurt

0 Kudos
Message 1 of 11
(3,612 Views)

You can build an array of variants, in which each element is actually a different data type wrapped in a variant envelope.  You cannot, however, use "Build Cluster Array" to do it.  Build Cluster Array lets you build a cluster of arrays, where every array has the same type and dimension but may have a different length.  Instead, you could use "To Variant" to convert each cluster to a variant, and then wire those variants to Build Array.

 

If you post your code it may be easier to provide more specific advice.

0 Kudos
Message 2 of 11
(3,607 Views)

Thanks for the quick reply,

 

I just tried to convert each individual cluster to a variant then added each of these variant elements to an array, of which im hoping to select one of the elements, but I don't know how to "de-variant" the element to get back my cluster. Im trying to use the "variant to data" VI but im not sure what to connect to the data type input, my guess was a cluster constant (created from the original 24 element cluster)...alas that didn't work.

0 Kudos
Message 3 of 11
(3,604 Views)

You do need to use Variant to Data, but, not surprisingly, the type input needs to match the type of the data.  That means it needs to be the same type as the original input cluster.  Since you started with a bunch of different cluster types and combined them into an array of variants, when you try to get the data back you'll need a separate case for each of the original cluster types.  LabVIEW is strictly-typed and doesn't work well with generic data.  If you could post your code, and a description of what you're trying to accomplish, we might be able to suggest a better approach.

0 Kudos
Message 4 of 11
(3,591 Views)

I guess I wasn't specific enough but each original cluster is the exact same size and contains the same order and combination of data types they just refer to different front panel controls and thus can have different values. I just want to select one of these identically structured clusters and pass it through based on a dequeued channel number. What do I wire to the "Variant to Data" type input - the cluster type right - which is all the same 24 element cluster, but how? 

0 Kudos
Message 5 of 11
(3,579 Views)

Please, please, please attach your code, or at least a screenshot of it.  I can't figure out what you mean by "refer to different front panel controls."  Do you mean that's where they obtain their values?  If all the clusters are identical, there's no need for variants at all, you just need to use build array to build an array of them.

0 Kudos
Message 6 of 11
(3,577 Views)

Code Example.JPG

^this is the Variant method which should still work, I simplified it abit, but as you can see the inputs are all the same cluster and I want the channel to select what cluster to use and unbundle.

 

Thanks again for the help nathand 

0 Kudos
Message 7 of 11
(3,569 Views)

If Inputs, Inputs 2, etc are all identical, then remove all the Variant to Data functions (EDIT and the Variant to Data function) and it will work exactly as you want.

0 Kudos
Message 8 of 11
(3,567 Views)

Code Example.JPG

^ So I guess heres my question again with a visual

 

I've clearly asked for the ( 0 ) element in the array which should return "inputs" not "inputs 4" which is what's shown in the picture (returning BatterID Ch3). Is there a 2D array i should be using? 

 

0 Kudos
Message 9 of 11
(3,561 Views)

You're misunderstanding what's happening here.  The names are taken from Inputs (because it's the first element), but the values will be the data you expect.  Does this make sense to you?

Message 10 of 11
(3,554 Views)