LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Aborting a SubVI

I have a VI that calls a subVI which runs a flat sequence loop. I am having trouble finding a way to stop the subVI so that the flat sequence does not finish the iteration. Basically, I want to be able to have a stop button on the front panel of my main VI that immediately aborts the subVI without progressing in the flat sequence. Any suggestions?

Matt
0 Kudos
Message 1 of 9
(4,703 Views)
You can use an Invoke node with the 'Abort VI' method and get a reference to your subVI and kill it that way, but it's not good practice to use Abort to stop a VI, it's really a developmet/debugging tool. Another problem is the Sequence structure, they cannot be broken out of before it's done executing all of its frames.

Your best bet is going to be to redesign your subVI so it doesn't use the sequence, and instead have it running in a While loop. You can then use a Queue to send a message from your main VI to the subVI to tell it to stop. A bit more work, but it's a better way to go about it.

Ed


Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
Message 2 of 9
(4,703 Views)
Ed,
Thanks for your help. I was afraid you might say that about the sequence loop. I had read some articles that lead me to believe that I should re-design to another type of loop. I have a number of tasks that need to be complete before the next task starts, which made it seem (at the time) that the sequence loop was my best choice. Will the while loop be ok for that kind of requirement?
Matt
0 Kudos
Message 3 of 9
(4,703 Views)
The while loop combined with a state machine breaking your problem up into pieces allowing you to check for abort at the end of each piece. Works well.
Stu
0 Kudos
Message 4 of 9
(4,703 Views)
A While loop would work, and is probably the most used structure in LabVIEW. But if the subVI just runs through once, then passes back to the main VI, the While loop isn't even needed. You only need a loop if you're going to be running until a certain condition is met, or if you need shift registers to store data.

If you don't need either of these, then don't even bother with a structure. If it's only going to be run once each time it's called, then you have no way of stopping mid execution except to use the Abort method. I guess you could divide your tasks up and check for a Stop command from the main VI before each task runs, then you could skip the remaining tasks using a Case structure around each one. This would require a sepa
rate loop running in you main VI to issue the Stop command because the loop that contains the subVI will be stopped while the its subVI is running and cannot send the command.

As for doing tasks in a certain sequence, that�s what dataflow is all about. Simply connecting a wire from one subVI to another will force then execute one after the other. A subVI or LabVIEW primitive cannot begin to execute until all of its connected inputs have their data. An easy way to do this is to push your tasks into subVIs, then, if there�s no data dependency between the tasks, you can add Error In and Error Out to all the subVI and connect them in a chain and that will control the execution order.

Look at the attached image. Each chain of subVIs will execute in the same order. The top one because of the error wire connected between the VIs, and bottom one because of the Sequence structure. The advantage of the top method is that you�re not locked in the sequence, plus you have error handlin
g to aid in debugging.

Hope that helps a bit.

Ed


Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
0 Kudos
Message 5 of 9
(4,703 Views)
Thanks for the help,

It seems to me that my best option at this point would be to have no loop at all. When I first implemented the flat sequence structure I was just begining with LabView and not sure of where my program was heading. Now I am pretty certain that no loop at all would work just fine. I also am implementing your suggestion of dividing up the tasks coupled with the case structure. I have done something like that in the past and it worked great.

Thanks again,
Matt
0 Kudos
Message 6 of 9
(4,703 Views)
Ed,

As I mentioned in my last post, I am working on using a stop command to halt a subVI. I have removed the loop and added case structures at certain intervals to skip the remaining tasks. However, I am having problems because the Stop command is only sent to the subVI once. I think this is what your were indicating when you said I needed a seperate loop in my main VI? Could you please elaborate on how that would work? I am a little confused on that matter.

Matt
0 Kudos
Message 7 of 9
(4,703 Views)
Since a picture is worth... well, you know.

Take a look at the attached image. It shows a very basic top level architecture that uses two While loops. The top loop could handle all of the user interface processing, and send commands through a queue to the other loop for processing.

In your case, the bottom loop that has your subVI would stop looping when it gets to the subVI, until the subVI has completed its execution, so any controls inside this loop will not be acted on until the subVI has completed, since they cannot be read until the loop iterates again.

The top loop will continue to run while the bottom loop is waiting on the subVI to complete. So when the Stop SubVI control is clicked, a True is enqueu
ed, which will then be read inside the subVI which is running. All you�d have to do is check the queue for True and then skip the remaining steps in your subVI.

Clear as mud, right?

LabVIEW 7 has some pretty good templates that show this type of setup. They call them either Master/Slave or Producer/Consumer architectures. In the �New� VI dialog, look under Design Patterns, then Frameworks and you�ll see them.

Ed


Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
0 Kudos
Message 8 of 9
(4,703 Views)
Thanks! That looks like what I need.
0 Kudos
Message 9 of 9
(4,703 Views)