LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can we (without globals) update a local variable from a currently running subvi?

I have a subvi that I wish to have running continuously in a separate thread during the entire main execution.  The problem that I am having is that I want to update a local variable from the subvi periodically, and the only way I know how to do that is with globals (which would reduce portability of code).  Is there any other way to periodically update the calling vi from a subvi?
 
Thanks,
Sean
0 Kudos
Message 1 of 6
(3,358 Views)
There's several ways you can do it, it depends greatly on your code:

1.  Pass a reference to the variable to the subVI and use the Value or Value (Signaling) Property.
2.  Create a User event and generate the user event in the subVI (good if you already have an event structure in place)
3.  Use a notifier to notify the main VI that the variable should be updated
4.  Use a queue to tell the control to update (good is your using a queued State Machine)
Message 2 of 6
(3,344 Views)
Hi Sean,

Well, just as I finished writing this, Matthew beat me to the punch.  But here's what I would say, anyway:

Yes, there are a few ways to do this.  The most common ways to do this is using a queue or a notifier.  If you enter "queues" or "notifiers" in the NI Example Finder, you should get some examples.  Specifically, check an example called "Queue Message Logging."  That example illustrates how to pass data between VIs.  I couldn't find a good notifier example to accomplish the same thing, but you could very easily modify the Queue Message Logging example to use notifiers since the queue and notifier functions are very similar.

There are fancier ways to do this, too, like VI server, user events or even TCP if you're feeling really ambitious.  I'm sure other folks will have other ideas.

I hope that helps...

Jim


Message 3 of 6
(3,340 Views)
On Oct 12, 12:40 pm, Sean.C <x...@no.email> wrote:
> I have a subvi that I wish to have running continuously in a separate thread during the entire main execution.&nbsp; The problem that I am having is that I want to update a local variable from the subvi periodically, and the only way I know how to do that is with globals (which would reduce portability of code).&nbsp; Is there any other way to periodically update the calling vi from a subvi?
> &nbsp;
> Thanks,
> Sean

Have the calling VI pass to the subVI a reference to the control you
want to update. In the subVI, wire the reference to a property node
to access the 'Value' property of the control.

Paul Cardinale

Message 4 of 6
(3,318 Views)
on top of the above responses, i will add my 2c:
 
my favorite way to replace global variables is by using a LV2 global. for more info, look at this nugget
in short, you pass your data to a subvi, which consist of a case structure in a while loop, terminated after a single iteration.
the structure might have 2 cases: write and read. in the write case you pass the data to a shift register in the while loop. in the 'read' case you retrieve the data from the shift register.
the secret: the shift register of the loop is uninitialized.
 
then everytime you want to write to a global, you write to this sub. and same, replace the read from globals with this sub.
-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
Message 5 of 6
(3,312 Views)


@Sean.C wrote:
The problem that I am having is that I want to update a local variable from the subvi periodically,
Just to clear up some possible misconceptions:
A local variable is not somethings that can stand on its own, it is just something that actually points to a front panel control or indicator. The control or indicator actually holds the data. It seems you actually want to update a control/indicator from within the subVI. So, yes, a control reference will do the job as some have already pointed out.


@Sean.C wrote:
and the only way I know how to do that is with globals (which would reduce portability of code). 
Can you elaborate why a local variable would reduce the "portability" of the code? AFAIK, global varaibles are supported on all OSs. You project already has several parts: a main VI and subVIs. What kind of "portability" do you have in mind?
 
An action engine or functional global (as gabi suggested) would also add one more element to your distribution and that should not be a serious issue.
 
Another relatively clean way to share data between VIs is the shared variable, available in recent LabVIEW versions.
 
Are you more interested having access to the value for use in computations or are you mostly interested to just update a value of a control?
Message 6 of 6
(3,292 Views)