LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stop a sub VI anytime


@MaSta wrote:

@Bob: Very clever way. Didn't know of the pipe. However, it doesn't help to end the sub VI. I also opened another thread where the topic was to end two loops at the same time. Did you perhaps want to answer there?


My previous answer stands -- when you have multiple loops, you need to be sure you stop all of them (unless, of course, you want to do an "uncontrolled Panic Stop", such as shutting down Windows or killing the power to your PC).  Event Loops are usually easy to stop -- a User Event can be created that just wires a True to the While Loop's Stop Control.  Any loop that "loops" fairly often can be stopped by using a Tag channel (or a Notifier) that, when read, sends a True to the outer While Loop.  Similarly, if you have parallel loops (such as Consumers in Producer/Consumer pairs), you can get the Producer (which is often in the Main loop) to tell the Consumer to exit.  I think I mentioned that the Stream Channel Wire has an added "feature" that makes this very simple.

 

So the only problem is what to do if you have a loop running very slowly, say once an hour?  If the "Time to exit" signal comes when the loop timer still has 45 minutes to run, you can't exit until the 45 minutes elapses.  So you have to be clever -- instead of having a clock that waits an hour, have one that waits a second, but is in a exitable loop (I'm thinking a For Loop with a Stop terminal) that runs 3600 times.  If the "Quit" signal comes in, send a Tag to stop the clock, and also potentially skip whatever you were waiting to do, and exit the loop.  [It's tricky to explain this in words, but I'll bet if you look at your LabVIEW code, you can see what I'm driving at).

 

Bob Schor

0 Kudos
Message 11 of 11
(215 Views)