LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Efficient way to change value of a control

Hi,

 

I would like to know what is the most efficient way to change the value of a front panel control.

 

I have an "OK" button (with default value set to False). When the users presses the button, the value changes to True. However, I would like to set it right after to False.

 

I know that property nodes are not really efficient (always updating the front panel) and I don't like local variables because te dataflow is broken (and because LabVIEW makes a copy for each local variable).

 

What is your way for this ?

 

Thanks !

 

0 Kudos
Message 1 of 9
(5,934 Views)

Right-click on the control and navigate to Mechanical Action and choose one of the Latch Options on there. The best way to know what exactly the mechanical actions do is to open up Example Finder (Help -> Find Examples ) and then search for the Mechanical Action of Booleans.vi

Adnan Zafar
Certified LabVIEW Architect
Coleman Technologies
0 Kudos
Message 2 of 9
(5,928 Views)

If you use the Latch mechanical action, the button will reset after it is read by the program.  To make sure that it is read, put the terminal in a loop which will be iterating whenever the button might be pressed.

 

Typically the event structure is used for reading user inputs. Put the terminal inside the Value Changed event case for the control.

 

If for some reason you cannot poll the switch or place it in an event structure, the local variable is probably the appropriate choice.  As you are aware there are good reasons to minimize the use of local variables, but this is one place where using one may be the best choice.

 

Lynn

0 Kudos
Message 3 of 9
(5,926 Views)

I will try with a different mechanical action or with an event structure.

 

And what about another kind of control, for example a string control ? How to programmatically change its value ?

0 Kudos
Message 4 of 9
(5,909 Views)

You use the Value property or you use a local variable. Both of these are explained in the LabVIEW Help and in the LabVIEW tutorials. Watch how you use local variables as it's VERY easy to create race conditions.

 

 

To learn more about LabVIEW it is recommended that you go through the introduction material, tutorial(s), and other material in the NI Developer Zone's Learning Center which provides links to other materials and other tutorials. You can also take the online courses for free.

0 Kudos
Message 5 of 9
(5,903 Views)

I was looking for any other efficient way of doing this but it seems that I still need to use local variables.

 

Thanks !

0 Kudos
Message 6 of 9
(5,899 Views)

The local variable is the most efficient way of changing the value of a control in terms of speed. It simply has its downsides as I noted. The Value property node causes a thread swap to the User Interface thread, so it's much slower. You could also use the VI server, but that's going to be glacial in comparison.

0 Kudos
Message 7 of 9
(5,894 Views)

Benchmarks were provided here.

'Control Value Set' (from VI server) did perform surprisingly well.

 

Felix

0 Kudos
Message 8 of 9
(5,858 Views)

I was also taking into account the time for the Open VI Reference operation, though in this case it wouldn't be necessary. One interesting thing about that benchmark is that I found the results to be all over the place. When I have some time I'll have to take a look at the values using a large enough sample to see if there's a distribution for them.

0 Kudos
Message 9 of 9
(5,843 Views)