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