LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Interrupting a state machine while loop.

I have a state machine, as can be seen in the atatched vi. When the user clicks a "start Procedure" button, the case "start procedure" is executed. Inside this case I have while loop with a further case structure, which iterate over the five steps inside the case structure until the users desired cycles are done. I want to now inlcude an "interrupt Procedure " button, that breaks the while loop and halts further execution. However the button becomes inactive during running and I am not able to interrupt the loop. Highlight execution revealed that the button never changes value. How can this be? My understanding of the while loop/case structure assembly is that one case is one cycle, then moving onto the next case is another cycle, etc. Is this not correct?  

Thanks in advance.
Doug

0 Kudos
Message 1 of 9
(1,517 Views)

May it be related to this link: https://zone.ni.com/reference/en-XX/help/371361M-01/lvhowto/caveatsrecmndtnsevnts/. Under the last point it says that a VI may become unresponsive (which mine sometimes does) if the while loop doesnt execute fast enough. Given my rather lengthy sequence inside the loop (some cases may take up to 2 minutes to complete), might this be the issue?
Cheers

0 Kudos
Message 2 of 9
(1,487 Views)

Don't have a while loop inside a state.  If there are 5 steps inside of it, then it should be 5 more states on the outer state machine.  If you need to repeat a state, you just have the state machine repeat that same state.  That way at any point in these shorter running steps or states, if the stop button is pressed, then it can go to the stop state instead of the next step/state.

0 Kudos
Message 3 of 9
(1,486 Views)

Yes. your event structure could be a problem as well.

 

Do you need the event structure?  If you do, then it should be a separate state that could be called "Check for events".  Your state machine can go through that state as needed to see if it needs to handle anything before it goes on to its next state.

0 Kudos
Message 4 of 9
(1,483 Views)

Hi few Suggestions in your code,

1. Avoid usage of Sequence structure unnecessarily, use error wire for sequencing instead of sequence structure.

2.Avoid time consuming or looping logics inside the event struture, call states and implement the same logic in different state than having inside event structure.

3.Error wires are not used throughout your code.

4.Even the Loop inside start procedure can also be changed by creating the states in Main Loop itself.

 

basically need to reframe with proper state machine architecture.

 

Palanivel Thiruvenkadam,
Certified (LabVIEW || TestStand) Developer
0 Kudos
Message 5 of 9
(1,482 Views)

Thanks for your comment. So I need to make another 5 states: move stages down, immersion wait, move MTS up, move LTS up and drying wait? Is that what you mean? So in my start procedure event I would need to link to the move stages down event, from there to the immersion wait event, etc. Correct? How would you suggest I do this? Hidden controls that get programatically pressed?

0 Kudos
Message 6 of 9
(1,479 Views)

@bockdoug wrote:

Thanks for your comment. So I need to make another 5 states: move stages down, immersion wait, move MTS up, move LTS up and drying wait? Is that what you mean? So in my start procedure event I would need to link to the move stages down event, from there to the immersion wait event, etc. Correct? How would you suggest I do this? Hidden controls that get programatically pressed?


Never ever use hidden controls! Bad practice. Your Event structure should only act for GUI user commands, and placed into a SINGLE case of the State Machine. Other cases of your state machine would accommodate the required steps. You need to change your VI design a lot. In such case I would just use a Producer-Consumer (Events) design, where you can start a certain procedure and the State Machine is the consumer loop. Whenever you need to "interrupt", you can place an "abort" or "interrupt" command in FRONT of the Queue from the Producer loop, so the Consumer will act. Important thing is you need to cut up steps in a way in your state machine that each step should not take too much time. In this way you can interrupt fast any time...

 

Another big advantage of the Producer-consumer design is that your GUI and your State Machine is decoupled: for example, when the user clicks on "interrupt", you can ask for confirmation with a pop-up window if you want, and during this pop-up window active, your consumer loop is just still running happy and undisturbed... And so on..., producer-consumer design is very powerful you will see...

0 Kudos
Message 7 of 9
(1,465 Views)

I really suggest you to go through some LabVIEW tutorials, like the "self-paced-learning" Core 1-2-3, you can learn a lot about different design patterns and state machines, etc...

0 Kudos
Message 8 of 9
(1,453 Views)

Refer to producer consumer loop concepts

http://www.ni.com/white-paper/3023/en/

Palanivel Thiruvenkadam,
Certified (LabVIEW || TestStand) Developer
0 Kudos
Message 9 of 9
(1,449 Views)