View Full Version : Labview SubVI return and continue looping
skidmarks
05-01-2009, 21:57
We wish to have several VIs running simultaneously, and we want each one to loop continuously. We would have one section which would quickly return, and another than loops indefinitely. While I do not believe this is possible, other team members and mentors say they saw how to do it but have since forgotten. Is this possible, and how is it possible if so?
Larry Lewis
05-01-2009, 22:28
We wish to have several VIs running simultaneously, and we want each one to loop continuously. We would have one section which would quickly return, and another than loops indefinitely. While I do not believe this is possible, other team members and mentors say they saw how to do it but have since forgotten. Is this possible, and how is it possible if so?
I would probably loop each one individually in a while loop. Just create a new loop for each subvi you want to run. If you wanted to constantly return values for one of them place a indicator in the loop. Every time it runs it will update the value on the indicator.
If you want to stop all the processes at the same time just use a stop button control to one of the while loops condition terminal and create local variables of that stop button and place them in the other loops. That way when one stops they all should stop.
skidmarks
05-01-2009, 22:32
I thought the "cleanest" method that would work well would be to store inputs and results in a global or shared variable, then in the loops they would access the variable.
Larry Lewis
05-01-2009, 22:47
I thought the "cleanest" method that would work well would be to store inputs and results in a global or shared variable, then in the loops they would access the variable.
You could do that but it may lead to potential race conditions and also requires more memory usage. But I guess in the end if it works out for you and your team that is all that really matters. :)
whitetiger0990
06-01-2009, 01:06
LabVIEW runs highly parallel. If you look at the Basic Robot Main.vi you can see 3 loops, 2 of them are infinite.
The first one does the DS comms and motor control and handles auto and all that jazz. It's where you put most of your code (and subVI calls)
Below that is the camera code. If you want to access camera data in other loops, you have to use global variables
The loop below -that- is a timer loops. It is an infinite loop with a wait timer so it only executes the commands in it depending on what the timer value is. Again, to get data from this loop you have to use global variables.
Modifying global variables from multiple VIs is tricky.. race conditions (http://en.wikipedia.org/wiki/Race_condition) are also bad, so you must be careful.
Greg McKaskle
06-01-2009, 07:18
To the original question, a subVI cannot return until its whole diagram is complete and all of its outputs are ready. So you cannot have it be partly running and partly returning.
Your choice is to have the loop in the caller, making many calls to give and get data from the subVI, or you can push the loop into the subVI. The template shows both.
Using globals is fine as long as you have only one writer, but be careful when you want more than one loop to write. You can safely have as many reader as you want, but of course they may not always be in sync with each other.
Greg McKaskle
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.