TIME Command
Does anyone use the TIME command?
I am using it to send the current time to AXB-TMCs once a day in DEFINE_PROGRAM with a flag so my event only occurs once each time 06:00:00 comes around.
Is this a typical usage for the TIME command?
Does anyone find it otherwise useful?
Thanks!
I am using it to send the current time to AXB-TMCs once a day in DEFINE_PROGRAM with a flag so my event only occurs once each time 06:00:00 comes around.
Is this a typical usage for the TIME command?
Does anyone find it otherwise useful?
Thanks!
0
Comments
IF(TIME='23:00:00')
{
// SHUT SYSTEM DOWN
}
Joe
Or if you want to use the wildcard(??), valdating the expression for the entire minute:
IF (COMPARE_STRING(TIME,''12:00:??'))
{
// SHUT SYSTEM DOWN
}
i do things with TIME, like downloading tv guides early in the morning for the next day; reseting log files just after midnight; for very remote systems, i ensure they do a reboot at 4am every day (i don't want an inaccessible device that's 300 kilometres away to hang); if the time is equal to sunset, turn on some lights, or open/close blinds
i tend to place repeating, relative time events into a timeline. this is better for example when checking weather or news, every 60 minutes or so.
just my 2 cents worth.
Also keep in mind that the "If(Time='23:00:00')" will be true for a full second, and will execute multiple times. Make sure if you're doing something that should only be done once that you set a flag or somthing to make sure that it doesn't happen multiple times. I usually use a "Wait 11" for that purpose.
--D
The '??' wildcard will not work in NetLinx!!!
Some kind of funtion I'd do:
DEFINE_VARIABLE VOLATILE INTEGER ZeitFlag DEFINE_FUNCTION CheckForTime() { STACK_VAR SINTEGER Hour, Minute, Secund // get current time Hour = TIME_TO_HOUR(TIME) // get hour of system time as a numeric value Minute = TIME_TO_MINUTE(TIME) Second = TIME_TO_SECOND(TIME) SELECT { ACTIVE((Hour = 12) AND (Minute = 0)): // { IF(NOT(TimeFlag)) // to prevent multiple executions { // Lock time check TimeFlag = 1 // Do what you want } } ACTIVE((Hour = 12) AND (Minute = 1)): // activate timecheck again { TimeFlag = 0 } } } DEFINE_PROGRAM WAIT 200 // check every 20 seconds only { CheckForTime() }Please read Tech Note Number 555
However... nice to have functions to get the time elements numeric
Every 15 minutes
local_var integer nRunOnce If (Mytime.Minute == '00' || Mytime.Minute == '15' || Mytime.Minute == '45' && Mytime.Seconds == '01' ) { if (!nRunOnce) { // do something nRunOnce = 1 wait 15 { nRunOnce = 0 } } }I use the seconds to allow for a short wait to keep the event from repeating during the duration of the minute. So I wait for 1.5 seconds whichs is 1/2 second longer than the duration of the second of which the event would evaluate as true and keep repeating through every pass if not for the wait and the local variable nSBRunOnce.
DEFINE_TYPE structure sTime { char Hour [2] char Minute [2] char Seconds [2] } DEFINE_VARIABLE non_volatile sTime MyTime DEFINE_FUNCTION fnProcessTime(char iMyTime [8]) { if(length_string(iMyTime) == 8) { MyTime.Hour = get_buffer_string(iMyTime,2) cRSSTrash = remove_string(iMyTime,':',1) MyTime.Minute = get_buffer_string(iMyTime,2) cRSSTrash = remove_string(iMyTime,':',1) MyTime.Seconds = get_buffer_string(iMyTime,2) } } DEFINE_PROGRAM { stack_var char cMytime [8] if (cMyTime != TIME) { cMyTime = TIME fnProcessTime(cMyTime) } if (Mytime.Minute == '05' && Mytime.Seconds == '01') { local_var integer nRunOnce if (!nRunOnce) { send_string 0,"'Time ',Time,' - Updating Doing Something!',crlf" Do something nRunOnce = 1 wait 15 { nRunOnce = 0 } } } }IF(COMPARE_STRING(TIME,'10:00:??') AND nBLOCK == 0) { nBLOCK = 1; //DO SOMETHING WAIT 700 nBLOCK = 0; //reset }I use the time string for HVAC setbacks - we have a customer who sometimes turns zones off, but forgets to turn them back on. With Michigan weather - this can become an issue quickly from rapids temperature changes.
As a result in my timeline for feedback I use this:
IF(TIME='02:00:00')
{
//TO SAVE SPACE I WONT WRITE OUT THE LOOP,
//BUT IT IS A FOR LOOP THAT TURNS THE ZONES ON.
}
Works well.
As a result in my timeline for feedback I use this: IF(TIME='02:00:00') { //TO SAVE SPACE I WONT WRITE OUT THE LOOP, //BUT IT IS A FOR LOOP THAT TURNS THE ZONES ON. }Just keep in mind that if your feed back timeline repeats @ 200ms your code will run 4 or 5 times before the "if" is no longer true. 9 or 10 times if your feedback timeline is 100ms. If it were in define_program w/o a wait it would probably run 1100 times.vining,
You are absolutely right, which is why this time line is at 1000ms. It is a seperate timeline for the HVAC feedback. You do point out something that is a good detail that less experienced programmers might miss. Also you made me realize that I did not put enough detail in my hastily crafted post. Sorry to all for any confusion.
Dave