LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to stop and close subvi without stopping main vi

rctrigger

               Have you tried my VIs? 

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 11 of 18
(2,236 Views)

It's true that you need all while loops in the subvi to stop for the sub vi  to properly close and prevent the main vi from hanging. For the event case, it would be better to have one event case structure that handles all events. To add events to your event case structure, right-click and then select "Edit Events Handled by This Case" or "Add Events Handled by this Case". In summary, in your main vi you should have one event case structure that handles both the default case and your "Exit" Value Change case, and a similar set up in the sub vi. This would reduce the number of while loops in your code, which I suspect is causing some of the freezing.

Taylor B.
National Instruments
Message 12 of 18
(2,214 Views)

Another idea, in your sub vi, you could try linking the Cancel Boolean control to all the stop conditions, rather than using a local variable. Values can pass through while loops. However, that will force the while loops to stop in a certain order, which you may or may not care about.

Taylor B.
National Instruments
0 Kudos
Message 13 of 18
(2,212 Views)

@TBirkulosis wrote:

Another idea, in your sub vi, you could try linking the Cancel Boolean control to all the stop conditions, rather than using a local variable. Values can pass through while loops. However, that will force the while loops to stop in a certain order, which you may or may not care about.



Can you demonstrate what you mean by these statements?  What you are describing sounds like you are breaking data flow and will keep parallel while loops from even beginning to start until prior ones finish.

0 Kudos
Message 14 of 18
(2,200 Views)

It's correct that you can't connect while loops that you want to run in parallel.

 

Here is a good example of how to close the sub vi once the cancel button is finished: https://decibel.ni.com/content/docs/DOC-10571

In this code, instead of having the VI's FP.close invoke node in a while loop, they have it in a flat sequence structure connected to the while loop. I made example code that implements this. I noticed that the Mechanical Action associated with the Stop Boolean (or the Cancel Boolean in your case) effected if the value stayed true when pressed. I had to have the Mechanical Action of my Stop button set to Switch When Pressed for it to work.

Taylor B.
National Instruments
0 Kudos
Message 15 of 18
(2,184 Views)

Actually, looking at your code, I think it is the Mechanical Action of your Cancel button that is failing. You have it set to Switch Until Released. The Cancel Boolean is only True when pressed. You should changed to Switch When Pressed for it to function correctly. You can change the mechanical action by right-clicking on the Boolean and selecting Mechanical Action. Try that and let me know if it works!

Taylor B.
National Instruments
0 Kudos
Message 16 of 18
(2,183 Views)

Thanks Ranjeet_Singh for your VI,

 

However, I am dealing with subvis in which I need to pass data from the main VI to the subVIs. I modified your main and sub VIs to pass data, and now the subVI stops, but does not closes.  (see the attached files).

 

Do you know how can I fix this?

 

 

Thanks,

 

Daniel

Download All
0 Kudos
Message 17 of 18
(1,883 Views)

Hi Daniel,

 

I noticed that you are not opening or closing your reference in your main VI. Check out this tutorial about calling a VI by reference. It talks about closing references and best practices for calling a VI by reference.

 

http://www.ni.com/tutorial/3929/en/

 

Best,

Doug

Aaron Douglass
Applications Engineer
National Instruments
0 Kudos
Message 18 of 18
(1,852 Views)