Handle correctly the RTC in PFC200, UTC time and cycle time

Hi there,

I am new here, hopefully this post will have some meaning for others too.
I am trying to work with WAGO RTC time.
I am using the library SysTime.SysTimeRtc 3.5.17
I would like to use it in two ways.
First, use it to measure the cycle time of the Function “LogStatusErrors”. My “first” try
was to use mS and it worked, but the result is 0
VAR: tsNowStart, tsNowEnd, tsRun : UDINT;
BODY Start: tsNowStart:= SysTimeRtc.SysTimeGetMs();
// Strange code with Arrays I want to test/log!!!
BODY End:
tsNowEnd := SysTimeRtc.SysTimeGetMs();
tsRun:= (tsNowEnd-tsNowStart);
GVL_IEM3150a.udiLastRunTime:=tsRun; //
Since I am getting 0 in GVL, and I see that the Function is working from time to time, I need to use nS or something else?
I am trying the Library Function FUNCTION SysTimeRtcHighResGet, but I get syntax errors with everything I tried.
And secondly, in the arrays I mentioned before, I want to store the UTC time in some logs. So I have to use pTimestamp.
Again, I tried “every” way with “every” variable declaration, but it never worked.
Anybody to throw some help?
Thank you in advance for your time!

George
(my first post was on Saturday night!)

Saturday was hot, and I came up with some answers,
2 ways to measure the cycle time of an FB:
VAR:

//---- Time count 1st way -------
tsNowStart, tsNowEnd, tsRun : ULINT;
//---- Time cound 2nd way ------
tsHighStart, tsHighEnd : LTIME;
runTime_ns: LINT;
BODY Begin
//---- Time count 1st way -------
WagoAppTime.SysTimeRtc.SysTimeGetUs(pUsTime:=tsNowStart);
//---- Time cound 2nd way ------
tsHighStart := FuGetLongSystemTime();

BODY Begin
//---- Time count 1st way -------
WagoAppTime.SysTimeRtc.SysTimeGetUs(pUsTime:=tsNowStart);
//---- Time cound 2nd way ------
tsHighStart := FuGetLongSystemTime();

// Strange code with Arrays I want to test/log!!!

/---- Time count 1st way -------
WagoAppTime.SysTimeRtc.SysTimeGetUs(pUsTime:=tsNowEnd);
GVL_IEM3150a.udiLastRunTime:=(tsNowEnd-tsNowStart);

//---- Time cound 2nd way ------
tsHighEnd := FuGetLongSystemTime();
GVL_IEM3150a.udiLastRunTimeNs := FuGetLTimeDifferenceNanoseconds(tsHighEnd,tsHighStart);

The values I get (before start shifting the array) are something like
10 for udiLastRunTime and
7450 for udiLastRunTimeNs
Any feedback?
thank you

as far as the UTC time store to the array I tried this:
VAR
timeStamp : LTIME;

BODY
IF error AND store THEN
GVL_IEM3150a.aErrorHistory[GVL_IEM3150a.udiErrorCount].timeStamp := WagoAppTime.FuGetLongTime();
END IF

GVL_IEM3150a.udiErrorCount is the pointer of the array.

the logic works but the time I see on the logs is something like
LTIME#20254d10h45m44s417ms
I checked the RTC of the PLC and it is correct,
Can somebody see my mistake? this code is written in a FUN that I call from a FB.
Thank you in advance,

FuGetLongTime 
Retrieves the global time (in UT, i.e. GMT+0000) since 1.1.1970 in LTIME format
he time format LTIME combines the representation of absolute time 
(in millisecond resolution) and large value range (584 years). 
It is uniformly applicable without having to worry about overflow or reference 
points.

The LTIME you have seem correct since it is the time difference between 1970/01/01 00:00:00.00 and now.
What format you want the timestamp to be ?
A Linux timestamp ?
A text one like “2025/06/16 9:18:46.874” ?

You have the function: FuConvertLStampToTimeComponents which transform the LTIME to a human readable datatype (UTC) or FuConvertLStampToLocalTimeComponents for the LOCAL time / date.

2 Likes

If you want to show timestamp in text log, try to use function “Format1()” from WagoAppString library

1 Like

Dear Damian,
thank you for the suggestion on Strings…
Nice!