FB_BA_GetTime

Reading the system time

FB_BA_GetTime 1:

Functional description

With this function block an internal clock (Real Time Clock RTC) can be implemented in the TwinCAT PLC. When the function block is enabled via bEn, the RTC clock is initialized with the current NT system time. One system cycle of the CPU is used to calculate the current RTC time. The function block must be called once per PLC cycle in order for the current time to be calculated. Internally an instance of the function blocks NT_GetTime, FB_GetTimeZoneInformation and RTC_EX2 is called in the function block. The time is output at the outputs stSysTi for the read system time and stUtcTi for the Coordinated Universal Time (UTC). This is determined internally from the system time and the time zone. If the system time and/or the time zone was entered incorrectly, the UTC time will also be wrong.

The system time is read cyclically via the timer to be set (udiUpdRTC [sec]); it is used to synchronize the internal RTC clock. The time information (time zone, time shift relative to UTC, summer/winter time) is read in the same cycle. The output udiRemTiUpd indicates the seconds remaining to the next read cycle. The time structures that are output, stSysTi and stUtcTi, can be resolved with the aid of the function block FB_BA_ExtTiSt into the components day, month, hour, minute etc.

FB_BA_GetTime 2:

Read / wait cycle

During the read cycle, the outputs bRdySysTi and bRdyTiZoInfo change to FALSE, and the enumerator eTiZId shows 0 = eTimeZoneID_Unknown. If the read operation was successful, the outputs switch back to TRUE or show the respective information for summer or winter time, if available. If the read operation was unsuccessful - internally the system waits for a response for 5 seconds - the outputs remain at FALSE or 0, and another wait cycle is started before the next read cycle. Although the internal RTC clock is not synchronized in the event of an error and may still show the right time, the time information may be wrong, and therefore also the UTC time. Errors during the read cycle will, any case, show up in bErr and udiErrId / udiErrArg. The countdown output is not restarted until the wait cycle starts.

Inputs/outputs

VAR_INPUT

bEn       : BOOL;
sNetId    : T_AmsNetId;
udiUpdRtc : UDINT;
bUpdRtc   : BOOL;

bEn: Enables the function block. If bEn = TRUE, then the RTC clock is initialised with the NT system time.

sNetId : This parameter can be used to specify the AmsNetID of the TwinCAT computer, whose NT system time is to be read as timebase. If it is to be run on the local computer, an empty string can be entered.

udiUpdRtc: Time specification [s] with which the RTC clock is regularly synchronised with the NT system time. Internally this value is limited to a minimum of 5 seconds, in order to ensure correct processing of the internal function blocks.

bUpdRtc: In parallel with the time tGetSystemTime, the RTC clock can be synchronised via a positive edge at this input.

VAR_OUTPUT

bRdySysTi    : BOOL;
bRdyTiZoInfo : BOOL;
bRdyRTC      : BOOL;
udiRemTiUpd  : UDINT;
stSysTi      : TIMESTRUCT;
stUTC        : TIMESTRUCT;
dtSysTi      : DT;
dtUTC        : DT;
eTiZId       : E_TimeZoneID;
bErr         : BOOL;
udiErrId     : UDINT;
udiErrArg    : UDINT;

bRdySysTi: the system time was read successfully from the target system.

bRdyTiZoInfo: the additional time information (time zone, time shift relative to UTC and summer/winter time) was read successfully.

bRdyRTC: this output is set if the function block has been initialized at least once. If this output is set, then the values for date, time and milliseconds at the outputs are valid.

udiRemTiUpd: countdown to next synchronization/update of the time information.

stSysTi: system time of the read target system. The time structure can be resolved with the aid of the function block FB_BA_ExtTiSt into its components: day, month, hour, minute etc.

FB_BA_GetTime 3:

If the function block is not enabled (bEn = FALSE), the output stSysTi and its subelements (day, month, etc.) show 0.

stUTC: Coordinated Universal Time. This is determined internally from the system time and the time information read from the target system. The time structure can be resolved with the aid of the function block FB_BA_ExtTiSt into its components: day, month, hour, minute etc.

FB_BA_GetTime 4:

If the function block is not enabled (bEn=FALSE), the output stUTC and its subelements (day month, etc.) show 0.

dtSysTi / dtUTC: same as stSysTi / stUTC, but in DATE-AND-TIME format: year-month-day-hour-minute-seconds. Note: if the function block is not enabled (bEn= FALSE), the outputs dtSysTi and dtUTC show DT#1970-01-01-00:00, since this is the lower limit, which corresponds to the zeros in the structure representation of stSysTi / stUTC.

eTiZId: enumerator for summer/winter time information

bErr: this output is switched to TRUE if the parameters entered are erroneous.

udiErrId / udiErrArg: contains the error number and the error argument. See error codes.

Requirements

Development environment

Target system

required library

required supplement

TwinCAT 2.11 R3/x64

PC/CX

TcBA library from V1.0.0

TS8040 | TwinCAT Building Automation from V1.0.0