Real-Time Measurement and Control

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

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
(1,231 Views)
Solution
Accepted by topic author emmab
05-22-2017 04:37 AM

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.


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 2 of 6
(1,223 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
(1,220 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


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 4 of 6
(1,216 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
(1,214 Views)

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


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 6 of 6
(1,204 Views)