Hi Mserrao,
The issue with your code is that the DELAY commands essentially halt all operation of the logger for a period of time, which means nothing else can occur during this time.
What I choose to do instead is run a schedule as a timer and have it control everything else. This is what I call a state machine.
Excuse me for re-writing your program, but it was a few minutes work to put into a format that should work well and have no delays. Given that there are no other state machine examples on the forum yet I thought I would use yours as an example.
The below code uses G schedule to control all of the timed events, including the relay, measurements and FTP transfers. The G schedule timer is re-started every hour by the A schedule. On the 12 hour events, an additional flag is set so the relay stays closed, keeping the modem awake and proceeding with the FTP transfer.
Give this a go and read the comments in the program (after the apostrophe's)
BEGIN"A"
LOGON
RA1H
DO{1CV=0;GG} 'reset timer and start the state machine
RB12H
DO{2CV=1} 'timer already started by A, so only need to enable the FTP flag (2CV=1)
RG1S HG 'state machine (1CV = time elapsed)
IF(1CV>0){1RELAY=1} 'turn on modem and sensors
IF(1CV==3){XI} 'run I schedule when counter gets to 3 seconds
IF(1CV==6)AND IF(2CV<1){1RELAY=0} 'dont turn off if 12H schedule running
IF(1CV>7)AND IF(2CV<1){HG} 'halt counter if no FTP required
IF(1CV==608){XJ} 'run J schedule when counter gets to 608 seconds
IF(1CV==908){1RELAY=0} 'turn off modem at 908 seconds
IF(1CV>909){2CV=0;HG} 'reset the FTP flag and halt the counter
1CV("TIMER",W)=1CV+1
RIX 'measurement schedule
1I(120)
1+I(120)
2I(120)
2+I(120)
RJX 'FTP schedule
DO{COPYD sched=I dest=ftp://xxx:yyy@IP_ADDRESS}
END
KadeM
Hi Mserrao,
The issue with your code is that the DELAY commands essentially halt all operation of the logger for a period of time, which means nothing else can occur during this time.
What I choose to do instead is run a schedule as a timer and have it control everything else. This is what I call a state machine.
Excuse me for re-writing your program, but it was a few minutes work to put into a format that should work well and have no delays. Given that there are no other state machine examples on the forum yet I thought I would use yours as an example.
The below code uses G schedule to control all of the timed events, including the relay, measurements and FTP transfers. The G schedule timer is re-started every hour by the A schedule. On the 12 hour events, an additional flag is set so the relay stays closed, keeping the modem awake and proceeding with the FTP transfer.
Give this a go and read the comments in the program (after the apostrophe's)
BEGIN"A"
LOGON
RA1H
DO{1CV=0;GG} 'reset timer and start the state machine
RB12H
DO{2CV=1} 'timer already started by A, so only need to enable the FTP flag (2CV=1)
RG1S HG 'state machine (1CV = time elapsed)
IF(1CV>0){1RELAY=1} 'turn on modem and sensors
IF(1CV==3){XI} 'run I schedule when counter gets to 3 seconds
IF(1CV==6)AND IF(2CV<1){1RELAY=0} 'dont turn off if 12H schedule running
IF(1CV>7)AND IF(2CV<1){HG} 'halt counter if no FTP required
IF(1CV==608){XJ} 'run J schedule when counter gets to 608 seconds
IF(1CV==908){1RELAY=0} 'turn off modem at 908 seconds
IF(1CV>909){2CV=0;HG} 'reset the FTP flag and halt the counter
1CV("TIMER",W)=1CV+1
RIX 'measurement schedule
1*I(120)
1+I(120)
2*I(120)
2+I(120)
RJX 'FTP schedule
DO{COPYD sched=I dest=ftp://xxx:yyy@IP_ADDRESS}
END
KadeM