LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I get values into a vi from a subvi while the subvi is still running within the vi?

Hello
This is my problem. I have a subvi that runs an experiment. At different point in the experiment different instruments are on or off and I have a boolean array display this info. It is updated at various points of the experiment via a local variable. That works fine. Here is the problem though. I run that subvi from a main vi program (that runs it several times for several experiment cycles). I would like to pass the status of that array onto the mainvi to display there too. The problem is that the array in the main vi is not updated until the subvi is done running and thus displays only the array status at end of experiment (instead of changing
as the status changes within the subvi). I tried using a global variable to write to it in the subvi every time there is an update, and read from it in the mainvi, but that doesn't work, it still displays just the status at the end of the subvi execution. Does anyone know how to make this work, or if there is a workaround this? Thanks.
0 Kudos
Message 1 of 7
(3,245 Views)
I got around this problem using references. I can directly change controls and indicators on the main screen from any of my sub-VI's. This is done by using the VI reference supplied with LabVIEW, but I made it a little easier with my own library of routines.

I have attached my library of VI's to do this. Take a look and you should be able to slightly modify one or two to get the effect that you need.

Be careful of race conditions.
0 Kudos
Message 2 of 7
(3,245 Views)
I am going to guess that you have some form of loop - FOR or WHILE inside your subVI. This loop is what is controlling your experiment and such.

From what I know, you're right about the main vi not getting updated. The subVI can only return values when it is done running. (It would be nice if you could use pointers here...)

However, there are two ways to make this work:

First, you might want to bring the FOR or WHILE loop to the main VI calling the subVI. Thus, the subVI only runs once and will return its proper value to the main VI.

Second option is to have two consecutively running WHILE loops. One calls the subVI as you are doing now. The second takes values from the GLOBAL variables and displaying it on the screen. This method is not elegant but it wor
ks. (also consider adding some delay or wait time so you don't end up using all processor time updating the screen.)

Hope that helps.

Shan Pin Koh
0 Kudos
Message 3 of 7
(3,245 Views)
If you have LabVIEW 6i, you can update indicators of a calling VI from
a SubVI, while the subVI is running.

In your case you need
1) an indicator on the main VI panel to display the boolean array
2) to pass a reference to that indicator to the subvi when you call it
3) to use this reference in the subVI, connect a property node to it and
write the values to be displayed to the 'value' property of this node

If you don't have version 6, you can write the values to be displayed to
a global and display this global in the main VI from within a while loop
which must run in the main VI in parallel to the running subVI.
It's more complicated, since you need a mechanism to gracefully shut
down the while loop after subVI finishes. You could do this with
another global control boolean which is not displayed but just connected
to the repeat terminal of the while loop. Don't forget to put a 'Wait' of,
say, 50...100 msec in that while loop.


-Franz

zkajan schrieb:

> Hello
> This is my problem. I have a subvi that runs an experiment. At
> different point in the experiment different instruments are on or off
> and I have a boolean array display this info. It is updated at
> various points of the experiment via a local variable. That works
> fine. Here is the problem though. I run that subvi from a main vi
> program (that runs it several times for several experiment cycles). I
> would like to pass the status of that array onto the mainvi to display
> there too. The problem is that the array in the main vi is not
> updated until the subvi is done running and thus displays only the
> array status at end of experiment (instead of changing as the status
> changes within the subvi). I tried using a global variable to write
> to it in the subvi every time there is an update, and read from it in
> the mainvi, but that doesn't work, it still displays just the status
> at the end of the subvi execution. Does anyone know how to make this
> work, or if there is a workaround this? Thanks.

--
Franz Josef Ahlers
Section Semiconductor Devices
Physikalisch-Technische Bundesanstalt
Bundesallee 100
D-38116 Braunschweig
phone: (+49) 531 592 2410
fax: (+49) 531 592 2405
0 Kudos
Message 4 of 7
(3,245 Views)
The best way to accomplish this task is to use references in Labview 6. I have written a very simple example program that demonstrates this principal.

Best Regards,

Eric Enger
National Instruments
Applications Engineer
Download All
Message 5 of 7
(3,245 Views)
Thanks EricE
That is exactly the kind of stuff I meant. I haven't had a chance to make it part of my program, but looking at what you did it doens't seem that hard (once I understood that it could be done that way). Thanks man
0 Kudos
Message 6 of 7
(3,245 Views)
that looks great, what are the steps to creating it. I found no references to any of this in the manuals or the help. Some convulated stuff about property nodes is all. Any help would be greatly appreciated
0 Kudos
Message 7 of 7
(3,245 Views)