AMX Clock Events
23 October 2008, 08:40 by Chad Reynoldson
It is pretty common to have customers want to do things to their AMX control systems based upon the time of day. Some new programmers may struggle a bit with it and I wanted to shed some light.
First off, drop this block into the DEFINE_VARIABLE section.
(*---------------------------------------------------------*) (*-- Clock Events --*) (*---------------------------------------------------------*) VOLATILE CHAR strTime[8] VOLATILE CHAR strOldTime[8] VOLATILE CHAR strMin[5] VOLATILE CHAR strOldMin[5]
Next, drop this block of code into mainline (DEFINE_PROGRAM) and add your custom code to it.
(*---------------------------------------------------------*)
(*--- At 6:30am, do stuff. --------------------------------*)
(*---------------------------------------------------------*)
strTime = TIME
IF(strOldTime <> strTime)
{
strOldTime = strTime
strMin = LEFT_STRING(strTime,5)
IF(strOldMin <> strMin)
{
strOldMin = strMin
IF(strMin = '06:30')
{
// Do stuff here!
}
}
}
What if you don’t want it to happen over the weekend? I’ve modified the block here.
(*---------------------------------------------------------*)
(*--- At 6:30am, do stuff. --------------------------------*)
(*---------------------------------------------------------*)
strTime = TIME
IF(strOldTime <> strTime)
{
strOldTime = strTime
strMin = LEFT_STRING(strTime,5)
IF(strOldMin <> strMin)
{
strOldMin = strMin
IF((strMin = '06:30') &&
(FIND_STRING(DAY,'SAT',1)=0) &&
(FIND_STRING(DAY,'SUN',1)=0))
{
// Do stuff here!
}
}
}
A lot of people are afraid of using mainline and prefer to use a timeline that would fire every 60 seconds and basically do the same thing as above. I’m not afraid of mainline and I’ve embraced it.
Notice that this code looks for a time in minutes (HH:MM) and not down to seconds (HH:MM:SS). Mainline will run 30-40 times per second, so we could watch for a change by HH:MM:SS. However, when I’m testing code, it is easier to change the time of day to 06:30 and let it run than it is to set the time to 06:29:59 and wait for the clock to count.
Also, notice the trick of checking the time against the previous value. You need to do this because you only want the “stuff” to execute once. Without this check, it would execute every pass through mainline during that 1 minute.
You could get fancy with this and make the time a variable that is editable from the touch panel. You could also create an editable schedule against any day or days of the week. Hmm, sounds like a good idea, see __rcSCHEDULER__.axi.
Comments
Comments are turned off for this article.
