Alarm Activitation According Day And Time


Recommended Posts



I am trying to make a user input to activate alarm according to weekday and time of day.

For example make alarm active (enable) from 18:00 on friday evening to 08:00 on monday morning.

similar as "Active Times" in DAQConnect.




here is how I started:


while (1)
   if ((systime() > 18h) && (systime() <= (08h)) & (v.ON_Button_Alarm[0] == 1))
Alarm.MyAlarm.Enabled = True
        Alarm.MyAlarm.Enabled = False


Thanks for any help







Link to comment
Share on other sites

Its probably easier to simply put the criterea in the alarm itself.  I personally would create a function that returns 0 or 1 depending on whether the alarm should be active, then you could use the same criterea for a group of alarms.  So if the alarm expression was just:


myChannel[0] > 50


you would do something like:


(myChannel[0] > 50) && alarmsActive()


where alarmsActive() is a function like:


function alarmsActive()

   return(v.On_Button_alarm[0] && (systime() % 86400 > 3600*8) && (systime() % 86400 < 3600 * 18)))


I like using % 86400 to determine time of day rather than hms notation.  Note that this just disables the alarm if v.On_button_alarm is 0, and the current time of day is between 08:00 and 18:00.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.