LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with While Loop

Solved!
Go to solution

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.

0 Kudos
Message 1 of 8
(2,550 Views)

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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 8
(2,545 Views)

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?

0 Kudos
Message 3 of 8
(2,518 Views)

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.

 

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 4 of 8
(2,509 Views)

@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).

0 Kudos
Message 5 of 8
(2,502 Views)
Solution
Accepted by topic author stormbreaker18

@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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 8
(2,491 Views)

"Run continuosly" was the issue here. Without that everything worked as expected. Thanks everyone for yor help!

0 Kudos
Message 7 of 8
(2,475 Views)

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.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 8 of 8
(2,462 Views)