Can anybody here tell me how to modify the time and date on my CPX-E? I used the code I found on CODESYS online help, but it doesn't work. What am I missing?
FUNCTION current_date_time : STRING
VAR
stUTC_Timestamp : SysTime; //utc time // ULINT#1528280694913
stLocal_TimeStamp : SysTime; //local time but is in general equal // ULINT#1528280694913
stdNow : SysTimeDate; //local time in an object to access each number (day, month...)
END_VAR
SysTimeRtcHighResGet(stUTC_Timestamp); // ULINT#1528273494913
SysTimeRtcConvertHighResToLocal(stUTC_Timestamp, stdNow); //convert UTC ULINT to Local SysTime
Hello,
Can anybody here tell me how to modify the time and date on my CPX-E? I used the code I found on CODESYS online help, but it doesn't work. What am I missing?
FUNCTION current_date_time : STRING
VAR
stUTC_Timestamp : SysTime; //utc time // ULINT#1528280694913
stLocal_TimeStamp : SysTime; //local time but is in general equal // ULINT#1528280694913
stdNow : SysTimeDate; //local time in an object to access each number (day, month...)
END_VAR
SysTimeRtcHighResGet(stUTC_Timestamp); // ULINT#1528273494913
SysTimeRtcConvertHighResToLocal(stUTC_Timestamp, stdNow); //convert UTC ULINT to Local SysTime
// stdNow.wYear = UINT#2018
// stdNow.wMonth = UINT#6
// stdNowy.wDay = UINT#6
// stdNow.wHour = UINT#10
// stdNow.wMinute = UINT#24
// stdNow.wSecond = UINT#54
// stdNow.wMilliseconds = UINT#913
// stdNow.wDayOfWeek = UINT#3
// stdNow.wYday = UINT#157
SysTimeRtcConvertDateToHighRes(stdNow, stLocal_TimeStamp); // ULINT#1528280694913
dtNow := TO_DT(stLocal_TimeStamp / 1000 ( ms )); // DT#2018-6-6-10:24:54
todNow := TO_TOD(stLocal_TimeStamp MOD TO_ULINT(T#1D)); // TOD#10:24:54.913
datNow := TO_DATE(dtNow); // D#2018-6-6
(convert to appropriate string)
current_date_time := concat('$N[', TO_STRING(dtNow));
current_date_time:= concat(current_date_time,'.');
current_date_time:= concat(current_date_time, TO_STRING(stdNow.wMilliseconds));
current_date_time:= concat(current_date_time,'] - ');
RETURN;