LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Exiting simultaneous loops

I am running two while loops simultaneously and I want them to both stop when the user presses a single front panel bolean control.  Is there any way I can do this using the 'latch when released" button operation so that the button doesn't have to be reset before the next time the VI is run?  Using the "switch until released" is no good as both loops take some time to finsh and exit. 
0 Kudos
Message 1 of 8
(4,457 Views)
Unless you are familar with notifiers, occurences or queues, the way to go is to use an additional boolean.

See attached example.

0 Kudos
Message 2 of 8
(4,449 Views)
You can reset the state of your stop button with a local variable.

Set the boolean to "switch when released". place the control in one of the simultaneous loops; wire this to the stop terminal. Place a local variable set to "read" in the other loop and wire this to stop terminal. copy the boolean local variable to the outside of this second loop and set its mode to "write". Wire the local variable inside the loop to the one outside the loop. Place a boolean NOT operator on the wire between the outside of the loop and the "write" local variable.

Since a picture is worth a thousand words...



Message Edited by Phillip Brooks on 06-19-2007 06:32 AM

0 Kudos
Message 3 of 8
(4,451 Views)
Perfect.  Thanks.  🙂
0 Kudos
Message 4 of 8
(4,435 Views)
I would tie them together with a logical OR before the NOT... just to insure that both loops complete before switching the boolean back... It could potentially lead to a race condition depending on how long the loop not wired to the NOT executes past the other loop.  Definate gotcha at times.
My $0.02

Paul
0 Kudos
Message 5 of 8
(4,429 Views)
Very good remark ! Another way would be to initialize the boolean before starting the loops like showed in my example.
0 Kudos
Message 6 of 8
(4,419 Views)
I typically use event structures.
 
In each loop, use the timeout case for regular activities and have stop events, all tied to the same boolean button.
One advantage is that no matter how slow the loop iterates, the stop will work immediately.
 
 

Message Edited by altenbach on 06-19-2007 09:01 AM

0 Kudos
Message 7 of 8
(4,404 Views)
On OpenG I posted a set of VIs that harness the event structure into one VI!

Here's a screenshot of the same code as Altenbach's:


Where the upper while loop runs at 200 ms and the lower runs at 500 ms.
Both will react instantly!

Ton

Message Edited by TonP on 06-19-2007 10:12 PM

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 8 of 8
(4,387 Views)