LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stopping a while loop with 10 seconds delay

Hi all. I have put in a 10 seconds delay for my while loop for perform some task but I wish to stop it immediately when a stop signal is given to the loop.  
I have tried many ways but I still couldn't stop the loop. 

0 Kudos
Message 1 of 10
(5,053 Views)

Where does the stop signal come from ? User interface, hardware... ?

 

Post your code and we will adapt it for you.

0 Kudos
Message 2 of 10
(5,041 Views)

You can split up the 10 seconds delay into many small waits (of 50ms ?) and use "Get Date/Time In Seconds" to see if 10 seconds have passed.  You can then stop the loop if this condition has been met or if anyone has pressed 'STOP'.

 

So you will have the loop run many times with a short delay and check the current time and 'STOP' button each time to see if you should stop the loop.

 

If you only want the loop to run once you could create a second loop inside the one you have using the same mechanism in that second loop as I described above.

0 Kudos
Message 3 of 10
(5,037 Views)

 


@m3rv89 wrote:

Hi all. I have put in a 10 seconds delay for my while loop for perform some task but I wish to stop it immediately when a stop signal is given to the loop.  
I have tried many ways but I still couldn't stop the loop. 


Check the attached example (saved in version 8.0)


I am not allergic to Kudos, in fact I love Kudos.

 Make your LabVIEW experience more CONVENIENT.


0 Kudos
Message 4 of 10
(5,029 Views)

Thank you for all your comments above. 

Here is why i am trying to do. Lets assume I have a while loop with 3 LED indicator, each delayed with 1 second in a order sequence structure framed. Whenever the stop button is pressed, the program continues to run to finish its 3 seconds delay. 

I would like to stop it before the second LED lights up or stopping the while loop immediately whenever the stop button is pressed. 

Attached is the screenshot. Thanks alot!

 

 

block diagram.png

front panel.png

Download All
0 Kudos
Message 5 of 10
(5,008 Views)

Do NOT use sequence structures.

This is the main source why you cannot stop inbetween.

 

What you should use is a state machine. This enables you to poll for a stop condition and, if it does not occur, continue to wait and switch to the appropriate action when needed.

 

hope this helps,

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 6 of 10
(5,002 Views)

Thank you for the suggestion of state machine. However, if a delay of n seconds (for instance 5 seconds) is placed in a while loop or a for loop or whichever case, it will eventually delayed for 5 seconds before doing the next task? Please correct me if I am wrong. Eventhough with a state machine, when it does poll for the next action, it must serve its delay of 5 seconds implemented before going to the next state. Am i right?

0 Kudos
Message 7 of 10
(4,992 Views)

You wouldn't use a static wait time of several seconds. This also blocks the whole application.

You would rather poll a timer for "elapsed time: (search for this 🙂 ) and if the time is elapsed, go to the appropriate state.

 

The state machine will therefore include a state like "check for elapsed waiting time" which will poll the stop button and, if pressed, go to the shutdown case instead of resuming the waiting...

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 8 of 10
(4,980 Views)

see if you can better understand using a state machine, polling, elapsed timer, transitions to different states, data flow....and not being locked in with flat sequences.

 

Spoiler
delay.png

 

0 Kudos
Message 9 of 10
(4,964 Views)

Dear Nobert and Apok, thank you guys for your helpful suggestions and different ways of tackling the delay issue.

0 Kudos
Message 10 of 10
(4,942 Views)