LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Respond to Main Front Panel Event from Anywhere at Any Time During Execution

Hello,

I've been trying to figure out a way to break out of a sub VI at any point in time based on a stop button on the main VI's front panel.  I've tried the que system, and a state machine with an event structure to handle state changes, but each state will run all the way to the end before realizing it should stop.  I've tried a "stop flag" FGV, and polled it before each sub VI, but the event I use to set the flag doesn't actually happen until the state is done anyway, defeating the purpose.  The reason I would like to do this is each state will contain a string of VI's that set up various equipment and relays to make measurements, then store the measurements for reporting later.  Ideally, the sequence of sub VI's should stop and then skip ahead to the "exit" or stop state, where I handle clearing of relays and power down.

 

Is there a recommended design pattern that can achieve this?  I've only been doing LabVIEW for a couple months, but I've dabbled in C++, Java, and C# for a few years.  It would be really nice if LabVIEW had a software interrupt / handler of some kind.

 

Thanks,

JK

0 Kudos
Message 1 of 3
(136 Views)

Two things come to mind.

 

1.  The event case that detects events belongs in its own loop.  It will use whatever mechanism to send that information throughout your program.  A stop functional global variable is a reasonable choice.

2.  A state machine architecture which is sounds like you have.  But you need to make sure each state is pretty quick to complete.  You say each state will have a string of VI's.  Perhaps each of those VI's deserves to be a state of its own.  If you do have a string of them within each state, have each one check the FGV at the beginning of its execution and only execute the code in a case structure assuming the Stop had not been pressed.  If even after  you broken down the states to the finest level of explicit actions, but they are still long running, perhaps a state is a loop to wait a specified amount of time, or slowly ramp a value,  treat that as a state which keeps calling back to itself until the exit to next state condition is met.  Then it will be a faster running state that can keep checking on the stop status and expire early jumping right to your exit state.

0 Kudos
Message 2 of 3
(113 Views)
Highlighted

 

@jk_physics wrote:

Hello,

...  The reason I would like to do this is each state will contain a string of VI's that set up various equipment and relays to make measurements, then store the measurements for reporting later.  Ideally, the sequence of sub VI's should stop and then skip ahead to the "exit" or stop state, where I handle clearing of relays and power down.

...


As Raven's Fan wrote, you have to write your code such that it is capable of "...skip ahead to the "exit" or stop state..."

 

Are you by any chance using a sequence structure?

 

If so switch to a State Machine designed to execute short steps in the proper sequence and keep checking if the stop flag was asserted.

 

State_Diagram.JPG

 


Take care,

 

 

Ben

0 Kudos
Message 3 of 3
(89 Views)