FB_BA_GetTime

FB_BA_GetTime 1:

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. Within the function block, an instance of the function blocks NT_GetTime, FB_GetTimeZoneInformation and RTC_EX2 is called. The time is output at the outputs stSysTi for the read system time and stUtc 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 [s]; 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_sec indicates the seconds remaining to the next read cycle. The time structures that are output, stSysTi and stUtc, 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:

Notes regarding 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 sErrDescr. The countdown output udiRemTiUpd_sec is not restarted until the wait cycle starts.

VAR_INPUT

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

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

sNetId: This parameter can be used to specify the AmsNetID (see T_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_sec: Time specification [s] with which the RTC clock is regularly synchronized 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 udiUpdRtc_sec, the RTC clock can be synchronized via a positive edge at this input.

VAR_OUTPUT

bRdySysTi         : BOOL;
bRdyTiZoInfo      : BOOL;
bRdyRTC           : BOOL;
udiRemTiUpd_sec   : UDINT;
stSysTi           : TIMESTRUCT;
stUTC             : TIMESTRUCT;
dtSysTi           : DT;
dtUTC             : DT;
udiCurrentTime_ms : UDINT
eTiZId            : E_TimeZoneID;
bErr              : BOOL;
sErrDescr         : T_MAXSTRING;

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_sec: Countdown to next synchronization/update of the time information.

stSysTi: System time of the read target system (see TIMESTRUCT). 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 world time (see TIMESTRUCT). 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: As stSysTi / stUTC, but in DATE-AND-TIME format: year-month-day-hours-minutes-seconds. Note:

FB_BA_GetTime 5:

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.

udiCurrentTime_ms: Current time of day in ms.

eTiZId: Enumerator for summer/winter time information (see E_TimeZoneID).

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

sErrDescr: Contains the error description.

Error description

01: Warning: ADS error when reading the time (FB NT_GetTime). The ADS error number is stated.

02: Warning: ADS error when reading the time zone information (FB_GetTimeZoneInformation). The ADS error number is stated.

Requirements

Development environment

Required PLC library

TwinCAT from v3.1.4024.7

Tc3_BA from v1.1.6.0