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!
Solved! Go to Solution.
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.
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?
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.