LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

for loop interrupt

Solved!
Go to solution

Attached please find my test vi(i use while loop instead of for loop,cause my labview version is 8.2, which don't have interrupt condition item in for loop. )

i wanted to stop the vi while the vi was running, such as i pressed the stop button when i was 4, the vi wouldn't stop immediately,it first finished the current cycle, gave me the 5th random number and time delay, then it ran the next cycle and gave me the 6th random number and stop, so i had to wait some time(time delay+the 6 cycle duration)since i pressed the button, now i hope someone can give me some advice that don't let the next cycle happen and stop the vi immediately.

0 Kudos
Message 1 of 7
(4,112 Views)

Your Stop button gets read very early in the iteration of the outer loop.  So if you read it, it gets read at the local variable in the inner loop, but it was already read as its original false in the outer loop, so the outer loop iterates again.

 

Try putting the stop terminal in the inner loop and wiring out of it through a tunnel to the stop condition of the outer loop.  Is there a reason for the outer loop?  A state machine architecture might be a good idea.

0 Kudos
Message 2 of 7
(4,105 Views)

You probably should use an event structure instead. If you place a 10s wait, the loop cannot finish until the wait has elapsed.

If you use the timeout case of an event structure, it wil react immediately to other events.

 

Here's a simple example to get you started.

 

 

Message 3 of 7
(4,103 Views)

to altenbach:

thanks for your help,  it's very helpful. But i still have a small problem, your example vi don't creat the first random number immediately, it waits 500 million seconds. If i change the number "500" to a much bigger number, i have to wait a longer time to get the first number, so how can i get the first number immediately while others wait?

0 Kudos
Message 4 of 7
(4,086 Views)

to Raven Fan:

since i only learn labview for a few weaks,  so i'm not familiar with the "state machine architecture" yet ,but i'll try to learn it ,thanks for your help anyway!

0 Kudos
Message 5 of 7
(4,082 Views)
Solution
Accepted by topic author 413332985

413332985 wrote:

to altenbach:

thanks for your help,  it's very helpful. But i still have a small problem, your example vi don't creat the first random number immediately, it waits 500 million seconds. If i change the number "500" to a much bigger number, i have to wait a longer time to get the first number, so how can i get the first number immediately while others wait?


No, that's not correct. The initial timeout is 0, so it generates the first random number immediately. Try it once more.

 

Here's a modification that shows it more clearly. Once the program is started, you need to press another button to start with the random numbers. As you see, the first one appears immediately.

Message 6 of 7
(4,069 Views)

i might know where my problem was. i put a start button in "time out loop" and conneted it with a case structure, the time i pressed the button a time delay happened too. it 's all because i couldn't use event structure quite well.

thanks altenbach, you help me a lot, i still have a lot to work on.

0 Kudos
Message 7 of 7
(4,008 Views)