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.

Real-Time Measurement and Control

cancel
Showing results for 
Search instead for 
Did you mean: 

Stop multiple while loops

Solved!
Go to solution

Hi all,

 

I have written a small program in which I can control 2 motors. Within my control program I have written the option of being able to start an automated cycle which will execute indefinitely until a stop button is pressed in the main VI. The trouble I am having with this is that my automated program is written in a sub VI, inside a while loop. When I try to stop the program from my main VI, the sub VI continues to run. I have looked into using a global variable to do this but I still cannot seem to stop my program. 

I am fairly new to Labview so I figure it's just something that I have forgotten to include in order to make my global variable work correctly within the two VIs. 

 

I have attached the files that I have been working with as I know it can be difficult to grasp the issue from just a description!

 

Many Thanks,

Emma

 

0 Kudos
Message 1 of 6
(3,331 Views)
Solution
Accepted by emmab

1. You never write to your global variable.

2. Even if you did write to it on your top level VI, it would not be performed because the subVI would be halting your loop.

 

In general, you do not want loops in your states.  And you definitely do not want a state machine INSIDE of your state machine.  Move the code from your subVI and merge it with your main state machine.  Add in a state for checking to stop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 6
(3,323 Views)

Thanks for getting back to me on this so quickly. When you say move my code from my sub VI and merge it with my main one, how to you propose I do this? Should create the 4 states, that I have in my sub VI program, in my main one along with my 'init', 'direct mode', 'stop' cases etc? Or do I need to add some other kind of structure in to include my automated program?

 

Thanks again,

Emma

0 Kudos
Message 3 of 6
(3,320 Views)

@emmab wrote:

Should create the 4 states, that I have in my sub VI program, in my main one along with my 'init', 'direct mode', 'stop' cases etc?


Exactly


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 6
(3,316 Views)

How can I check in each of these states that the 'stop' button has been pressed? I have been using case selectors along with the stop control, but if I were to do this in every state, I would need 4 buttons. I also would like to be able to use latching so creating a local variable is not an option.

 

Thanks

0 Kudos
Message 5 of 6
(3,314 Views)

As I said before, add another state for checking your stop condition.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 6
(3,304 Views)