LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to circumvent For Loop wait time

I have a timed For Loop that runs once per minute...  The STOP button for the entire code is inside this For Loop and after days to weeks of running this code, when I'm ready to stop execution, I press the STOP button on the Front Panel.  I have the button set up to ask "Are you sure" to allow the operator a chance to say "NO" if they have accidentally hit the STOP button.  But, say for example you hit the STOP button (and really do want to Stop) say 10 seconds into the next 60 second cycle.  The "Are you sure" message won't come up for another 50 seconds...  Is there a way, using occurences or events or whatever (??) to cause that delay (loop timer) to be short circuited such that the response to pressing the STOP button occurs immediately???  thanks...

0 Kudos
Message 1 of 6
(2,646 Views)

Don't put your UI code in the For loop. Use a producer/consumer architecture where your UI code is controled using event structures. You can respond very quickly that way. For your consumer loop use a queued message handler (some call it a queued state machine). You can inject a stop message into the task when the event structure detects the stop button has been pressed and accepted. In addition, the state machine of the consumer would use a smaller delay (sort of polling) to be more responsive. Your UI loop could use the timeout case to fire a message to the consumer to perform your period task. That way the consumer is effectively idle unless it receives a message.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 2 of 6
(2,638 Views)

Well Mark beat me to it but He is exactly right.  If you find that you are in pain you've done something to cause yourself pain.  In this case you created UI that is not responsive to user input.  When the user sais close the program needs to be able to close.  Loops with intervals greater than 200mSec are poor practice for that very reason.  Run your consumer faster and use Elapsed Timer to control what state executes in the consumer loop.  There is a good shipping example for Elapsed Timer.


"Should be" isn't "Is" -Jay
0 Kudos
Message 3 of 6
(2,634 Views)

Hi...  I'm currently hunting for your Elapsed Timer example in LabVIEW 2011.  So far I've persued Examples/General but haven't found yet what I think you're referring to...  Any help???  thanks...

0 Kudos
Message 4 of 6
(2,620 Views)

See the search button on the functions palette? That is all that you have to use though if you go to the timing palette, you should immediately spot it there. Please make sure you always have Context Help turned on as well.

0 Kudos
Message 5 of 6
(2,614 Views)

Oh, I thought you were talking about an example that used the Elapsed Timer, not the function itself...  Yes, I certainly see it...  thanks...  bob...

0 Kudos
Message 6 of 6
(2,599 Views)