From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

implementation of time triggered events

Solved!
Go to solution

imagine ive got a schedule to turn on and off many leds at a givent time of day as attached. (col 3=on  time, col 4 = off time).

whats the best way to implement this?

an event case firing events at given timestamps? (ive already converted strings to timestamps)

2 event structures (one for the on and one for the off times)?

a while loop with 1s period?

a timed loop? 

 

ps. this is going to be part of a larger project im working on. actually some serial bytes are going to be sent at every given time.

obviously i could go with a while loop ticking every second and comparing current time with my on and off timestamps, but  i can see its a waste of resources.

 

any ideas? thank you in advance.

0 Kudos
Message 1 of 10
(4,453 Views)

One thing you could implement is a "Scheduler".  Suppose you need to turn things on and off with a time accuracy and precision of 1 second.  You could create a "Schedule", an Array of Clusters that contain a Time and an Action (which could be a Boolean, On/Off, and an identifier to say which control to turn on or off).  You have one routine that adds new Events to the Schedule, another that acts like a Clock, firing once/second and seeing if anything is due to be Scheduled Now.  If no, then you "go back to sleep", otherwise handle whatever needs to be scheduled.  I recommend that you do this in a parallel process so that the "clock" runs independently from the process being scheduled.

 

Bob Schor

0 Kudos
Message 2 of 10
(4,394 Views)

i've already got a kind of scheduler. my on off timestamps are stored in a multicolumn listbox for each day of the week. i just need to generate an event at given times of day without using a while loop comparing every sec my system time with the given timestamps. 

 

wasting resources if you think that in a day i could have one or two timestamps.

any help on how to implement that?

0 Kudos
Message 3 of 10
(4,369 Views)

came with a solution. i calculate the time remaining to nexr event and feed it to a timeout event structure. works well but im having issues when i have the same timestamp for 2 items. works if they have 1sec difference.

 

but given that i need to send & receive serial commands at 9600baud instead of turning on off leds i would need some sort of queue for the commands to be sent that have the same timestamps (both on & off).

 

any ideas? thank you.

0 Kudos
Message 4 of 10
(4,352 Views)

I don't have LabVIEW 2016, so I can't look at your vi,

but be aware that the Event Timeout is not a reliable

timing method.

 

Any Event that occurs (like a button push or user Event) will reset the timer.

steve

--------------------------------------------------------------------------------------------------------------------------
Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
question. Give "Kudos" to replies that help.
--------------------------------------------------------------------------------------------------------------------------
0 Kudos
Message 5 of 10
(4,345 Views)

that event structure will only have the timeout event. 

i uploeaded a sc. the false case only increases the index. 

 

any other ways to generate events at given timestamps?

im new to labview so im short of ideas. thank you.

0 Kudos
Message 6 of 10
(4,344 Views)

I don't know how "new" you are to labVIEW - your block diagram is very

clean and organized - better than I've seen from some experienced people. Kudos.

 

Bob_Schor gave some very good advice earlier. I would like to add a bit to his mention

of using an Array of Clusters. If each cluster has a timestamp and an an array of

actions, you can handle those occasions where multiple events need to be performed

at the same time. Use a For Loop to process the actions.

 

I haven't been able to think of a way to avoid polling the timestamps for the next action(s)

but 1 one second interval should not cause any issues. I think you can do without the

Event structure.

 

For sending the data to your serial device, I would send the data (or request) to a

consumer loop using a queue.

 

You haven't said how accurate the timing needs to be. This would be useful to know.

 

steve

--------------------------------------------------------------------------------------------------------------------------
Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
question. Give "Kudos" to replies that help.
--------------------------------------------------------------------------------------------------------------------------
0 Kudos
Message 7 of 10
(4,328 Views)

thanks for that. like to keep things nice and clean. been using since august.

 

as for timing accuracy. on a given timestamp i should send a serial command and get a response from a plc. 

 

so two items with the same timestamp should be sent "simultaneously". obviously send second command after ive got the first response. so a queue should be useful here as you stated. one sec of a difference between the to commands is more than enough for me.

keep in mind that my "list" could have up to 20~30 items so 40-60 timestamps. so ill need to poll all of them each sec. 

 

as for the array of clusters. if i got it right. lets say ive got 20 items. so 40 timestamps.

you mean i should create 40 clusters with a timestamp and the command to be sent. then feed them in an array and poll them each sec? obviously will be handy to sort the array by the timestamps.

0 Kudos
Message 8 of 10
(4,311 Views)
Solution
Accepted by topic author afetsis

Yes, I would assemble the array in timestamp order.

Then you only have to check one array entry.

When you get a match, process it and increment the array.

Here is a simplified array of clusters based on your earlier posting:

Event triggers.png

Notice how multiple concurrent actions are handled (first element). The example shows

an array of strings for the action, but it could be a cluster of items if that is useful.

Be sure to name the cluster items and "Type-Define" your clusters.

steve

--------------------------------------------------------------------------------------------------------------------------
Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
question. Give "Kudos" to replies that help.
--------------------------------------------------------------------------------------------------------------------------
Message 9 of 10
(4,302 Views)

done. my timestamps with the respective serial commads. Smiley Happy

thank you all for your help.

0 Kudos
Message 10 of 10
(4,266 Views)