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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stopping a while loop that is dependent on another a case structure.

Solved!
Go to solution

I have done a lot of resarch about this and i think i have narrowed down the problem very precisoucly. I want my user to enter a password and if the password is correct the alarm shouldn't sound. But if it is wrong i want the alarm to sound. The problem is i have no way of telling the alarm to stop the sound when the user inputs because the sound is locked in a while loop :(. I can't seem to make this while loop stop for some reason when the user inputs a new number. 

I would be very grateful to you genous people if you could help me here. On the VI i have stated where the problem is. (The problem occurs within the inner while loop). 
If you guys have any questions please let me know and i will try and answer them to the best of my abilities. 

Just a harmless student
0 Kudos
Message 1 of 6
(3,247 Views)
Solution
Accepted by topic author bahjat

All inputs to the while loop that are outside of the loop don't change after you enter the loop.  So if the first loop has a "False" wired into it, meaning not to stop, it will never stop.

 

You'll need to have something there that reads a new value every time.

 

I should note that it looks like your whole program structure won't work, though.  The event structure at the top can only fire one time each time the large outer while loop occurs, so right now it can never register any more key presses after you pass a "true" to the Alarm case structures you have in the bottom part of the block diagram.

Message 2 of 6
(3,240 Views)

That is my question :D. I figured out what was wrong with my system before i posted it on here. 

I just need ways to slove this problem 😞 

Just a harmless student
0 Kudos
Message 3 of 6
(3,232 Views)

You need to have two separate While loops (i.e. one on top of the other, not one inside the other).  One for your event structure and one to handle things that need to happen while waiting for events.

 

The easy (but somewhat "wrong") way to do this is to create controls containing the information you need to pass between the loops (in your case, probably an "Alarm on" boolean and a "Stop the loop" boolean).  Then create local variable(s) for each so that both loops can read/write to them in multiple places.

 

The "right" way would be to use something called "producer/consumer architecture" which you should be able to find a number of examples and tutorials on if you do a search.

0 Kudos
Message 4 of 6
(3,226 Views)

You don't have all the dependencies to test this file, but the structure is very wrong.

You should have your alarm playing in a separate parallel while loop and communicate with it via a queue or functional global variable.

The other internal while loop should also be in a separate parallel loop and communicate with it via a queue or functional gloval variable.

Once your while loops start they don’t accept any more inputs from the border. So your communications doesn't work.

Glad to answer questions. Thanks for any KUDOS or marked solutions 😉
0 Kudos
Message 5 of 6
(3,214 Views)

I was hoping that i would be able to avoid this because i figured out that i had a race condition 2 hours inot solving this problem (i'm a newbie whne it comes to labview). The local valirable is working correctly for now (I am at home so i can't implement the DAQ system). Once i get into University i'll let you know how things went. If the local variable works out i will accept it as a solution and post my result (and ofcourse Kudos you). 
Thanks for the suggestion, speak to you soon 🙂

Just a harmless student
0 Kudos
Message 6 of 6
(3,177 Views)