LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

sub-vi from event handler updating front panel object

I am trying to updating front panel led's from sub-vi in event handler in while loop. After the event triggers the sub-vi it executes and updates but led are not changing on the front panel. Thanks 
0 Kudos
Message 1 of 8
(3,335 Views)
Try using a reference to the front panel conrtol in the subVI.  this can be done by right clicking on the LED indicator, select Create > Reference.  From the terminal on the reference, right click and select Create > Property Node > Value.  Cut and paste this property node into your SubVI.  Right click the property node and select Change All to Write.  Then you can right click the upper left terminal on the property node and select Create Control.  Wire the control you just created to a connector on the SubVI (right click the VI icon and slect show copnnector).  Then you can go back to the main VI and wire the reference you created to the terminal on the SubVI Icon.

I attached vi's that demonstrate this.

Post any more questions you might have.

Kenny
Kenny

Download All
0 Kudos
Message 2 of 8
(3,320 Views)
Thanks! How reference different from variables to make this work?
0 Kudos
Message 3 of 8
(3,316 Views)
I will probably get the "lingo" screwed up, maybe someone with more official programming experience can explain it in more technical terms.
 
But what I have learned and read on the forums, is that references are much nicer than varibales (global), in that they requiore much less memory and computing power when dealing with transfereing data to and from subvis.  Also, local variaables cannot be used to transfer data from a subvi in "real time".  Globals can be tricky (in my experience) to get data to transfer from a subvi to a main VI.
 
References can pass data from a subvi in real time, which makes it ideal for this stype of situation and they are very simple to implement.
 
Sorry if it is not a great explaination.
 
Kenny
Kenny

0 Kudos
Message 4 of 8
(3,309 Views)
mchips>> Thanks! How reference different from variables to make this work?
 
It's the difference between "call by value" and "call by reference."
 
I assume you were wiring your front-panel LEDs directly to your subVI. If that's the case, what your subVI updates is a local copy of the LEDs. (That method of parameter passing is known as "call by value.") Updating the local copy of the front-panel LEDs had no effect on the front panel of the main VI.
 
If you pass in a reference to your LEDs, and update the reference's Value property, you are updating the object "pointed to" or "referred to" or "referenced by" the reference. That object is your front-panel LEDs (cluster or whatever it actually is)--not a local copy but the actual LEDs the user sees. That "call by reference" method ensures that your front-panel LEDs get updated in "real time"--as fast as the subVI can operate, or close to it.
 
::Marty
0 Kudos
Message 5 of 8
(3,307 Views)
Thanks for info. In other programming languages, global variable should work in this case. Why global does not work in LabVIEW in this case?
0 Kudos
Message 6 of 8
(3,304 Views)
Kenny K>> But what I have learned and read on the forums, is that references are much nicer than varibales (global), in that they requiore much less memory and computing power when dealing with transfereing data to and from subvis.  Also, local variaables cannot be used to transfer data from a subvi in "real time".  Globals can be tricky (in my experience) to get data to transfer from a subvi to a main VI.
 
References can pass data from a subvi in real time, which makes it ideal for this stype of situation and they are very simple to implement.
 
I agree.
 
In this particular case, with the front-panel LEDs etc., it's possible to update in real time by writing the Value property of a global reference to the LEDs. The only benefit to doing this is that you don't have to wire the reference to the subVI. The drawbacks are worse. Rather than use a global reference, in general it's better to wire the reference, even if you already have a cluttered diagram.
 
Better still, usually, to store references to front-panel objects within a subVI that's responsible for managing one or more front-panel items. This is the "functional global" concept. You pass in the reference at the first call to the subVI ("Initialize" step). The reference is stored in a shift register within the subVI. The value of the shift register persists as long as the subVI is in memory; that is, it persists across calls to the subVI (unless the subVI isn't in memory, e.g. if it's called only with an Invoke Node or whatever). Then, to update whatever the reference points to, pass in enumerated values, or strings, to the subVI that stores the reference. Each of those enumerated or string inputs is a mnemonic for an action. Like, "Hide" could tell the subVI to set the Visible property of the appropriate reference to False.
 
(In C/C++ terms, the shift register in the subVI is a type of static variable.)
 
The functional-global solution minimizes wiring, abstracts data, and can maintain state information internally. So "functional global" is a term that doesn't do justice to the idea. But the term is widely used and I haven't thought of a better one....
 
::Marty
0 Kudos
Message 7 of 8
(3,301 Views)
mchips>> Thanks for info. In other programming languages, global variable should work in this case. Why global does not work in LabVIEW in this case?
 
There's no way to make a front-panel object into a global variable in the way you seem to mean.
 
On your front panel, you can have an array or cluster full of LEDs. You can create one or more global variables that contain a bunch of booleans (True/False values). You can update the global booleans in a subVI, but you can't update your actual LEDs from the booleans without explicitly wiring the globals to the actual LEDs. And without references (whether they're global references, or references passed to the subVI), the actual LEDs won't update in real time.
 
::Marty
0 Kudos
Message 8 of 8
(3,298 Views)