Hi Tim,
Just to be clear, here is the code in the BASIC IDE:
CYCLIC SECTION
END
GetDateTime:
yy% = GetIO “PLC_Year”
yy$ = STR$ yy%
mm% = GetIO “PLC_Month”
mm$ = STR$ mm%
dy% = GetIO “PLC_Day”
dy$ = STR$ dy%
hr% = GetIO “PLC_Hour”
hr$ = STR$ hr%
mn% = GetIO “PLC_Minute”
mn$ = STR$ mn%
ss% = GetIO “PLC_Second”
ss$ = STR$ ss%
DT$ = dy$ + “/” + mm$ + “/” + yy$ + " " + hr$ + “:” + mn$ + “:” + ss$
DT% = FCNV DT$, 40
SetIO “PLC_DateTime”, DT%
END
LogAllOnBoot:
Rem Get status of AB PLC. Value of 1 means connected
plcstatus% = GetIO “PLCStatus”
IF (plcstatus% = 1) THEN
numTags% = GETSYS PRG, “NBTAGS”
FOR i% = 1 TO numTags% STEP 1
Rem LOGIO i%
NEXT i%
Rem Disable timer after log occurs once on boot and PLC connected, historical log config will take care of logging after
TSET 1,0
ENDIF
END
EnableTimer:
plcstatus% = GetIO “PLCStatus”
IF (plcstatus% <> 1) THEN
TSET 1,5
ENDIF
END
INIT SECTION
Rem Set Timer to delay calling label to log all loggable tags after boot
TSET 1, 5
ONTIMER 1,“goto LogAllOnBoot”
Rem Set label to pack PLC date/time when seconds from PLC changes
ONCHANGE “PLC_Second”,“goto GetDateTime”
ONCHANGE “PLCStatus”,“goto EnableTimer”
END
I already have ONTIME and ONCHANGE code in the INIT, so is moving the code all I need to do, for example:
CYCLIC SECTION
END
INIT SECTION
Rem Set Timer to delay calling label to log all loggable tags after boot
TSET 1, 5
ONTIMER 1,“goto LogAllOnBoot”
Rem Set label to pack PLC date/time when seconds from PLC changes
ONCHANGE “PLC_Second”,“goto GetDateTime”
ONCHANGE “PLCStatus”,“goto EnableTimer”
END
GetDateTime:
yy% = GetIO “PLC_Year”
yy$ = STR$ yy%
mm% = GetIO “PLC_Month”
mm$ = STR$ mm%
dy% = GetIO “PLC_Day”
dy$ = STR$ dy%
hr% = GetIO “PLC_Hour”
hr$ = STR$ hr%
mn% = GetIO “PLC_Minute”
mn$ = STR$ mn%
ss% = GetIO “PLC_Second”
ss$ = STR$ ss%
DT$ = dy$ + “/” + mm$ + “/” + yy$ + " " + hr$ + “:” + mn$ + “:” + ss$
DT% = FCNV DT$, 40
SetIO “PLC_DateTime”, DT%
END
LogAllOnBoot:
Rem Get status of AB PLC. Value of 1 means connected
plcstatus% = GetIO “PLCStatus”
IF (plcstatus% = 1) THEN
numTags% = GETSYS PRG, “NBTAGS”
FOR i% = 1 TO numTags% STEP 1
Rem LOGIO i%
NEXT i%
Rem Disable timer after log occurs once on boot and PLC connected, historical log config will take care of logging after
TSET 1,0
ENDIF
END
EnableTimer:
plcstatus% = GetIO “PLCStatus”
IF (plcstatus% <> 1) THEN
TSET 1,5
ENDIF
END
Thanks,
Mike