Basic Q: What's the most effic way to do time-of-day events?
youstra
Posts: 135
I've got to do multiple time-of-day events - should I put an IF in mainline to start an absolute timeline at midnight? Seems fairly wasteful to run a constant IF test....
Apologies for the basic question.
-Bill
Apologies for the basic question.
-Bill
0
Comments
Time can be based on timeservers, but will also work fine with the NI master's internal clock.
There is nothing wrong putting your time evaluations in mainline (Define_Program section.)
I would use the following:
Make sure you put in the Wait 11 so that the timed event only runs once. This is because the Active statement will be evaluated many times over the course of a second and the Wait will only be started once. Without the Wait the code under the Active would run many many times depending how large your program is.
Just for fun, try this.
Check the value of nCount to see how many times Define_Program loops in one second.
I was under the impression that the Wait has to be named to avoid being run more than once. But, I might be mistaken as I haven't worked with this type of scenario lately.
Jeff
I do it like this:
I set a flag, first of all, for every event, and test a new day to reset them. Depending on the precision needed, I then run a flag checker on a timelijne. If I only need to-the-minute precision, the timeline fires every 60 seconds, for example. Inside the timeline is a function call that does something like this (this example uses to-the-minute precision): You can add whatever other handling is needed for manual resets or recurring events. This is a very simple code block, and has practically no overhead to maintain. You can even (and I have done this) make a way for the client to adjust the times from the panel simply by changing the values in nTimers, giving much more flexibility to it, and you can add another set of flags to turn events on and off semi-permanently.
Edit: Pft! What happened to QUOTE blocks preserving whitespace??
I use a Timeline that triggers every 60 seconds with an array for the user defined days (selected_days[7]), if a day IS selected then I'll look at the user defined TIME.
Jeff,
A Wait does not need to be named unless you need to cancel it. Otherwise they both behave the same.
Brian