Type: |
Function block |
Available as of: |
V1.0.7.0 |
The FB_SntpClient function block provides SNTP client functions.
The FB_SntpClient function block is the user interface for SNTP communications.
The function block needs to be enabled and ready to perform a request. When starting the execution of a request, the information from the inputs is used to build an SNTP telegram containing the time request. The telegram is sent to a single server using UDP.
The function block waits for a response from the server, processes it and presents the received information at the output q_stTimeResponse. As long as the function block is executing a request, the output q_xBusy is set to TRUE and q_etResult presents the state of operation. The output q_xDone indicates a successful execution and q_xError shows if the function block detects an error during execution with q_etResult and q_sResultMsg presenting further information on the nature or cause of the detected error. If an error is detected, the function block needs to be reset by disabling and re-enabling it.
Depending on the input i_xSyncRtc, the calculated values are used to set the RTC of the controller to the value that has been received from the server (including the offset defined with the input i_diTimeZone). A maximum accuracy of 1 s can be reached for UTC synchronization.
NOTE: Daylight saving time is not taken into account by the function block. You have to take appropriate measures in your application. Also refer to the RTC Control / Timezone / Daylight Saving Time Example Guide document.
The input i_uiMaxRtcOffset can be used as a plausibility check to verify the results from the server before the RTC of the controller is set.
NOTE: Setting the RTC of the controller generates entries into the controller log file. Therefore, for automatic adjustments, do not use this function more than once a day.
Input |
Data type |
Description |
---|---|---|
i_xEnable |
BOOL |
Activation and initialization of the function block. |
i_xExecute |
BOOL |
The request specified with the input iq_stTimeRequest is executed upon rising edge of this input. |
i_xSyncRtc |
BOOL |
If this input is set to TRUE, the RTC of the controller is set automatically after a response has been received from the (S)NTP time server. Default value: FALSE NOTE: Setting the RTC of the controller generates entries into the controller log file. Therefore, for automatic adjustments, do not use this function more than once a day. |
i_diTimeZone |
DINT |
Offset that is added to the time stamp received from the (S)NTP time server in seconds. Default value: 0 Value range: -86400...+86400 (24 h x 60 min x 60 s) |
i_uiMaxRtcOffset |
UINT |
Maximum difference allowed between the present and the new RTC value if i_xSyncRtc is TRUE. Can be used as a plausibility check to help prevent an unintended set of the RTC. For example, if the RTC is synchronized once with a time server, any following synchronizations (offsets) shall be in the range of ±30 s. Default value: 0 (function is inactive) Maximum value: 7200 s (2 hours) |
i_stTimeRequest |
Structure containing required user input data regarding the (S)NTP time server. |
Output |
Data type |
Description |
---|---|---|
q_xActive |
BOOL |
If the function block is active, this output is set to TRUE. |
q_xReady |
BOOL |
Indicates TRUE if the function block is ready to receive user input. |
q_xBusy |
BOOL |
If this output is set to TRUE, the function block is processing. |
q_xDone |
BOOL |
If this output is set to TRUE, the function block has successfully completed the requested command. Additional data can be collected from iq_stTimeRequest. |
q_stTimeResponse |
Structure containing the synchronized time stamp (including the offset i_diTimeZone), the clock offset between local RTC of the controller and the (S)NTP time server, and the round-trip delay. |
|
q_Error |
BOOL |
If this output is set to TRUE, an error has been detected. For details, refer to q_etResult and q_etResultMsg. |
q_etResult |
Provides diagnostic and status information as a numeric value. |
|
q_sResultMsg |
STRING[255] |
Provides additional diagnostic and status information as a text message. |