From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to stop loop in SubVI from Main VI?

Hello everybody,
My problem is probably simple for advanced LabVIEW users since I just learn this language.
I have created a subVI which makes some processing in a While Loop. This subVI is called from higher lever VI, and on the front panel of this VI I have got a button called "Stop" which I want to stop the loop in the SubVI. I tried to use Control Reference to this button and pass the value of button to subVI but it didn't work. Do you know any solution for my problem?

TIA,
Yazilim.
0 Kudos
Message 1 of 11
(3,913 Views)
You can use global variables to pass data from one vi to another.
Create a global variable with Stop button inside (Functions/Structures/Global variable, then double click on it and create a button on its front panel). Save it to disk. Then write data to this variable in your main VI, and read this variable in your subVI.

Good luck.

Oleg Chutko.
0 Kudos
Message 2 of 11
(3,913 Views)
This is hard to say exactly what is going wrong without seeing the program. A few things to check though:

You could make a "Stop" button in the subVI and set its value from the main VI by reference. Make sure that the "Stop" button on the VI diagram is INSIDE the while loop. If it is outside, the value only gets passed in once and it does not matter what the value changes to after that (unless you check it by reference from INSIDE the while loop).

If the mechanical action of a button that is called by reference is "latch when..." then the results can sometimes be a little unpredictable. Change these buttons to "Switch when...". And don't forget to turn them off again after reading a TRUE by reference.

I use subVIs to change/read the controls and ind
icators on my main VI all the time. I open a reference to the VI during initialization and pass this reference (along with the error cluster) down the line in my main program. I have included a short VI that I used to test my reference library. See if you can use some of it. Run the "Loop Test.vi" from the library.

Rob
Message 3 of 11
(3,913 Views)
Hi Oleg

I wanted to be clear about which method to use when passing values between main and subVI.
My program will have a main VI which will be consisted of few subVI's.
Take for example one of the subVI's, the multi-gauge instrument that measures the pressure. If I want to change the units of the pressure from Torr to Pa I am using enum inside of subVI. Now when main VI is running and the user changes the units on the front panel of main VI do I use reference of my enum or global variable method you described or some other method?

What is the best way of passing data from main to subVI in general?

Thanks,
Pedja
0 Kudos
Message 4 of 11
(3,913 Views)

Hi

I have a lot of subVi with loops which I want to stop them from MainVi with Stop button ,I tried with global variable,but it does not work,I don't know what should I do!! I would really appreciate if somebody tell me a solution !

 

Thank you

0 Kudos
Message 5 of 11
(3,149 Views)

@casper747 wrote:

Hi

I have a lot of subVi with loops which I want to stop them from MainVi with Stop button ,I tried with global variable,but it does not work,I don't know what should I do!! I would really appreciate if somebody tell me a solution !

 

Thank you


Yeah, take a look at Rob's kudod post above...

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 11
(3,134 Views)

@casper747 wrote:

Hi

I have a lot of subVi with loops which I want to stop them from MainVi with Stop button ,I tried with global variable,but it does not work,I don't know what should I do!! I would really appreciate if somebody tell me a solution !

 

Thank you


use "stop" references and take a look at notifiers....

abort notifier ver8.5_BD.png

0 Kudos
Message 7 of 11
(3,094 Views)

example.PNG

0 Kudos
Message 8 of 11
(3,069 Views)

Hi

Thank you for your solution but I can not open it in labview8.2  😞 

0 Kudos
Message 9 of 11
(3,031 Views)

Hi

Thank you for your solution but I can not open it in labview8.2  :smileysad: 

0 Kudos
Message 10 of 11
(3,024 Views)