From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

get cluster element control index by name

Solved!
Go to solution

Is it possible to use "Get Control Index by Name", to set a Cluster item/element? I would need a way to input a name identifying the cluster element via the cluster name. Discrete cluster name or discrete cluster element name is not the issue. Is there some format of text used to identify a cluster item .->(member or pointer) to an element (like in programming a car object items use the dot "car.tires" "car->engine"....

 

Rich J

0 Kudos
Message 1 of 11
(6,648 Views)

OK, my answers appear to come to me after I post...

 

Using a name directly is not implemented for a cluster element. Instead get the Ctrl[] property of the cluster and use "ControlIndex" property gives you the Index of the cluster element...

 

Rich J

0 Kudos
Message 2 of 11
(6,644 Views)

You can build an array of control and name/index pairs by recursively traversing the front panel for all controls if you need to look up a specific control reference by name.  You would want to make sure all cluster and element names are unique throughout the front panel if you just use their names however. 

 

You can also just right click a cluster element from the front panel to create a static reference to that control if you just need a few elements.

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

Yup, that's what I typically do, build a list of names and index for controls I want to read write.

 

My suggestion didn't solve my problem, the To More Specific function cannot be completed. I'm going from VI Ref to Strict Cluster Ref (I probably need to take a ref step in between), to get to Ctrl[].

 

So question still remains, can I set/get a Cluster element with Set/Get Ctrl by Index? I have 2 VI running, I'm attempting to update the first VI with control settings of the 2nd VI so that they are in agreement.

 

Rich J

0 Kudos
Message 4 of 11
(6,599 Views)

Yes you can get or set the value of a control or indicator in a cluster by reference. Without code I'm not sure what the problem is, but you should just be able to get the reference to the cluster, then the array of references to the controls/indicators in the cluster and to know which element of that array corresponds to each control/indicator in the cluster. 

0 Kudos
Message 5 of 11
(6,581 Views)

I'm looking to use "Set Ctrl by Index", the control is inside a cluster. After fixing my error, I've now determined it is not possible since I get "Error 1629 - the control must have a terminal on the BD". "Set/Get By Index" can be used for the cluster (it connects on the BD) not cluster elements. Probably not a big performance hit if I Read and Set the whole Cluster by Index.

0 Kudos
Message 6 of 11
(6,578 Views)

Sometimes I will reference an element of a cluster by name if I think the cluster will change in the future such that the control indices will change.  Neither way is bullet-proof though, as far as scalability goes.  (What happens if the name of the element changes, for example?)

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 11
(6,570 Views)

@richjoh wrote:

I'm looking to use "Set Ctrl by Index", the control is inside a cluster. After fixing my error, I've now determined it is not possible since I get "Error 1629 - the control must have a terminal on the BD". "Set/Get By Index" can be used for the cluster (it connects on the BD) not cluster elements. Probably not a big performance hit if I Read and Set the whole Cluster by Index.


If you are just trying to change the value (or limit or other property) of a control or indicator in a cluster, what I mentioned before is a way to do this. Is there a reason you need to use the "Set Ctrl by Index" function?

0 Kudos
Message 8 of 11
(6,569 Views)

I learn something new (almost) every time I browse the Forum.  I was unaware of the Get/Set Control Values by Index, and now that I've read about them, I don't understand why one would use them.  Of course, no code employing them (even if it generated errors) was provided, so I've yet to see this function in context.  Is it something with VI Server?  Under what circumstances would you want to use such a function?

 

Bob Schor

0 Kudos
Message 9 of 11
(6,564 Views)
Solution
Accepted by topic author richjoh

Rich,

> So question still remains, can I set/get a Cluster element with Set/Get Ctrl by Index?

 

No, you can not set or get an "element" of a cluster with these functions.

The item being addressed has to have a terminal on the block diagram.

You must read/write the whole cluster.

 

Bob,


@Bob_Schor wrote:

I was unaware of the Get/Set Control Values by Index, and now that I've read about them, I don't understand why one would use them. Of course, no code employing them (even if it generated errors) was provided, so I've yet to see this function in context. Under what circumstances would you want to use such a function?

Bob Schor


These functions allow reading and writing FP objects remotely (or locally) without switching to the UI thread.

This is a big deal for large applications.

In a current project, I'm updating 198 FP indicators (booleans, doubles, rings) from a subvi in 1 ms.

It takes extra programming, but the benefits are certainly worth it.

 

steve

--------------------------------------------------------------------------------------------------------------------------
Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
question. Give "Kudos" to replies that help.
--------------------------------------------------------------------------------------------------------------------------
Message 10 of 11
(6,547 Views)