LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to update a single control in a cluster, referenced by index?

Solved!
Go to solution

Hi,

I'd like to programmatically change control values in a cluster, referencing the controls by index (alternatively by control label). The attached code works, but seems ridiculously complex for such a simple task.  I'm sure there's a better way.  Any suggestions would be appreciated. 

Thanks,

Martin

 

0 Kudos
Message 1 of 5
(2,304 Views)
Solution
Accepted by topic author mdebrecz

If you don't mind using toolkits, there is one available on VIPM called, of all things, Cluster Toolkit. Many functions available including one to index a cluster by element.  I've never had a need to use this toolkit so I can't speak to the quality of the VIs. 

2019-05-08_14-52-49.png

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 2 of 5
(2,289 Views)

@mdebrecz wrote:

The attached code works, but seems ridiculously complex for such a simple task.


This entire thing just does not smell right. "Coeffs out" is an indicator, so how does it ever gets it's initial values? (and if you would configure the VI to "clear indicators when called", all's lost. Can you explain the logic and use case for all this.

 

How generic should that tool be? Since the clusters are strictly typed, you might as well do a simple explicit solution that keeps the unchanged output values in a feedback node, for example. Here's one idea.

 

ChangeOneByIndex.png

 

0 Kudos
Message 3 of 5
(2,271 Views)

Thanks aputnam! I installed the Cluster Toolkit (thanks Autotestware!), and tried out the "Get or Set Cluster Element". It worked nicely as a drop-in replacement for my clumsy code. 

 

Martin

0 Kudos
Message 4 of 5
(2,263 Views)

@altenbach wrote:

@mdebrecz wrote:

The attached code works, but seems ridiculously complex for such a simple task.


This entire thing just does not smell right. "Coeffs out" is an indicator, so

Thanks for weighing in altenbach (and I have to agree about the malodorous code ;).  The cluster in my actual use case contains about 40 different controls, so I was hoping to avoid having to create a case structure to handle each control (which I should have mentioned initially).  The actual program I'm working on is for reading/writing coefficients from/to instrument memory.  There is a enum selector for the different coefficients.  All coefficients other than the selected one are hidden from the user.  The user can read the coefficients to/from file and/or edit them within the cluster.  I'm creating an object for each command that is a child of a generic command, so that I can call a generic read or write and override that with the specific coefficient read/write.  I'm sending the corresponding control value (as a variant) to the read/write call - thus the need to read/write to the specific controls within the cluster.  

0 Kudos
Message 5 of 5
(2,260 Views)