LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to terminate parallel while loops

Solved!
Go to solution

Hi, I'm using LV8.5.  I have 2 while loops running in parallel.  Loop1 is faster (100ms wait time) and Loop2 is slower (several minutes wait time).  I'm using a local variable (boolean STOP button) to communite between the loops.  The button is in the faster loop (Loop1) and the local variable is in Loop2.  When I try to terminate the While Loop, Loop1 stops immediately while I have to wait for Loop2 to finish.  Is there any simple way to make both loops stop immediately?  I have been using Application Control\Stop, but it may not be the good solution.

Thanks.

0 Kudos
Message 1 of 4
(3,436 Views)
Solution
Accepted by topic author shanx2

Hi shanx2,

reduce the wait time in your second loop and count the iterations instead. The loop will do the same, but the stop will react much faster. Another possibility would be to use a queue instead. Connect a timeout which corresponds to the wait time you currently use and send a message to stop the loop. You can decide between the queue has been timed out or not. Connect this result to the loop conditional terminal. You can send the queue message after the first loop has been stopped.

 

Mike

0 Kudos
Message 2 of 4
(3,431 Views)
Loop2 won't read it's STOP terminal until it finishes whatever code it contains.  You'll have to modify the internal code in it so that it can be aborted when the loop1 STOP is pressed.  There are many ways to do this that are prefable to locals.  You'll have to post your code if you want more specific advice.
LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
0 Kudos
Message 3 of 4
(3,425 Views)

One method is to use a WAIT ON OCCURRENCE to do your loop timing.

Generate an OCCURRENCE and wire the refnum to both loops.

 

In loop 1, when the STOP button is clicked, TRIGGER the occurrence, and then stop the loop.

In loop 2, WAIT on the occurrence with a timeout of "several minutes".

If the occurrence is TIMED OUT, do whatever you need to do every several minutes.

If the occurrence is NOT timed out, then it was triggered - stop the loop immediately.

 

Another method that MIGHT work in your case is to use an EVENT structure in loop 2.

The EVENT structure should respond to the STOP button (by stopping the loop), and respond to a TIMEOUT of "several minutes" by doing whatever needs doing every several minutes.

Loop 1 would also have an EVENT that responds to the STOP button.

 

Note that TIMEOUTS in an EVENT structure are reset - if your TIMEOUT is 1000 mSec and you trigger some other event at T = 999, then the TIMEOUT will be pushed back to T = 1999, not T=1000. 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 4 of 4
(3,410 Views)