Efried
Active Member
HelloLarrylLix said:Here is one basic idea how you could accomplish this. I created a time slice main routine based on a 6 second repeat / heartbeat. Remember MOD(ulus) is your friend.
SEC0:
MOD CS UROM1 RAM2 # Div C)urrent S)econd by UROM1=6, remainder into RAM2
TSTNE RAM2 0 # check it for 0 remainder = timeslice 0
GOTO SEC0_DUN # not? then forget it
BNZ RAM1B1 SEC1 # Already done this timeslice? Then do next
CALLSUB CLOCK1 #
SET RAM1B1 1 # mark it as complete this timeslice
GOTO MAINLOOP # back to the PLC beginning
SEC0_DUN:
SET RAM1B1 0 # other timeslice? flag ready for next loop
SEC1:
TSTNE RAM2 1 # timeslice at 1 second mark
more PLC jobs
Here is my clock subroutine. I pack all the date and time together and ship it to ISY every 6 seconds and use it for a heartbeat and also to tell ISY what time it is, useable as individual elements.
CLOCK1:
TSTLT CYEAR 2014 # if clock isn't valid yet don't send it
GOTO CLOCK_X
MUL CMONTH 100 RAM2 # date and time format will be on integer MMDDhhmmss
ADD RAM2 CDAY RAM2
MUL RAM2 100 RAM2 #shift it left two decimal digits and keep adding LS values
ADD RAM2 CH RAM2
MUL RAM2 100 RAM2
ADD RAM2 CM RAM2
MUL RAM2 100 RAM2
ADD RAM2 CS RAM2
SETLED 1
SET VAR1 RAM2 #RAM2 is my global scratchpad variable.
WEBSET URL1 VAR1 #VAR1 is the last thing sent via WEBSET URL1
SETLED 0
CLOCK_X:
RET
When the WC8 reboots I do a WEBSET URL1 -1 to flag my ISY that the WC8 rebooted. Just for monitoring purposes to establish reliability for now.
If the heartbeat is missing too long an Insteon ON/Off module power cycles the WC8 and the bridged router sending the data to another building where my ISY resides.
If
$CAI1_DateTime <= -1
Then
code to record reboot in ISY
Else
Wait 9 seconds
code to record the first heartbeat period is missed
Wait 6 seconds
code to record the second heartbeat period is missed
Wait 6 seconds
code to record the third heartbeat period is missed
Wait 6 seconds
code to record the fourth heartbeat period is missed
Wait 60 seconds
Set 'Workshop / Shop Webcontrol Board' Off
Wait 15 seconds
Set 'Workshop / Shop Webcontrol Board' On
I was checking for mod (n*seconds) assuming that in my code it will be not returning to the line in the same second (or do wait 1)
May be a real pretty code would need also a check if the webset channel is clear, e.g. not congested...
regards