LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Interrupt a an unfinished state in a QSM

Solved!
Go to solution

Hi,

 

I have a QSM not a QMH. Once a state is initiated in the QSM it cannot be exited until the subvi's running in the state finish exectution.

 

According to grandma I am guessing you can interupt an immediatly escape a state and run a new state using a QMH

 

I will study the QMH now to see how this is done.

 

In my whole application I intend to have the following

 

1. UI loop (based on butten EVENTs such as LogOut, Pause, Resume etc)

2. A hardware polling loop (to check the state of some I/O switches, e.g an interlock switch)

3. A state machine loop

3a. Up to 3 wait for data states

 

I seek to be able to immediately exit any state (particularly the wait for data states) by events generated by UI button press OR change in value of an I/O which is being polled.

 

UI or hardware value changes will priority place a state in the front of the queue.

 

I am simply stuck on how you can exit a state immediatly (without subvi finishing execution), other than of have a timeout, re-run the state and let any prioritised state generated by events chime in after the timeout

0 Kudos
Message 11 of 14
(1,364 Views)

You need your states to be able to execute fairly quickly.  Timeouts are sometimes needed.

 

So let's say you are in the Drve to Grandma state (I can already taste those cookies).  What you should do here is do whatever updating you need to (turn left, update location, etc) and then go to another state to check to see if you are there.  If not, queue up another "Drive to Grandma" and a "Are We There Yet?" for new commands.  If you enqueue other commands in there, then you will process those based on the queue priority.

 

If you keep each state within something like 100ms, this will flow a lot better.


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 12 of 14
(1,343 Views)
Solution
Accepted by topic author t.mcgregor

@t.mcgregor wrote:

Hi,

 

I have a QSM not a QMH. Once a state is initiated in the QSM it cannot be exited until the subvi's running in the state finish exectution.

 

According to grandma I am guessing you can interupt an immediatly escape a state and run a new state using a QMH

 

I will study the QMH now to see how this is done.

 

In my whole application I intend to have the following

 

1. UI loop (based on butten EVENTs such as LogOut, Pause, Resume etc)

2. A hardware polling loop (to check the state of some I/O switches, e.g an interlock switch)

3. A state machine loop

3a. Up to 3 wait for data states

 

I seek to be able to immediately exit any state (particularly the wait for data states) by events generated by UI button press OR change in value of an I/O which is being polled.

 

UI or hardware value changes will priority place a state in the front of the queue.

 

I am simply stuck on how you can exit a state immediatly (without subvi finishing execution), other than of have a timeout, re-run the state and let any prioritised state generated by events chime in after the timeout


QSM and QMH are reasonable interchangable terms.  Don't worry about digging into that.

 

The problem is not that you want to abort the unfinished state but that you have designed a state poorly!  to fix this we need to redefine the state "Wait for data"

 

The easiest solution is to make the state ""Does data exist?"

 

Assuming the data is comming from an external resource like VISA or (Well that isn't really important is it) the state might just take the following actions

 

VISA Read 4096 bytes timeout 2000mSec.  

If Error other than timeout. Pass error to caller for handling (Connection lost abort)

elsle if no timeout error, pass read buffer to destination enqueue "Idle" as next state  (Success!)

Else (timeout error) surpress timeout error and enqueue "Does data exist?" as next state.

 

Now your loop iterates and your state does not execute indefinately.

 

And yes! your producer loop should use "Enqueue opposite end" to enqueue "Stop" or "Return to idle" in front of any queue-to self-messages and flush the buffer in the consumer loop as appropriate.

 

Going back to grandmas.

 

"I Need to pee" would just jump in line if front of the last "Are we There yet?" We would enter "Peeing" state (But not flush the buffer) and return to the next "Are We There Yet?" state.  "The Bridge is Out!" would also jump in line if front of the last "Are we There yet?" but the "Process road hazzard" state would Flush the queue and then add an appropriate next state like "Go home" with the <Disapointed> flag set since we got no cookies.

 

 

Again, you cannot exit a state that has a sub vi that might not complete.  BUT, you can always write a subvi that will complete in a reasonable time.  "Stopping" the "Get Data" subvi isn't your problem.  That the sub vi may run indefinately is a design flaw of the subvi and should be addressed


"Should be" isn't "Is" -Jay
Message 13 of 14
(1,335 Views)

i like the use of notifiers (as my son would say on those long trips to Grandma's, "I gotta go...")..."GOOD FRIDAY" everyone!

abort notifier ver9.png

Message 14 of 14
(1,328 Views)