LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to set the value of a variable in a cluster in LabVIEW from C#?

Solved!
Go to solution

Hi guys, I'm working on a small c# program, which using the interface provided by LabVIEW.  And I know that, using lv.SetControlValue(name, value) can set a variable just on the front panel. But in my case, there're several clusters on the front panel. So it confused me how to set the variables in these clusters. For example there's a cluster named clusterA, and a variable in it named valueA, I've tried something like this:

lv.SetControlValue("clusterA.valueA",1);

but it totally not work. Anyone has some experience about this stuff? Thanks a lot!! 😄

0 Kudos
Message 1 of 4
(2,741 Views)

I assume the full cluster is the item you can access this way, but i've never tried.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 4
(2,736 Views)

LabVIEW clusters are represented as Typedefs, so you have to declare ClusterA as the typedef you define.

Machine Vision, Robotics, Embedded Systems, Surveillance

www.movimed.com - Custom Imaging Solutions
0 Kudos
Message 3 of 4
(2,725 Views)
Solution
Accepted by topic author Ray_OPG

Hey guys, thanks a lot for all your reply. I just find a simply way to solve this porblem. For example, there a cluster named "ClusterA", and there are only two control values in it, which are: an int value named "IntA" (default value IntA = 10)and a  string value named "StringA" (default value StringA = "abc"). In C# if you invoke the method:

 

var clusterA = (Array) vi.GetControlValue("ClusterA");

 

you will get an Array looks like: clusterA = {10, "abc"}; Then if you want to change IntA to 123, you just need to do:

 

clusterA.SetValue(123, 0); // 123 is the value, 0 is the index of IntA in the array clusterA, after this clusterA = {123, "abc"}

 

After this, you just need to give the array back to LabVIEW by using:

 

vi.SetControlValue("ClusterA", clusterA);

 

and now see the panel in you LabVIEW, the IntA is changed.

0 Kudos
Message 4 of 4
(2,701 Views)