LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

stop a loop with wait timer

I have a state machine and within one of the states i have a while loop where I poll a device every 20 seconds.  I am using a wait timer for 20 seconds to perform the polling.  The problem is that I have a stop button for the loop, but it does not stop when I press the button.

 

Is there a better way to poll the device every 20 seconds which gives me the flexibility to stop the loop whenever I want?

 

 

Thanks,

Gary

0 Kudos
Message 1 of 8
(4,732 Views)

Take a look at the picture below.  This will give you the ability to stop in between polls, but it does not gaurantee that the polling will occur exactly on the 20 second mark.

 

 

Message Edited by jmcbee on 11-18-2008 09:48 AM
0 Kudos
Message 2 of 8
(4,724 Views)
Thank you very much.  This should work.  I will try it out.
0 Kudos
Message 3 of 8
(4,719 Views)
Another good approach would be to use a notifier.  Let "Wait on Notification" handle your loop timing.  When someone clicks the Stop button, send a notification.  The Wait on Notification node will then stop waiting immediately.  If there's no notification and the Wait on Notification times out, continue running normally.  You'll need to put the Stop button in a separate loop with the Send Notification.
0 Kudos
Message 4 of 8
(4,704 Views)

Would an event structure work.

 

place an event structure in the loop.

Wire a stop button (placed in an event responding to stop button value change) then wire it outside the event structure to the stop symbol on the loop

 

Put the polling in the/a timeout event ...  when that event goes off then check your system.

Put the stop button in an event ... when the button is depressed it will stop the loop.

 

There is also some real power in the timed events that I haven't mastered yet that might do some neat stuff as well.

 

Good Hunting.

0 Kudos
Message 5 of 8
(4,699 Views)

This example works.

 

Set the millisecond delay for the timout event first...

Then run the example.

The active lamp will change state every time the timeout function runs...

The vi will stop when you hit the stop button.

0 Kudos
Message 6 of 8
(4,693 Views)
0 Kudos
Message 7 of 8
(4,692 Views)

I agree with Hummer, an event structure is the best way to handle UI events such as pressing the Stop Button.  Here is what I think Hummer was describing.  This architecture will handle the Stop button press at any time, and if you just happen to press it while its executing the timeout case, it will queue it up and handle it as soon as that is done.  The other great thing is that you are not even polling constantly so your CPU resources can be put to better use elsewhere.

 

 

 

Looks like I was a little late to the party on my response, I can't open 8.5 stuff but I'll assume it's pretty similar.

Message Edited by SiegeX on 11-18-2008 01:16 PM

Message 8 of 8
(4,689 Views)