LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I allow a sub-vi to run independent of the main program once it has been called while still sending data to the sub-vi

I have a main program where I call a sub-vi. In this sub-vi, there is a while loop that is used to wait for commands in the sub-vi. While the while loop is running, I cannot continue with normal operation of the main program. I would like get the sub-vi to run independently once it has been called, but not hold up the main program. As well, I need to still be able to send data to the sub-vi
0 Kudos
Message 1 of 6
(5,209 Views)
For a real simple example on how to use VI Server to start another VI, go to Help>Examples>Advanced>Execution Control>Dynamic Loading of VIs. There are a lot of other examples available in NI's Resource Library.
0 Kudos
Message 2 of 6
(5,209 Views)
You'll have to run the vi dynamically and pass data to it using globals, Queues, or something along those lines.
0 Kudos
Message 3 of 6
(5,209 Views)
One way is to use VI Server, which has been mentioned by others. This will allow you to start another VI (by name) and run it entirely independently of the calling VI. This is a good way to start various independent VIs from a main menu, for example. None of the VIs thus called need have any connection to the others.

Another way it to have the SubVI in a separate while loop on the calling VI's BD. Then, use a local var to start this sub VI from the main loop. The calling VI sets a local START bit and continues running. The sub VI's while loop watches for this START bit to go true, and then runs the Sub VI. The advantage here is that one can more easily pass arguments to the SubVI when it is started, using local vars, which are preferable to globals. Once the Su
bVI is running, however, you must use a global Stop Bit, set in the calling VI, to stop it when the calling VI exits, or the calling VI will hang up, waiting for the Sub VI to close and exit its while loop.

If you need an example of this, email me. (ttower@aecontrols.com). I can also recommend Gary W. Johnson's excellent book which discusses this. ("LabVIEW Graphical Programming", 2nd Ed).

Note: Where possible, I try to call a subvi from within the main VI, wait till it is done, then continue. It avoids the use of locals & globals, and results in cleaner code, with fewer "race" conditions. However, the main VI stops until the subVI is done, hence one should make the subVI modal.
0 Kudos
Message 4 of 6
(5,209 Views)

I have the same problem, in my program i have a main vi from which i execute many functions and i want to call a sub vi to be executed. I used VI server to have multithreading but i still can't go back to my main problem to execute its functions when the sub vi is runing.

How can i solve this problem please? 

I really need your help, thanks

0 Kudos
Message 5 of 6
(4,517 Views)

You might have been better off starting your own thread (did you see how long ago the original post was?), but if VI-server isn't doing it you need to look into the asynchronous call by reference aspects of VI server - there  are a couple of examples to help you understand the way these work.

0 Kudos
Message 6 of 6
(4,511 Views)