LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stop Finction that Stops Sub-VI but Not Main-VI

I have a main VI, running several sub-IVs, which in turn run several sub-VIs. Many of these sub-VIs contain while loops, and sequence structures.

I would like to be able to 'break' or end a sub-VI (much like the STOP function) and not end the main-VI. I would prefer not to wire the while loop stop buttons through all the levels of the program.

More generally, is there a break function for sequence structures? Can a exit a sequence without passing through every frame?
0 Kudos
Message 1 of 5
(2,731 Views)
First of all, the best way to Stop the sub-vi is by applying the logic to the while loop conditional terminal. Depending on the nature of your algorithm you can do one of several things. One simple way is to let the sub-vi window open when it is called and have a STOP button on the sub-vi front panel. A better way is to pass a reference to a front panel control to the sub-vi and therefore read the control from the main vi to determine the exit logic in the sub-vi.

With regard to the sequence structure there is no way to exit the sequence without completion (well, perhaps you could put case statements in each frame of the sequence, but that would get complicated). You would be better off to convert the case structures to a state machine structure which readil
y allows skipping around within the structure as well as exiting using simple logic.
0 Kudos
Message 2 of 5
(2,731 Views)
One way is with a reference to a control on the main VI. Another way to do it programmatically is to use notifiers. If you set up the while loops in your sub-VIs to watch a notifier, then you can "tell" a sub-VI to close from anywhere else in the program. With notifiers, you do not need a control on the main (or any other) VI.

I have included the VIs that I built to test this function using references. The cancel button stops the execution of the sub-VI but leaves the main VI running. You can also notice how much slower the loop using references is. If you put the STOP function in the sub-VI loop (connected to the boolean read), you can see that it stops ALL VIs in this program.

Have fun with it.

Rob
Download All
0 Kudos
Message 3 of 5
(2,731 Views)
You're right that notifiers are a better way to handle this problem. I have attached a sample vi that does the same thing that your vi's with reference did. I did change a couple of actions. First, I made the subvi stop once the main loop of the vi stops (in your example you have to independently stop both the main vi and subvi). Also, I made the counter for the subvi reset just like you did with the main vi counter. There are certainly other ways to do this, some of which may be more efficient, but this was what I could quickly come up with.

By the way, in case there was confusion about my suggestion of a STOP button on the subvi panel, the STOP button was intended to be wired to the loop in the subvi and not to a STOP function. This
is certainly not the best option but could be the easiest to implement in DrWalker's already written code, although it doesn't work if there are a number of subvis operating at the same time.
Download All
0 Kudos
Message 4 of 5
(2,731 Views)
Yeah, I built those VIs quite a while ago to test the "stop the loop" thing in a sub-VI. I've since built a set of library functions to make the references much easier to use. And yes, both loops have to be stopped seperately. I didn't spend a lot of time on something just for a quick test.

Rob
0 Kudos
Message 5 of 5
(2,731 Views)