07-22-2009 10:02 AM
Hi everyone,
I am trying to put a 'stop' button inside my labview program that could control the program to stop immediately (Or quickly) right after click (Not the stop button on control panel ). I am not sure whether there something like 'signal handler' in C/C++ or 'hook' that could capture the event of clicking the button. I really don't want to put some check code in each step to finish this function.
Any idea is well appreciated,
thanks,
-Kun
07-22-2009 10:40 AM
In a separate parallel while loop with a small wait statement, you can wire a stop button to the Stop LabVIEW stopsign icon located on the application control palette. This is equivalent to hitting the abort button on the toolbar.
However, it is a rather harsh way to end the program. I don't understand your sentence "I really don't want to put some check code in each step to finish this function." With the right architecture probably based on a state machine, it should not be difficult at all for the program to detect when a button has been pressed and gracefully to do any clean up code such closing references and resources or saving data as necessary before stopping the program.
07-22-2009 10:41 AM - edited 07-22-2009 10:43 AM
Sure is-
Just launch a second thread with a structure that contains the STOP primitive found on the applications control pallate. You can poll a STOP boolean that the user has access to with an event case, for loop, timed for loop or timed event structure depending on how fast you want to react and how much CPU time you are willing to give the thread.
However, Raven's Fan makes a good point that you need to consider any clean-up code before hanging up the main vi especially if you have control of hardware from the vi.
07-22-2009 12:20 PM
Good post Ravens fan - "Start with the right architecture"!
I use the queued state-machince approach and check the ABORT (Panic Stop) button after each case is executed. If I get an ABORT I safely and gracefully exit the program.
07-22-2009 12:38 PM
Thanks VADAve.
I think part of that architecture as well should handle the situations where a state may take a long time to execute. A state should execute relatively quickly, and if it needs a long time to run, then it just calls itself again until some condition is met. For example, in a temperature control situation, if you want to take 5 minutes to ramp up to temperature before executing another state, then the Ramp Temperature state should execute quickly always calling itself again numerous times over the 5 mintue period until the end condition is reached and it is instructed to go on to the next state. That way it can check the stop button frequently rather than waiting a full 5 minutes until the state would otherwise end.
07-22-2009 12:53 PM
Kunsheng Chen wrote:Hi everyone,
I am trying to put a 'stop' button inside my labview program that could control the program to stop immediately (Or quickly) right after click (Not the stop button on control panel ). I am not sure whether there something like 'signal handler' in C/C++ or 'hook' that could capture the event of clicking the button. I really don't want to put some check code in each step to finish this function.
Any idea is well appreciated,
thanks,
-Kun
Ditto the previous indicating that the architecture should reflect these types of issues.
You could declare a dynamic event for your stop button and use a Event Struture to capture the event. Use the "Time Out" case to do whatever the code would be ding anyway (make sure the time out completes regularly so the event can fire).
Ben
07-23-2009 07:10 AM
Ravens Fan
Good Point I take it for granted that I will call a state numerous times if it takes a long time.
I have a standard QSM template and I have code in there to measure the execution time for every case. I just push the start time of each case on a Queue and get the dt when I am finished.