FB_HVACGetSystemTime
Application
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 bEnable, 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 and RTC_EX2 is called in the function block from the Utilities library.
Note Due to system characteristics the RTC time deviates from a reference time. The difference depends on the PLC's cycle time, the value of the basic system ticks, and on the hardware being used. The RTC is therefore synchronized internally in the function block with the NT system time depending on the input variables sNETID and tGetSystemTime. The local NT system time can, in turn, be synchronized with a reference time with the aid of the SNTP protocol. More information can be found in the Beckhoff Information System under:Beckhoff Information System > Embedded PC > Operating systems > CE > SNTP: Simple Network Time Protocol |
VAR_INPUT
bEnable : BOOL;
sNETID : T_AmsNetId;
tGetSystemTime: TIME;
bGetSystemTime: BOOL;
bEnable: enable of the function block. If bEnable = TRUE, then the RTC clock is initialized 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 determined. If it is to be run on the local computer, an empty string can be entered.
tGetSystemTime: time specification with which the RTC clock is regularly synchronized with the NT system time. This time specification must be greater than or equal to 5 seconds, otherwise the RTC clock will not be synchronized. Parallel to the time specification tGetSystemTime, the RTC clock can be synchronized via the input variable bGetSystemTime.
bGetSystemTime: the RTC clock is synchronized with the NT system time with a rising edge at this input. This takes place in parallel with the time specification tGetSystemTime.
VAR_OUTPUT
bReadyGetSystemTime : BOOL;
bReadyRTC : BOOL;
stSystemTime : TIMESTRUCT;
dtSystemTime : DT;
uiYear : UINT;
uiMonth : UINT;
uiDay : UINT;
uiDayOfWeek : UINT;
uiHour : UINT;
uiMinute : UINT;
uiSecond : UINT;
uiMilliseconds : UINT;
bErrorGetSystemTime : BOOL;
udiErrorIdGetSystemTime: UDINT;
bReadyGetSystemTime: the function block was successfully initialized or synchronized with the NT system time.
bReadyRTC: 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.
stSystemTime: structure with the current RTC time.
dtSystemTime: date and time of day of the RTC time.
uiYear: the year: 1970 ~ 2106;
uiMonth: the month: 1 ~ 12 (January = 1, February = 2, etc.);
uiDay: the day of the month: 1 ~ 31;
uiDayOfWeek: the day of the week: 0 ~ 6 (Sunday = 0, Monday = 1 etc. );
uiHour: hour: 0 ~ 23;
uiMinute: minute: 0 ~ 59;
uiSecond: second: 0 ~ 59;
uiMilliseconds: millisecond: 0 ~ 999;
bErrorGetSystemTime: this output is set if an ADS error occurs when transmitting the command. The output indicates with a TRUE that an error has occurred during initialization or synchronization with the NT system time. The function block continues to attempt to initialize or synchronize the RTC clock until the error has been rectified. The RTC clock starts with an incorrect date and time specification and must therefore be synchronized with the NT system time.
udiErrorIdGetSystemTime: returns the ADS error number when the bErrorGetSystemTime output is set.