Accessing Real Time Clock from PL/i Program
This article applies to both ValuPoint controllers and i.CanDoIt (AddMe) web servers. PL/i programs in Modbus devices have access to reading the real time clock/calendar if the hardware has a clock/calendar. There are special "registers" that may be read as integer (use geti function). These register numbers are as follows:
7001 = year (e.g. 2016)
7002 = month (1-12)
7003 = day of month (1-31)
7004 = hour (0-23)
7005 = minute (0-59)
7006 = seconds (0-59)
7007 = day of week (1=Monday, 2=Tuesday ... 7=Sunday)
If you need to do something in your program on a daily basis at midnight, the easiest way to do so is periodically check to see if day of month is the same as the last time you checked it. If it changes, you can reasonably assume it is midnight. Use some care in addressing how you initialize your day of month comparison variable so that you do not repeat the midnight action just because the program started up.
If you need to do something at a specific time or at some periodic rate (e.g. hourly), use additional tests applied to hour, minute, etc., as needed.
If you need to look at multiple registers in the clock for the same calculation and do not want time to roll over while doing so, then read the clock via the alternate "locked" registers:
7011 = year (e.g. 2016)
7012 = month (1-12)
7013 = day of month (1-31)
7014 = hour (0-23)
7015 = minute (0-59)
7016 = seconds (0-59)
7017 = day of week (1=Monday, 2=Tuesday ... 7=Sunday)
The meaning of "locked" is that registers 7012 through 7017 are copied from the clock when 7011 is read. The values of the remaining locked registers will not change again until 7011 is read again.
The server devices have a web page that lets you set the clock. BACnet protocol has a command for setting time/date and that is how you would set the clock for the MS/TP version of the device. To set the clock in the Modbus RTU version of the device, you would need to write to the register numbers using an external Modbus master.
Writing the clock from Modbus requires writing to the "locked" registers 7011 through 7017, except that when writing, there is one more lock register. After you have written valid numbers to 7011-7017, write any value to register 7018 to trigger the transfer of the register values to the actual clock hardware.