LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stop State machine execution at any time

Hi,

Please I need help with stopping an Event Structure execution.

There are a couple of user events that are organized in an Event structure. No matter which event is being executed the user has to be able to stop the execution at any moment.

I created a simple vi. The problem is that while the event structure is running the STOP button is not active.

Please let me know how the code should be organized in such a manner that the Stop could be immediately detected and the event execution terminated.

Thank you in advance for your advice.

0 Kudos
Message 1 of 5
(3,639 Views)

First, you really shouldn't have long running while loops inside of events.

 

Second, because you have Lock front panel set for that event, you are unable to hit the Stop button for it to be read inside that while loop.

 

Also read Caveats and Recommendations when Using Events in LabVIEW - LabVIEW 2013 Help

Message 2 of 5
(3,631 Views)

You got things inside out.  State Machines do NOT belong inside of an event case.  An Event Structure should be inside of one of your states in a state machine.  That way you can still react to user commands while still running other tasks in the state machine.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 5
(3,622 Views)

Thank you, OriolesFan.

Just removed the check mark from the Lock panel box and all started working as desired.

Thank you. Thank you. You cannot imagine how many hours I wasted trying to figure out the problem.

I do have long while loops in my event structure.

Smiley EmbarassedWhy should they be avoided? What should I replace the while loops with?

0 Kudos
Message 4 of 5
(3,614 Views)

When you have long running while loops, the event structure will be capturing events, but it won't be able to act on them until the inner while loops end.  It may not be as much of a problem with your code right now since you only have the one event case.  But as you add event cases, it will be more difficult, and your code will seem unresponsive to the user.

 

When you have a properly designed state machine, you will have quick running cases, and the outer while loop can keep sending itself back to the same state when something needs to happen repetitively.  But you will also need another case (called Idle, or CheckEvents, or something like that) where the state machine regularly goes through that state to be able to service any events that occur.

0 Kudos
Message 5 of 5
(3,600 Views)