LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stop 3 while loop

Hi..
I am trying to stop 3 while loop at the same time. When the STOP button is pressed, it should work at once to stop other two while loops.
0 Kudos
Message 1 of 10
(4,054 Views)
Hi
 
You can use local variable of ane of the stop button, as control for the other two while loops.
 
regards
Arun 
0 Kudos
Message 2 of 10
(4,045 Views)
You can achieve this with local variables, so long as they're set to "Switch When...", as opposed to latching action, which won't work for variables.  That would probably be the easiest route.  Then just make sure your program resets the value of the control to its before clicked state before finishing (otherwise it will leave the control in it's clicked state, and will immediately stop your loops next time you run).
0 Kudos
Message 3 of 10
(4,044 Views)

The simplest means, if the while loops are all in the same vi, is to use a local variable of the stop button. You can create these by right clicking on the control on the diagram and selecting the "create local" selection. Your run arrow may be broken if the switch has the wrong "mechanical action", which you can change on the front panel.

 

P.M.

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 4 of 10
(4,040 Views)
Is there any relationship between these loops?  Master slave, producer consumer or just 3 totally asynchronous loops?  If the loops are independent the local of a quit Boolean will work just fine but if the relationship between the loops are more rigid, I would suggest looking into a synchronization between the threads such as queues to perform a stop/shutdown of the code.  This approach, while more complex is much more controlled and you will be able to more easily modify the code in the future.  This also will allow the code to be more distributed in the future if that is a possibility (ie, multiple PC over a network).  The synchronization techniques restore to code to a more determinant state, which will save you a huge amount of time if you eventually encounter race conditions.  One word of caution if you do use a local only write to it in one thread to avoid the multiple reader-multiple writer race condition found in concurrent multithreading code.
 
Paul
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 5 of 10
(4,028 Views)
The three while loops are independent in that sense. Confused to follow you suggesation. Attached is my Vi
0 Kudos
Message 6 of 10
(4,020 Views)
Sandy:  You should put delays in your loops.  The top loop is running at full speed and will hog all the CPU time.  Putting delays will allow the CPU time to do other things.  I have modified your vi (in 7.0) to include the delays, and to set the stop button to false at the beginning of the program.  Otherwise, the second time you run it, it will stop immediately because the stop button is true.
- tbob

Inventor of the WORM Global
0 Kudos
Message 7 of 10
(4,003 Views)
Here is a way to stop the loops by using a queue.  No local variables, no needing to set the stop boolean to false.  Because there are no local variables for the stop boolean, I am able to set the mechanical action to latch when pressed (or when released).  When the stop button is pressed, the top loop is done, and the queue closes.  Because the bottom inner loop reads the queue, it will encounter an error when the queue closes.  This causes the loop to stop because of the status boolean going true.
- tbob

Inventor of the WORM Global
0 Kudos
Message 8 of 10
(3,998 Views)

Personally, I prefer event structures. You can have an event in each loop that gets triggered by the same stop button. The timeout event contains your normal code. The timeout sets the loop rate.

Notice that the VI does not stop after the stacked loops have finished. The upper loop still waits for the stop button.

See attached. (LabVIEW 7.0, converted, but not tested from 7.1).

0 Kudos
Message 9 of 10
(3,988 Views)
LV2 globals also work well for this, and you can use a latching boolean.
0 Kudos
Message 10 of 10
(3,979 Views)