10-14-2010 08:25 AM
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 !
10-14-2010 08:30 AM
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
10-14-2010 08:31 AM
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
10-14-2010 08:42 AM
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 ?
10-14-2010 08:46 AM
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.
10-14-2010 08:48 AM
I was looking for any other efficient way of doing this but it seems that I still need to use local variables.
Thanks !
10-14-2010 08:52 AM
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.
10-14-2010 12:22 PM
Benchmarks were provided here.
'Control Value Set' (from VI server) did perform surprisingly well.
Felix
10-14-2010 01:18 PM
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.