LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to schedule an event to occur in the future?

Solved!
Go to solution

I'm not sure I understand your problem then. The scenario I had running (and I checked before posting) was:

 

Event A to run 5 seconds after every other event (the timeout - I kept it simple)

Event B was triggered from a button on the front panel

 

Press Button - Event B triggered

Wait 2 seconds

Press Button - Event B triggered

Wait 6 seconds

After 5 seconds - Event A triggered

 

Had I wanted to ensure that event A hadn't been reset then I would have some time maintenance going as well, with a couple of shift registers, or a functional global.

 

If what you want is to trigger event A early, then just queue it early, and manage the queue. Don't forget there is a flush queue VI which will just empty the queue of all data which is what I use whenever I need to quit a producer/consumer set of loops - producer flushes queue then enques quit element - all that is then in the queue is the quit, and no errors. I probably assumed a producer consumer, or a looped state machine which runs continuoulsy with a stop only occurring in one specific situation, which means that a dequeue will only timeout when it has not had any other element populated within that time.

0 Kudos
Message 11 of 17
(1,447 Views)

@altenbach: You are right, I was not consistent in my terms, sorry.

 

What time resolution do you want/need? Please be specific. (milliseconds, seconds, etc.) 

I envisage timing requirements from a few ms to a few seconds. I am not trying to reprdouce a real time system. I am not (currently) worried about accuracies of better than (waves hands around) 10ms, say. If I specified a delay of x ms in my application this way, I would take it to mean 'not less than about x ms'. I am happy to accept the time resolution and accuracy that Windows and LabVIEW deliver in using counts in ms is fine even though sometimes it can be quite jittery.

 

The sorts of tasks I have in mind in this particular case are 'turn an indicator on / off after about 1/2 second or a second or 2 seconds', or send a serial command to a piece of equipment which takes between 0.1s and 0.2s to do it (but doesn't provide feedback), so do the next thing after about 300ms...

 

So, first of all, do you even use event structures?

Yes, my whole application is event driven - I didn't mean to sound like such a newbie. I use user interface events, VISA events etc. I use queues to manage the actions from the user interface that take longer to do and to pass the data around the program in a lossles way etc. That's why I was looking for an generic method to allow me to cause events to happen at some point in the future.

 

 

For example you could look at the array of scheduled tasks and recalculate a new timeout value for an event structure whenever a new task is added or whenever a task has just executed. No polling needed. In the timeout event, determine which task is ready to execute and launch it. (e.g. via a queue or similar).

Yes, exactly what I was thinking but I didn't realise I could change an event timeout value once it had started. I would have to do that from outside the event structure. So, thinking aloud, I would need two while loops, one to dequeue the requests, sort the array and work out when the next event was scheduled and post the request with a notifier and then the second while loop with the timeout event structure in it taking its timeout value from the notifier. But isn't whatever applies the value to the Timeout, polling?

 

 

0 Kudos
Message 12 of 17
(1,433 Views)

@Intaris: I think you've got it. And I think that's what Yamaeda was suggesting (or what it made me think of). It looks like the way to go.

0 Kudos
Message 13 of 17
(1,427 Views)
Each timeout or scheduling change will require calculation of the next timeout task. Also, all other events will of course break the timeout. All you need is some code after the event structure that determines the next timeout delay and place it in a shift register.
0 Kudos
Message 14 of 17
(1,422 Views)

@KatherynB: Good idea, I think the 'flushing the queue' method would work but I think the simplest thing to to is to lauch a clone subVI for each task which runs independently and then cleans up after itself so I'm going to try that first.

0 Kudos
Message 15 of 17
(1,418 Views)

I did what Intaris suggested. Beautifully simple and works like a charm. Took me less than 2 minutes to implement and test it. Thank you all for your help 🙂

0 Kudos
Message 16 of 17
(1,404 Views)

You're welcome.

0 Kudos
Message 17 of 17
(1,368 Views)