FB_BACnet_TimeSync

FB_BACnet_TimeSync 1:

Application

The function block is called cyclically and outputs the current local time and the current UTC time. When an edge is applied to the input bExecute, the function block sends the time to the BACnet stack and the BACnet network as a broadcast message (time master) - provided the input bBroadcast is set; otherwise, only the local BACnet stack is synchronized.

The function includes the function block FB_LocalSystemTime for reading the local time.

FB_BACnet_TimeSync 2:

This function block can be used with BACnet stack Revision 6. However, under Revision 6 a broadcast is always sent (input bBroadcast is disabled under Revision 6).

A time synchronization overview is shown below:

FB_BACnet_TimeSync 3:
Figure 1: Example for time synchronization sequence in the BACnet network:
  1. An external time source (e.g. NTP) synchronizes the operating system time of the time master system (NTP → operating system time)
  2. If bExecute = TRUE, the function block FB_BACnet_TimeSync of the time master system synchronizes the BACnet stack with the current operating system time (operating system time → BACnet time)
  3. If the input bBroadcast is set at the function block, a BACnet broadcast time synchronization message is sent to the network
  4. BACnet devices in network adjust the time accordingly (BACnet time → operating system time)

Time synchronization typically takes place at intervals of several hours or daily. Times between 23:00 and 03:00 should be avoided, in order to avoid potential overlap with automatic summer/winter time changeover of the devices to be synchronized.

Application information:

A distinction is made between two modes for time synchronization:

  1. Each BACnet device is connected to an external time source (e.g. NTP). FB_BACnet_TimeSync must be executed on each BACnet controller. bBroadcast always has the value FALSE and bExecute is triggered at regular intervals.
  2. A device is connected to an external time source (e.g. NTP). Then FB_BACnet_TimeSync must be executed on this device with bBroadcast = TRUE and bExecute must be triggered regularly.
    All other BACnet devices execute FB_BACnet_TimeSync with bBroadcast = FALSE and bExecute = FALSE, are synchronized via BACnet and automatically adjust their local operating system time.

VAR_INPUT

bExecute   : BOOL;
bBroadcast : BOOL:=TRUE;
tTimeout   : TIME:=BACnet_ADSTimeOut;

 

bExecute: The synchronization starts with a rising edge.

bBroadcast: TRUE → additionally sends a broadcast time synchronization to the BACnet network; FALSE → only local synchronization (Revision 12 and higher)

tTimeout: Optional input, monitoring time for ADS access (default: see BACnet_ADSTimeOut).

 

VAR_OUPUT

bReady       : BOOL;
bBusy        : BOOL;
bError       : BOOL;
nErrID       : UDINT;
tsSystemTime : TIMESTRUCT;
dtSystemTime : ST_BACnet_DateTime;
tzID         : E_TimeZoneID;
tzInfo       : ST_TimeZoneInformation;
tsUTC        : TIMESTRUCT;

 

bReady: Time output (tsSystemTime, dtSystemTime, tzID, tzInfo and tsUTC) is valid

bBusy: Block is busy (time synchronization is active)

bError: Error during processing.

nErrID: ADS error code.

tsSystemTime: Local operating system time (Windows time) as typical PLC data structure

dtSystemTime: Local operating system time (Windows time) as typical BACnet data structure

tzID: ID of the current time zone

tzInfo : Information regarding the current time zone

tsUTC: Operating system time as UTC timestamp (GMT or coordinated world time) as typical PLC data structure

 

VAR_IN_OUT

Device : FB_BACnet_Device;

 

Device: Specification of the instance of the local corresponding BACnet server block.

Example

FB_BACnet_TimeSync 4:
Fig. 2: Example for cyclic synchronization of the local time (no broadcast).

bExecute is set if 03:00 is exceeded and remains active until the time reaches 00:00 → daily synchronization.