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.
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.
05-22-2017 05:18 AM
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
Solved! Go to Solution.
05-22-2017 05:44 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.
05-22-2017 05:50 AM
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
05-22-2017 06:01 AM
@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
05-22-2017 06:04 AM
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
05-22-2017 06:37 AM
As I said before, add another state for checking your stop condition.