LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Dr. Damien's Development - Setting Front Panel Controls

LabVIEW 6i introduced control references to allow programmatic control of controls and indicators. Part of this interface is the Value property, which allows the user to set the value of a control or indicator from a location not in the original VI. Unfortunately, this process is slow, since it is a synchronous process. The value of the control must be fully updated and displayed before the property node returns and allows execution to continue. Is there a faster way to do the same thing? Yes!

 

17807iE2074EF98E7DD9CFSet Value property node

 

There are VI methods to set and get the values of controls/indicators on the front panel. Use of these is much faster than using the Value or Value (Signaling) properties. This is because these methods are asynchronous. They set the transfer buffer, but do not wait until the front panel is updated to return. Look for the VI method Control Value»Set in the pull–down list on the VI property node. There are flattened and variant versions. The overhead of converting from a flattened or variant to the actual data type means that these methods are much slower than local variables or using the terminal itself.

 

17809i7F09DDCF6DB31F6D VI Set Control Value method

 

Attached is a small project containing benchmark code which sets a front panel control. In the interest of completeness, I have included benchmarks for setting a terminal, setting a local variable, using the VI method, and using the Value property. Performance is in that order, with the first two being almost indistinguishable on my test machine.

 

Attached code is in LabVIEW 8.2.1 for Windows. The timing functions call into KERNEL32.DLL.

Message 1 of 14
(4,694 Views)

This is great code to have - thanks!

 

This comes down to "how fast is fast enough?". You have to weigh the benefits of using references. Updating the terminal directly or using a Local requires a flat VI, whereas updating then front panel from a VI nested several layers deep requires references or (yeesh) globals. If it takes a millisecond to update an indicator that pertains to a slow process - such as setting a relay - then I'm all for the reference.  

 

p.s. Don't change your code (not worth it) but one confusing thing is the term "Reference" in the enum. I kept thinking this was setting something by reference, when in fact it is getting the baseline.

Richard






0 Kudos
Message 2 of 14
(4,673 Views)

My least favorite thing about the Set Control Value method is that it creates fragile code. You must type the control name perfectly to match the label (one of the very few text-based language SNAFUs inserted into LabVIEW's graphical programming). Also, if you change the label of a terminal in a subVI without remembering to change the string into the Set Control Value, you have broken your code without knowing it (run-time failure, versus being able to catch the error compile time).

 

Finally, for whatever reason, LabVIEW allows terminals - even terminals of the same type - to have the same label. Even empty labels are allowed. This creates an ambiguous scenario where it's indeterminable which control value will be changed by the method (well, I think the control created first is the one to change, but there's no straightforward method for determining which control was created first).

 

The one scenario where Set Control Value is arguably the best method to pass data is when making Fire-and-Forget dynamic calls. That's why I'm a huge proponent of this Idea, which would all but deprecate the Set Control Val method.

 

 

17819i72333EAE890EA8E9

Message 3 of 14
(4,648 Views)

Wow! The snippet renames my controls to be properly unique! Well, here's a screenshot of what I'm looking at. If you test that snippet code, rename all controls to "Numeric" prior to running. And also, change the "This VI" control into a ref constant.

 

17821i0B105AA9534E06C1

0 Kudos
Message 4 of 14
(4,646 Views)

Why couldn't a method in LabVIEW] be developed that works asynchronously, like Ctrl Value Get or Set, but the actual control is defined using a Reference so the code isn't so fragile?

 

I guess as it is now, you could feed a reference to a property node to get its label, then feed that to the Ctrl Value Get or Set.

 

And to answer Jack's question, I am going to guess that whichever control named "numeric" that LabVIEW detects first is the one getting updated.  Whether that is the first is some stack of references, the first created, the last created.  Maybe the even the one that has either the highest or lowest Z value on the front panel.  I really don't know.  And will whichever is first in a given instance of LabVIEW, will it be first again, or could some recompile reshuffle the controls.

0 Kudos
Message 5 of 14
(4,637 Views)

 


Unfortunately, this process is slow, since it is a synchronous process. The value of the control must be fully updated and displayed before the property node returns and allows execution to continuue

Is this statement still true if the DeferFP updates is switched on before doing a bunch of property node updates, and then switched off at the end?

 

0 Kudos
Message 6 of 14
(4,555 Views)

Defer panel updates does not seem to improve the performance of SetValue on single controls very much (10% ?).  See attached VI.  I will see what I can find out about specifics.

0 Kudos
Message 7 of 14
(4,515 Views)

I dont think your benchmark is valid, looks like an effect of constant folding.

 

If you modify your example to use a random number instead of a constant the effect is more like a 100% change.

0 Kudos
Message 8 of 14
(4,436 Views)

I have to get on the road soon so I'll trow out these Q's for thought.

 

1) Does Ctrl.Value.Get run in the UI thread?

 

2) WHen uisng that method prior to starting up a template, is there a possible race condition where teh template can start before the ctrl-value.set executes?

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 14
(4,389 Views)

@Ravens Fan wrote:

 

And to answer Jack's question, I am going to guess that whichever control named "numeric" that LabVIEW detects first is the one getting updated.  Whether that is the first is some stack of references, the first created, the last created.  Maybe the even the one that has either the highest or lowest Z value on the front panel.  I really don't know.  And will whichever is first in a given instance of LabVIEW, will it be first again, or could some recompile reshuffle the controls.


According to the detailed help, the method uses the tabbing order of the front panel objects to locate the control.

Message 10 of 14
(4,322 Views)