LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

stopping a loop without waiting for its next iteration

Solved!
Go to solution

I'm wondering if there is a good way, or even anyway to stop a while loop without waiting for its next iteration. Lets say you have a timer in the loop so it iterates once evey 10 seconds, then you have to wait 10 seconds for it to stop after a stop button is pressed which could be a problem.

 

Thanks!

0 Kudos
Message 1 of 20
(3,986 Views)

Rather than put a 10s wait, make the wait much shorter, but only perform your action after 10s has elapsed. There is an 'elapsed time' express VI, or you can create your own Timer FGV.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 2 of 20
(3,980 Views)

There are lots of ways to do this, but it depends, a bit, on the current architecture or Design Pattern you are using.  Since you have shown us none of your code, we can't do more than say "Yes, it is possible, and not that difficult ...".  For more specific suggestions, post your code (as a VI or Snippet, so we can execute it and test out our suggestions to be sure they function correctly).

 

Bob Schor

0 Kudos
Message 3 of 20
(3,971 Views)

Sorry I didn't post code, here is a very simple example of what is happening. I took out the insurment controls but as you can see, the longer the ramp time, the longer the loop runs, thus it takes longer until it shuts off.

 

Thanks for assisting!

0 Kudos
Message 4 of 20
(3,957 Views)

One easy way would be to use the timeout event of an event structure and an event case for the stop button. Pressing stop will break the current timeout wait, even if it is infinite.

Message 5 of 20
(3,945 Views)

I've been looking at event structures in the labview help because I've never really used one. I can't figure out the correct way to wire it up

 

0 Kudos
Message 6 of 20
(3,924 Views)

I guess it's just a stop button inside the timeout case wired to stop the loop but im not sure what else i have to do

0 Kudos
Message 7 of 20
(3,921 Views)
Note that a typical program has also event cases of other things, potentially breaking the timeout without stopping the loop. Make sure to handle these scenarios.
0 Kudos
Message 8 of 20
(3,908 Views)

So is this what the final solution should look like, it seems to work?

0 Kudos
Message 9 of 20
(3,900 Views)
0 Kudos
Message 10 of 20
(3,898 Views)