‎09-23-2013 05:24 PM - edited ‎09-23-2013 05:27 PM
I have a cluster of references to 100+ front panel indicators (some boolean, some double), and I'd like to write values to the digital ones programmatically in a for loop. I have an array of strings values that match the cluster digital control labels, and a matching array of doubles that I'd like to write to the appropriate indicators. Is there a good way to do this? Ideally I would be able to "unbundle by name" with a variable string input for the name.
Thanks in advance!
‎09-23-2013 05:43 PM
You must have one huge bundle somewhere to package all those references. You cannot programmatically unbundle by name. There are a couple of other things you could do that might work, though.
First, if the only thing you need to set through the reference is the value, you could use the Set Control Value method (of a VI, using an invoke node) to set the value using the name of the control, since you already have that. This eliminates the need for the reference cluster.
Can you restructure your cluster so that it contains two sub-clusters, one containing the references for the booleans and the other the references to the numerics? Then you can use cluster to array, and loop through the array, checking the name of each reference until you find the one you want. Even better, do the conversion to an array once when your code starts up and generate an array containing the labels of the controls referenced in the cluster, in the correct order. Then, when you want to reference a particular item, you do a Search 1D Array within that array for the string, which gives you an index. Convert the reference cluster to an array and index out the desired reference.
Personally I hate dealing with large numbers of references after spending years dealing with an existing codebase that relied too heavily on them. There were two clusters passed to almost every function, one containing references and the other containing values. It was expected that the programmer would update both simultaneously but it was very easy to forget, and caused unusual behavior when the value on the screen didn't match the one that was being used for calculations. Since then I try to avoid structuring my code in a way that involves generating a huge cluster of references.
‎09-23-2013 06:04 PM
Thanks for the input. I think I'll break my cluster down by type and give that a try, since I do want to do more than simply update the values. I appreciate the help!
‎09-24-2013 02:33 AM
Breaking up the cluster is a could idea.
Check OpenG (available via VI Package manager) they have VIs to select cluster elements by name.
But it is all very time consuming. So a pre selection is definitly advised.
Gabi