02-10-2020 05:29 AM
Hi everyone,
I have a problem with a while loop. It doesnt react to the boolean input that i give it, but it just continues to run the SubVI. Can anyone help me? I'm a bit of a newbie so it might be something rather basic. Picture of my VI is attached.
Solved! Go to Solution.
02-10-2020 05:40 AM
The loop should stop if you press the Boolean button _unless_ the sub-vi doesn't stop but continues to run forever. You can get a similar feel if the sub-vi takes a very long time, in which case it'll probably stop after next loop, however long that is. This is because the Boolean is 'free' and will be read at the same time as the sub-vi starts, so if you press it during the sub-vi's run it'll be read at the start of the next loop iteration.
If you run the VI in Highlight mode (the light bulb on the toolbar) you should see that happens.
/Y
02-10-2020 07:21 AM
Thanks for your answer. However I don't have the same issue when using a case structure, as you can see in the file attached. In this VI the output reacts to the boolean input. If I press the button the motor moves (thats what the SubVI does), and if I release it, it stops automatically. I'm trying to stop the motor with the while loop just like I can with the button in this scenario. Are you sure this is an issue with the SubVI?
02-10-2020 07:36 AM
Please do not share Image/SnapShot, Its good to share code/Snippet for the forum users understand your problem easily.
In your Latest image it will skip executing subVI so that it will respond immediately, but which is not the case in earlier one.
02-10-2020 07:43 AM
@stormbreaker18 wrote:
Thanks for your answer. However I don't have the same issue when using a case structure, as you can see in the file attached. In this VI the output reacts to the boolean input. If I press the button the motor moves (thats what the SubVI does), and if I release it, it stops automatically. I'm trying to stop the motor with the while loop just like I can with the button in this scenario. Are you sure this is an issue with the SubVI?
A case structure and a while loop are two entirely different things. In the case of the case structure you will never enter the TRUE case if the boolean is FALSE. A while loop is designed to loop, and will always execute at least 1 time. This means that your subvi will execute one time even if the boolean is already TRUE when you enter the loop. In the event that it is FALSE when you enter the loop but is changed to TRUE while the subvi is running the subvi will complete that run and the loop will likely run one more time because the boolean was most likely read before it was changed. I suspect that what you really want to do is put a loop around your case structure code. You will then need to determine a stop condition for your loop (a STOP button will work).
02-10-2020 08:28 AM
@stormbreaker18 wrote:
Thanks for your answer. However I don't have the same issue when using a case structure, as you can see in the file attached. In this VI the output reacts to the boolean input. If I press the button the motor moves (thats what the SubVI does), and if I release it, it stops automatically. I'm trying to stop the motor with the while loop just like I can with the button in this scenario. Are you sure this is an issue with the SubVI?
A case structure only executes _once_ unless you're using the semi circular "Run Continuously"-button, WHICH YOU SHOULDN'T DO! 🙂
Change the button to "Switch while pressed" and reinsert the While (and a 10ms Wait in the loop). 🙂 Is the motor supposed to step once for a loop so you need to activate the sub-vi repeatedly?
(I don't mind the screen shots as i don't have LV on this computer)
/Y
02-10-2020 09:37 AM
"Run continuosly" was the issue here. Without that everything worked as expected. Thanks everyone for yor help!
02-10-2020 10:28 AM
Grrr... I think NI should relegate the "Run Continuously" option to the "Run" menu so inexperienced LabVIEW programmers won't be tempted to use it as a non-debug way of running a VI.