LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

abort button on front panel

I have a program that has for loops and many subVIs. I want to have an abort button on the front panel that immediately stops the program whenever it's clicked on (just like the abort button on the tool bar). Is there a simple way to do that without having to create a global variable or reference node? (I don't want to go to every subVIs and put a global variable/reference node of the stop button in, because I have so many subVIs) However, if there isn't any way to do that,could you tell me how to create a global variable or reference node? (I actually read a question like this on this website. They suggested to use a global variable or reference node, but I really don't know how to do those eventhough I looked at the example of the referen
ce node solution).
0 Kudos
Message 1 of 12
(4,497 Views)
Method 1:
create a boolean control for your abort button. in your code, put a do-loop outside of any other loops (off to the side or something). put a wait delay inside the loop (1-200ms will work). wire the abort control to the stop sign (application control -> stop).

Method 2:
if you need to end all routines without ending the program you need to use a global variable. file -> new -> global variable. this brings up a front panel with no code page available. you would place a boolean on this global page named LoopStop or whatever and then save the global and close it. then on each code page you would insert a vi via the dialog(Select a VI...) and choose your global file. wire the resulting control to the stop/continue of the loop. to repeat for multip
le loops cut/paste or ctrl+drag so you don't have to reinsert from the global file.
Message 2 of 12
(4,497 Views)
Method 1 can be dangerous since it doesn't allow for an orderly shutdown. References would still be left open, instruments on, etc., but it is a fast way to do a stop.

If you decide to implement method 2, you should know that there is no way to abort a for loop. It always runs for the number of times you've wired to the N terminal or the size of an array you input to it. You'll have to replace the for loops with while loops or put a case statement inside each of the for loops so that an abort condition is a case in which nothing is done.

Since it sounds like you've already done a lot of coding, method 2 may seem like a daunting task but in the long term, may be the safest.
0 Kudos
Message 3 of 12
(4,497 Views)
Dennis is right (again). Heed his warning!!!
If you're just crunching numbers, Stop may be harmless, but if you're talking to instruments or reading/writing files or testing hardware, Stop can get you into a lot of trouble. At best, you may lose data, but you may also leave a condition that's harmful to instruments or your unit under test or even to the test operator.
What are all those sub-VIs doing? If you take a look at which ones are active for long periods of time, you may find that there aren't that many that need to be changed to use a global (or a control reference) to do a controlled stop.
Why do you need an immediate stop? And what does immediate mean? Just short enough so the operator doesn't think nothing happens when Abort is presse
d?
0 Kudos
Message 4 of 12
(4,497 Views)
mmmm... good point about for loops... i primarily don't use them so i forgot to mention those. instead of changing the for loops to do loops you can also put a case structure inside the for loop wired to the global stop variable so that all instructions in the loop will be cancelled and the iterations will immediately execute one after the other until the routine ends, once the global variable is set.
0 Kudos
Message 5 of 12
(4,497 Views)
Yeah, I mentioned that possiblility but the downside to that technique is that you might have to process any auto-indexed arrays. For example, say a for loop normally has 100 iterations. If the abort condition a received after the first iteration, the auto-indexed array would still have 100 elements but 99 would have to be dummy values. Depending on what you're doing, you might have to modify your program to detect the dummy values or remove them from the array. One other useful technique in quicly aborting, is to have the loop where the abort is detected, set an error condition. If all of the subVIs have a outer case statement with the error in cluster wired to the selector and the error case being a do nothing, the subVIs will ret
urn control to the main VI quickly. Just something to keep in mind when designing your next app.
0 Kudos
Message 6 of 12
(4,497 Views)
Actually I am going to post this question but now I think there is a possibility.
Please take a look at my example and I think it is 99% possible and I tested with my program. My VI also has many subVI and I may not know what time they finish execution and I am controlling HV generator and it is very dangerous. So I want to get emergency STOP button for my VI. Pleas Look at my example.
Regards
Saw Naing Aye
Download All
0 Kudos
Message 7 of 12
(4,497 Views)
One more thing I forget is Why we use local variable for both loop is to run both loop simultaneously
0 Kudos
Message 8 of 12
(4,497 Views)
If every loop in every subVI continously monitors the global and you don't use the any of the wait functions with large values and you don't have any other functions that might take a long time to execute or timeout (like a VISA read), you might get some sort of reasonable response from an Abort button. If you really have the possibility of some sort of dangerous condition with high voltages, implement a big physical safety switch. How much trust do you want to place in the coding skills of yourself, Microsoft, etc.?
0 Kudos
Message 9 of 12
(4,497 Views)
I forgot to notice that you're also using the Stop function. This is a really bad thing to do as I mentioned earlier. Doing this will not do anything about a dangerous hardware condition. All it does is stop the program without doing the possibility of any hardware reset that you would need to do. I don't think you really want to leave the hardware in an unknown state.
0 Kudos
Message 10 of 12
(4,497 Views)