LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stopping an event structure inside a while loop.

Solved!
Go to solution
Solution
Accepted by topic author alek
Actually, sorry about that last post - I forgot about adding a "stop" event case. Now it works properly, thank you very much.

Later,

Alek
0 Kudos
Message 11 of 12
(786 Views)


alek wrote:
I still can not entirely understand why was it not stopping - why does it stop now and not before?
You need to know that a timeout event has an infinite timeout if you dont wire a timeout value (default is -1), this means that the timeout event never executes and thus the stop button will only get read if the loop spins by some other means (e.g. if right or left is pressed). Your timeout case might as well not exist. 😉
 
In practice, the loop will stop, but you typically need to press two more buttons after you press stop. Maybe you never went that far.
  1. You press stop. At this point, the stop button terminal has already been read because the VI is just waiting on the event structure and has time to do all other things that don't have any data depedency (such as reading the stop button).
  2.  right or left is pressed. Now the loop spins once more and reads the stop condition, but it cannot finish because the event structure is again waiting for an event.
  3. right or left is pressed again. Now the last iteration can finish and the VI completes.

Correct is to add an event for the stop value and all is well. 😄

An illustrative debugging tool is to run the VI in execution highlighting mode while watching the diagram. Try it!

(Of course you could define a finite timeout and leave things as is in the original code, but why would you spin an empty loop for no reason at all except to poll the stop button? Makes little sense in the grand scheme of things. Even worse, if you would define a timeout of zero, the loop would spin at max rate, consuming all CPU it can get while not really doing anything useful) 🙂

Good luck and happy wiring!

Message 12 of 12
(786 Views)