Con il rilascio della versione 5.20.x.xx di LogicLab è stata implementata la gestione degli operatori di Data e Ora. Quindi l’uso di alcuni oggetti embedded della libreria eLLabXUnified12Lib è deprecato. Per permettere comunque la compilazione dei progetti esistenti viene rilasciata la libreria eLLabDTimeAdjLib che andrà inclusa nel proprio progetto.
SysGetSysTime, get system time
La funzione ritorna il tempo di sistema espresso in μS. E’ possibile definire con il valore di Cmd se si vuole avere il tempo di sistema attuale (Cmd:=TRUE) oppure quello memorizzato con la precedente esecuzione della funzione (Cmd:=FALSE). Il valore di conteggio parte da 0 e dopo 4294 Secondi si resetta. Si consiglia di utilizzare la funzione SysTimeGetUs.
LogicLab (Sfr109, ST_SysGetSysTime)
PROGRAM ST_SysGetSysTime
VAR
TimeBf : UDINT; (* Time buffer (uS) *)
END_VAR
// *****************************************************************************
// PROGRAM "ST_SysGetSysTime"
// *****************************************************************************
// An example how to replace the older "SysGetSysTime" function.
// -----------------------------------------------------------------------------
// -------------------------------------------------------------------------
// USE OF "SysGetSysTime" FUNCTION
// -------------------------------------------------------------------------
// The function returns a time expressed on uS.
TimeBf:=SysGetSysTime(TRUE); //Time buffer (uS)
// -------------------------------------------------------------------------
// USE OF "SysTimeGetUs" FUNCTION
// -------------------------------------------------------------------------
// The function returns a time expressed on uS.
TimeBf:=SysTimeGetUs(); //Time buffer (uS)
// [End of file]
SysGetUTCDateTime, get the system Date/Time on UTC
La funzione ritorna la Data/Ora di sistema in UTC, il valore è espresso in Epoch Time. Si consiglia di utilizzare la funzione SysDateGetS.
LogicLab (Sfr109, ST_SysGetUTCDateTime)
PROGRAM ST_SysGetUTCDateTime
VAR
Read : BOOL; (* Read command *)
UTCTime : UDINT; (* UTC time (Epoch) *)
END_VAR
// *****************************************************************************
// PROGRAM "ST_SysGetUTCDateTime"
// *****************************************************************************
// An example how to replace the older "SysGetUTCDateTime" function.
// -----------------------------------------------------------------------------
// -------------------------------------------------------------------------
// USE OF "SysGetUTCDateTime" FUNCTION
// -------------------------------------------------------------------------
// On Read command, the RTC value has been read.
IF (Read) THEN
UTCTime:=SysGetUTCDateTime(TRUE); //UTC time
END_IF;
// -------------------------------------------------------------------------
// USE OF "SysDateGetS" FUNCTION
// -------------------------------------------------------------------------
// On Read command, the RTC value has been read.
IF (Read) THEN
Read:=FALSE; //Read command
UTCTime:=SysDateGetS(); //UTC time
END_IF;
// [End of file]
SysSetUTCDateTime, set the system Date/Time on UTC
La funzione imposta la Data/Ora di sistema in UTC, il valore è espresso in Epoch Time. Si consiglia di utilizzare la funzione SysDateSetS.
LogicLab (Sfr109, ST_SysSetUTCDateTime)
PROGRAM ST_SysSetUTCDateTime
VAR
SSts : BOOL; (* Set status *)
Update : BOOL; (* Update command *)
UTCTime : UDINT := 1675245796; (* UTC time (Epoch) *)
END_VAR
// *****************************************************************************
// PROGRAM "ST_SysSetUTCDateTime"
// *****************************************************************************
// An example how to replace the older "SysSetUTCDateTime" function.
// -----------------------------------------------------------------------------
// -------------------------------------------------------------------------
// USE OF "SysSetUTCDateTime" FUNCTION
// -------------------------------------------------------------------------
// On Update command, the RTC value has been updated.
IF (Update) THEN
SSts:=SysSetUTCDateTime(UTCTime);
END_IF;
// -------------------------------------------------------------------------
// USE OF "SysDateSetS" FUNCTION
// -------------------------------------------------------------------------
// On Update command, the RTC value has been updated.
IF (Update) THEN
Update:=FALSE; //Update command
SSts:=SysDateSetS(UTCTime);
END_IF;
// [End of file]
SysTimeZoneAdj, adjust date and time
La funzione permette di calcolare il valore di Data/Ora locale partendo dal valore UTC utilizzando il valore di TimeZone e DaylightZone definiti. Si consiglia di utilizzare la funzione SysDateLocalize.
LogicLab (Sfr109, ST_SysTimeZoneAdj
PROGRAM ST_SysTimeZoneAdj
VAR
DTimeLocal : UDINT; (* Date/Time local (Epoch) *)
END_VAR
// *****************************************************************************
// PROGRAM "ST_SysTimeZoneAdj"
// *****************************************************************************
// An example how to replace the older "SysTimeZoneAdj" function.
// -----------------------------------------------------------------------------
// -------------------------------------------------------------------------
// USE OF "SysTimeZoneAdj" FUNCTION
// -------------------------------------------------------------------------
DTimeLocal:=SysTimeZoneAdj(SysGetUTCDateTime(TRUE), +1, DAYLIGHT_ZONE#DLZ_EUROPE); //Local Date/Time
// -------------------------------------------------------------------------
// USE OF "SysDateLocalize" FUNCTION
// -------------------------------------------------------------------------
DTimeLocal:=SysDateLocalize(SysGetUTCDateTime(TRUE), +1, DAYLIGHT_ZONE#DLZ_EUROPE); //Local Date/Time
// [End of file]
SysDateToETime, date to epoch time conversion
Questo blocco funzione esegue la conversione dei valori di data-ora in un valore epoch time. Occorre fornire al FB la data e l’ora ed in uscita dal blocco funzione avremo un valore in epoch time. Si consiglia di utilizzare la funzione LogicLab CONCAT_DT.
LogicLab (Sfr109, ST_SysDateToETime)
PROGRAM ST_SysDateToETime
VAR
Year : INT := 2022; (* Year value *)
Month : INT := 9; (* Month value *)
Day : INT := 24; (* Day value *)
Hour : INT := 14; (* Hour value *)
Minute : INT := 10; (* Minute value *)
Second : INT := 30; (* Second value *)
EpochTime : UDINT; (* Epoch time *)
DToETime : SysDateToETime; (* Date to Epoch time conversion *)
END_VAR
// *****************************************************************************
// PROGRAM "ST_SysDateToETime"
// *****************************************************************************
// An example how to replace the older "SysDateToETime" FB.
// -----------------------------------------------------------------------------
// -------------------------------------------------------------------------
// USE OF "SysDateToETime" FB
// -------------------------------------------------------------------------
DToETime.Year:=TO_UINT(Year); //Year value
DToETime.Month:=TO_USINT(Month); //Month value
DToETime.Day:=TO_USINT(Day); //Day value
DToETime.Hour:=TO_USINT(Hour); //Hour value
DToETime.Minute:=TO_USINT(Minute); //Minute value
DToETime.Second:=TO_USINT(Second); //Second value
DToETime(); //Date/Time to epoch conversion
EpochTime:=DToETime.EpochTime; //Epoch time
// -------------------------------------------------------------------------
// USE OF "CONCAT_DT" FUNCTION
// -------------------------------------------------------------------------
EpochTime:=TO_UDINT(CONCAT_DT(Year, Month, Day, Hour, Minute, Second));
// [End of file]
SysETimeToDate, epoch time to date conversion
Questo blocco funzione esegue la conversione della data espressa in epoch time nei valori di Data/Ora. Fornendo al FB la data espressa nel formato epoch time avremo in uscita i valori di data espressi nel formato Giorno/Mese/Anno ed Ora:Minuti:Secondi. Si consiglia di utilizzare la funzione LogicLab SPLIT_DT.
LogicLab (Sfr109, ST_SysETimeToDate)
PROGRAM ST_SysETimeToDate
VAR
Year : INT; (* Year *)
Month : INT; (* Month *)
Day : INT; (* Day *)
WeekDay : INT; (* WeekDay *)
Hour : INT; (* Hour *)
Minute : INT; (* Minute *)
Second : INT; (* Second *)
EpochTime : UDINT := 1270822815; (* Epoch time *)
EToDate : SysETimeToDate; (* Epoch time to date conversion *)
END_VAR
// *****************************************************************************
// PROGRAM "ST_SysETimeToDate"
// *****************************************************************************
// An example how to replace the older "SysETimeToDate" FB.
// -----------------------------------------------------------------------------
// -------------------------------------------------------------------------
// USE OF "SysETimeToDate" FB
// -------------------------------------------------------------------------
EToDate.EpochTime:=EpochTime; //Epoch time (Use example data)
EToDate(); //Epoch time to date conversion
Year:=TO_INT(EToDate.Year); //Year
Month:=TO_INT(EToDate.Month); //Month
Day:=TO_INT(EToDate.Day); //Day
WeekDay:=TO_INT(EToDate.WeekDay); //WeekDay
Hour:=TO_INT(EToDate.Hour); //Hour
Minute:=TO_INT(EToDate.Minute); //Minute
Second:=TO_INT(EToDate.Second); //Second
// -------------------------------------------------------------------------
// USE OF "SPLIT_DT" FUNCTION
// -------------------------------------------------------------------------
eTO_JUNK(SPLIT_DT(TO_DATE_AND_TIME(EpochTime), ADR(Year), ADR(Month), ADR(Day), ADR(Hour), ADR(Minute), ADR(Second)));
// [End of file]