LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any programtical way to make labview program stop immediately by clicking a button in the program ?

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

0 Kudos
Message 1 of 7
(4,544 Views)

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.

Message 2 of 7
(4,535 Views)

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.

Message Edited by Jeff Bohrer on 07-22-2009 10:43 AM

"Should be" isn't "Is" -Jay
0 Kudos
Message 3 of 7
(4,534 Views)

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.

Visualize the Solution

CLA

LabVIEW, LabVIEW FPGA
0 Kudos
Message 4 of 7
(4,510 Views)

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.

Message 5 of 7
(4,503 Views)

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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 7
(4,495 Views)

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.

Visualize the Solution

CLA

LabVIEW, LabVIEW FPGA
0 Kudos
Message 7 of 7
(4,464 Views)