LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

universal break

Solved!
Go to solution

Hello all,

 

My program is 35 VI level tall and quite wide.   While executing the program I pop up a progress bar windows that shows the current status, along with this screen comes a cancel button.  When a user cancels task, is there anyway to force the program to stop executing immediately without quitting the program?  I have a lot of for and while loops, is there any quick and easy way to end all task immediately/break all the loops? thanks

0 Kudos
Message 1 of 6
(3,762 Views)
Solution
Accepted by lavalava

lavalava wrote:

Hello all,

 

My program is 35 VI level tall and quite wide.   While executing the program I pop up a progress bar windows that shows the current status, along with this screen comes a cancel button.  When a user cancels task, is there anyway to force the program to stop executing immediately without quitting the program?  I have a lot of for and while loops, is there any quick and easy way to end all task immediately/break all the loops? thanks


 

Quoting Ed Dickens from this thread "using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.".

 

So to be a purest always urging proper LabVIEW code regardless of the work to realize such I have to answer "NO, no easy way." You will have to find all of the loops your code can be busy in and modify them to monitor a stop flag, check the state of a button on the GUi etc. This is where a good design helps avoid the situation I think I hear you describing.

 

But if I switch hats to "hacker mode" I would suggest you look a the "stop"* and "quit LabVIEW"* functions available on the "application Control" palette. But I don't recomnd these functions and would prefer you implmement a global stop flag.

 

Ben

 

* Depending on the application and its hardware along with what is happening when a VI is aborted, you shoule EXPECT to have to manually kill the LV process occationally, and from time to time expect to re-boot to get it working again, so PLEASE don't use the either of those methods to stop an application that is running.

Message Edited by Ben on 12-31-2008 12:55 PM
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 2 of 6
(3,745 Views)

lavalava wrote:

When a user cancels task, is there anyway to force the program to stop executing immediately without quitting the program?


Listen to Ben, of course. 😉

 

Some additional notes:

  • If the program is under development, just hit the abort button and get it over with. This assumes that there are no critical shutdown steps that need to be triggered (e.g. shut off high voltage supply, etc.). Whenever external hardware is involved, you should not leave it in an undefined state when the program ceases control.
  • Once the program is used in a production environment, it always needs to be running. It should start up with "Run when openend". No operator should need to familiarize himself with LabVIEW specifics such as run and abort buttons, in fact the tool bar (and related entries in the "operate" menu hierarchy) should be hidden. At this point it should not even be relevant that we have LabVIEW under the hood (except for the pretty controls, amazing multitasking, and such ;)).
  • If the code is properly designed as a statemachine, you would just go back to the idle state if the operator wants to cancel the current operation. If you have deeply stacked loops, it just needs a bit more code. LabVIEW has all the tools to do this. Don't take any shortcuts!
Message Edited by altenbach on 12-31-2008 12:34 PM
Message 3 of 6
(3,726 Views)

You could programmatically abort if you want:

 

This basically aborts if the cancel button's value is true. 

Message Edited by Cory K on 12-31-2008 11:44 PM
Cory K
Message 4 of 6
(3,696 Views)

Hi lavalava,


lavalava wrote:

...is there anyway to force the program to stop executing immediately without quitting the program?


 

If you're asking: "Is there an easy way to terminate execution of code without stopping LabVIEW"

Then identical to the "Stop" function, why not use the "Abort Execution" button in the tool-bar?

 

If you're asking: "Is there an easy way to stop loops and other processes, without stopping the top-level VI"  

Then no - unless each and every loop has been designed to check some external "abort" condition.

Instead of calling a "Stop" or "Exit" function, pressing "Cancel" could set a global "Abort" boolean and loops that check the global would stop.

An occurrance can serve the same function - loops call Wait On Occurrance with Ignore Previous = False, Timeout=0 and checking for Timeout=False. Cancel=> Generate Occurrance.

A boolean Notifier works similarly. 

Queues and Notifiers, when destroyed, can signal "Abort" to loops that wait on them.

 

Cheers!

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
Message 5 of 6
(3,682 Views)

tbd wrote:

If you're asking: "Is there an easy way to stop loops and other processes, without stopping the top-level VI"  

Then no - unless each and every loop has been designed to check some external "abort" condition.

Instead of calling a "Stop" or "Exit" function, pressing "Cancel" could set a global "Abort" boolean and loops that check the global would stop.


 

Yes, that's what I'm referring to.  Aborting is very obvious but how can I do it so that it kills all lower level loops without affecting the top one.  Obviously the top level VI loop needs to be in tact otherwise the entire prog would shut down and my users would lose their saved works.  

 

 

I think I'll go with the first poster's suggestion about using a global variable and I'll replace all of my for loops with while loop.   Not a bad idea, pretty neat as a matter of fact.  Thanks for all the suggestion fellas.  Happy new year. Cheers!

0 Kudos
Message 6 of 6
(3,634 Views)