FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
03-06-2023 05:10 PM
Hello,
I'd like to read out system time in PLC.
Later he time should be split in hour, minute, second. There are several different libraries but I didn't get it to work.
Any hint?
With WebVisu it's easy with %t[HH:mm.ss] so the system time has to be available with standard library but which to use?
Thanks in advance
Solved! Go to Solution.
03-07-2023 01:52 AM
Hello Alink,
I happened to have done it in my recent project.
I used SysTimeRtc (System) library.
Declaration:
Date_and_time_in_seconds : UDINT;
Local_date_time_seconds : UDINT;
Date_and_Time_result : UDINT;
Local_date_time_from_secs : SYSTIMEDATE;
Date_and_time_format : DATE_AND_TIME;
Date_and_time_string : STRING;
Implementation:
// Get time in seconds since 1970 :
Date_and_time_in_seconds := SysTimeRtcGet(Date_and_Time_result);
IF Date_and_Time_result <> 0 THEN
RETURN;
END_IF
// Convert UTC seconds to local time seconds, regarding Timezone and Summer time :
Date_and_Time_result := SysTimeRtcConvertUtcToLocal(Date_and_time_in_seconds, Local_date_time_seconds);
IF Date_and_Time_result <> 0 THEN
RETURN;
END_IF
// Convert the UTC seconds to a DATE_AND_TIME variable dt#yyyy-mm-dd-hh:mm:ss :
Date_and_time_format := UDINT_TO_DT(Local_date_time_seconds);
// Convert DATE_AND_TIME to a String :
Date_and_time_string := DT_TO_STRING(Date_and_time_format);
03-07-2023 02:06 PM
Thanks a lot @Open
This works great.
Now I can build my own analog clock and assign a timestamp to recorded data.
01-29-2024 01:07 PM
Hi, @Open ,
would you pls give me a hint where SysTimeRtcConvertUtcToLocal function takes timezone and summer time from?
I only found IL_LocalTime fb where you can set different timezones and switchting time to summer/winter time but SysTimeRtc function somehow works without those information.
Thanks a lot.
01-30-2024 09:37 AM
You have to define the timezone settings, like offset to UTC and start & end of daylight saving time in a structure. See https://help.codesys.com/webapp/nuLcg6pcETbhW5dXsYWvvHsQUp0%2FTimeZone;product=Util;version=3.5.17.0