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: 

Stop Button Not Working

Solved!
Go to solution

Before anyone says anything about this issue being brought up a lot of times, believe me I have looked at most of those forum posts before deciding to write one myself. I also discussed with my other friends and theirs seem to work but mine doesn't and no one knows why. 

 

This program is about a car wash system, where customers can choose different types of car wash. After that, the program runs through the cycles for the respective type before the program resets. 

 

The problem is when I try to press the stop button half way through the program, the program doesn't stop as if labview is not reading the button press even though it works for my friends. If any of you have any suggestions on how to fix it, please let me know. Thanks in advance!

0 Kudos
Message 1 of 6
(1,561 Views)
Solution
Accepted by topic author KentLiew

Well,  you know this has been brought up a lot of times ....   😉

Actually, the car wash example is quite common, and this is the 3rd post I've seen on one in the last few days.  So you can go look at others to see how they do things, whether good or bad.

 

I see two things in your VI that could cause the issue you see.

 

First, remember the basic rules of dataflow:

1.  A structure or node won't begin until all the inputs it have arrived.

2.  A structure or node won't complete and pass data out until all the code inside of it is completed.

 

Your Stop button is read within the while loop, pretty much right away on every iteration of that outer while loop.  It won't be read again until all other code in the while loop completes and the while loop moves to its next iteration.  And then that iteration where it is read as True will still need to complete before it ends.

 

Two things in your code can keep that from being read quickly.

 

You have several states (i.e. cases within the case structure) with internal while loops that won't complete until a timer has elapsed.

Also, you have one state, "Choice", which has an event structure with no timeout defined.  Your code will pause there indefinitely until you press the Deluxe or Economy button.

 

The secret is to not have any case where it spends a long time in.  For the loops with timers, get rid of the internal while loop.  Let the master while loop iterate more frequently.  If the time has not elapsed, then the same state is passed into the shift register to be checked again for the timer.  If the time has elapsed, then move into the next state.

 

For the event structure, use the timeout case that is already there, but wire up a timeout value to the timeout node.  Have it go back to the choice state in the event of a timeout.  (Kind of weird in that you are sort of hybrid using events and a polling scheme.)   Or put a Stop Value Change event in that event structure that will pass a True out to the while loop's stop node.  You can OR that with the existing stop button.

 

PS:  Why are all of your terminals sitting on the left side unused, yet you use tons of local variables.  Get rid of some local variables and replace them with the terminals.

Message 2 of 6
(1,554 Views)

@RavensFan wrote:

The secret is to not have any case where it spends a long time in.  For the loops with timers, get rid of the internal while loop.  Let the master while loop iterate more frequently.  If the time has not elapsed, then the same state is passed into the shift register to be checked again for the timer.  If the time has elapsed, then move into the next state.


First of all, thanks for taking the time to answer my question. I think I might have solved the event structure thanks to you, but here you said to use the master loop more. If I were to use the master loop for the timer, then how would I reinitialize the timer value back to 0 for the other states?

0 Kudos
Message 3 of 6
(1,526 Views)

@KentLiew wrote:

If I were to use the master loop for the timer, then how would I reinitialize the timer value back to 0 for the other states?


You can set it back to zero at the end of the previous state as needed. Right?

Message 4 of 6
(1,522 Views)

When you make the change from one state to the other, put a value of 0 into a shift register.

Message 5 of 6
(1,513 Views)

@RavensFan wrote:

When you make the change from one state to the other, put a value of 0 into a shift register.


For some reason I struggled quite a bit on this one, just didn't quite know how to do it. I slept on it and I found a way to do it in the morning! Thank you and @altenbach for helping me out, learnt quite a few things today and I'm sure there are lots more to learn in labview. 

0 Kudos
Message 6 of 6
(1,491 Views)