LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stop boolean in state machine

I have a program that is written with the state machine arch.  There is a stop boolean on the front panel that the user can click to stop the program.  The stop is connected to the stop of the while loop.  However, each state of the program takes minutes to execute, so the program doesn't check the stop boolean until during the transition between one state to another, so the stop boolean doesn't reponse quickly.  What are some way to fix that?  Is checking the stop boolean more often the only way? If so, what are some elegant way in doing so?

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 1 of 11
(4,703 Views)

There is no way to stop a loop faster if the case structure is taking that long to execute.

 

If you want quicker response, you will need to break down your long running states into a series of shorter ones.  What are the long running states doing that is taking them minutes to run?

0 Kudos
Message 2 of 11
(4,698 Views)

Technically there are ways, but they might not be "elegant".  I inherited old code that always had a global variable called 'kill all'.  It was put into all sub-processes as a read (ussually OR'd with a loop stop terminal), then the upper level code wrote to it causing all lower loops to terminate and end the subVI allowing the main VI to take back control immediately.  Of course the data returned from the sub-processes wasn't valid but there was code to handle that if necessary.  Kind of kludgy and it breaks dataflow but it did work.

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
Message 3 of 11
(4,689 Views)

The state machine is just a long test, and each test is just a section of the test.  That's why each state takes that long.  Maybe the state machine arch is not the best way?  I don't have test stand, so I am using a state machine as a sequencer.

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 4 of 11
(4,682 Views)

Global is definitely one way.  At the moment, I am trying to avoid it, but I may have to resort to it.

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 5 of 11
(4,681 Views)

Can each step be broken down further?  What is taking so long in each step?

 

If it is something like waiting several minutes for a glass of water to heat up, then what you do is break it up into a 3 steps.  1.  Turn on the heater.  2.  Wait.  3.  Turn off the heater.  You keep iterating through the wait step at relatively fast pace until either the conditions have been met to go to step 3, or you stop early when you get the stop message, go to step 3, then proceed on to your shutdown of the loop rather than what ever would normally come after step 3.

Message 6 of 11
(4,662 Views)

Ravens Fan gave a good description of the most practical way to handle lengthy processes which may need to be interrupted.  If you have a long calculation or are acquiring large numbers of samples of data, the same technique of breaking it up into small sections which are repeated until done or until stopped can be used.

 

 

Lynn

Message 7 of 11
(4,643 Views)

Raven,

 

If I have a state that is supposed to perform a few operations on 10,000 data points (in an array).  It would be really simple create a while loop in one state and have the array fed into the loop for all the operations.  However, if I do that, I would be trapped in the loop for a while and not be able to detect the stop boolean until I exit the loop and the state.  In a situation like this?  What is the best way to break it down without over-complicating the code?

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 8 of 11
(4,613 Views)

Yik,

 

How long does the operation take for 10000 points?

 

Can the operation be done 100 points at a time?  If so, do 100 points, set a counter to n + 100, and exit the state to check for the Stop command.  If Stop is False, go back to the calculation state and do the next 100 points.  If Stop is True, exit.

 

Lynn

0 Kudos
Message 9 of 11
(4,606 Views)

Sounds like a lot of work to just check for a stop boolean, but that's definitely a way. 

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 10 of 11
(4,582 Views)