11-18-2008 10:14 AM
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
11-18-2008 10:47 AM - edited 11-18-2008 10:48 AM
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.
11-18-2008 10:53 AM
11-18-2008 12:29 PM
11-18-2008 12:44 PM
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.
11-18-2008 01:08 PM
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.
11-18-2008 01:09 PM
11-18-2008 01:14 PM - edited 11-18-2008 01:16 PM
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.
