FB_BA_ExternalSysTime

FB_BA_ExternalSysTime 1:

The template reads the NT system time of an external TwinCAT system at regular intervals.

If the readout was successful, then the external system time is written to the local NT system time of the TwinCAT system and the local BACnet system time of the TwinCAT system.

The two local system times are read out at regular intervals and mapped to local and global variables in the PLC.

Block diagram

FB_BA_ExternalSysTime 2:

Syntax

FUNCTION_BLOCK FB_BA_ExternalSysTime
VAR_INPUT CONSTANT PERSISTET
  sExternalAmsNetId                      : T_AmsNetId := '';
  {attribute 'parameterUnit':= 's'}
  GetExtSysTime_nTiAuto                  : UDINT := 600;
  {attribute 'parameterUnit':= 's'}
  GetLocalSysTime_nTiAuto                : UDINT := 60;
END_VAR
VAR_INPUT CONSTANT
  GetExtSysTime                          : FB_BA_GetTime;

  SetSysTimeLocal                        : FB_BA_SetTime;
  SetBACnetAdapterTime                   : FB_BACnet_SetAdapterTime;

  GetLocalSysTime                        : FB_BA_GetTime;
  GetBACnetAdapterTime                   : FB_BACnet_GetAdapterTime;
END_VAR
VAR
  GetExtSysTime_bSync                    : BOOL;
  GetExtSysTime_rtrigSync                : R_TRIG;

  GetBACnetAdapterTime_wYear             : WORD;
  GetBACnetAdapterTime_wMonth            : WORD;
  GetBACnetAdapterTime_wDayOfWeek        : WORD;
  GetBACnetAdapterTime_wDay              : WORD;
  GetBACnetAdapterTime_wHour             : WORD;
  GetBACnetAdapterTime_wMinute           : WORD;
  GetBACnetAdapterTime_wSecond           : WORD;
  GetBACnetAdapterTime_wMilliseconds     : WORD;
END_VAR

FB_BA_ExternalSysTime 3: Inputs CONSTANT PERSISTENT

Name

Type

Description

sExternalAmsNetId

T_AmsNetId

The AmsNetId of the TwinCAT computer whose NT system time is to be read is specified here.

GetBACnetAdapterTime_nTiAuto

UDINT

Based on this time information, the local BACnet system time of a TwinCAT system is regularly determined automatically.

GetLocalSysTime_nTiAuto

UDINT

Based on this time information, the local NT system time of a TwinCAT system is regularly determined.

FB_BA_ExternalSysTime 4: Inputs CONSTANT

Name

Type

Description

GetExtSysTime

FB_BA_GetTime

The function block GetExtSysTime determines the external NT system time of a TwinCAT system.

SetSysTimeLocal

FB_BA_SetTime

The locally determined BACnet system time (GetBACnetAdapterTime) is written to the local NT system time of the TwinCAT system using the function block SetSysTimeLocal.

SetBACnetAdapterTime

FB_BACnet_SetAdapterTime

The function block SetBACnetAdapterTime can set both the local BACnet system time of a TwinCAT system (SetBACnetAdapterTime.bTrigSyncLocal) and, by triggering a broadcast command (SetBACnetAdapterTime.bTrigSyncBroadcast), all BACnet system times of a network. Important parameters are explained below.

GetLocalSysTime

FB_BA_GetTime

The function block GetLocalSysTime determines the local NT system time of the TwinCAT system. The determined time is transferred to the global variable lists SysTime.

GetBACnetAdapterTime

FB_BACnet_GetAdapterTime

The function block "GetBACnetAdapterTime" determines the local BACnet system time. Important parameters are explained below.

VAR

Name

Type

Description

GetExtSysTime_bSync

BOOL

The variable triggers the writing of the external system time to the local NT system time of the TwinCAT system and the local BACnet system time of the TwinCAT system.

GetExtSysTime_rtrigSync

R_TRIG

The function block generates a rising edge after successfully reading the external system time GetExtSysTime and passes this on to GetExtSysTime_bSync.

GetBACnetAdapterTime_wYear

WORD

Year specification of the BACnet system time.

GetBACnetAdapterTime_wMonth

WORD

Month specification of the BACnet system time.

GetBACnetAdapterTime_wDayOfWeek

WORD

Indication of the day of the week of the BACnet system time.

GetBACnetAdapterTime_wDay

WORD

Indication of the day in the month of the BACnet system time.

GetBACnetAdapterTime_wHour

WORD

Hour specification of the BACnet system time.

GetBACnetAdapterTime_wMinute

WORD

Minute specification of the BACnet system time.

GetBACnetAdapterTime_wSecond

WORD

Seconds specification of the BACnet system time.

GetBACnetAdapterTime_wMilliseconds

WORD

Milliseconds specification of the BACnet system time.

Parameter of SetBACnetAdapterTime

These parameters are used to configure time synchronization.

Name

Type

Description

SetBACnetAdapterTime.bTrigSyncLocal

BOOL

On a rising edge at this input, the content of the structure SetBACnetAdapterTime.stDateTime is written to the local BACnet system time of the TwinCAT system.

SetBACnetAdapterTime.bTrigSyncBroadcast

BOOL

On a rising edge at this input, the content of the SetBACnetAdapterTime.stDateTime structure is written to all BACnet system times of a network as well as the local BACnet system time of the TwinCAT system.

SetBACnetAdapterTime.stDateTime

ST_BA_DateTime

Time specification which is written to the local BACnet system time.

SetBACnetAdapterTime.fbAdapter

fbAdapter

The function block fbAdapter represents a BACnet device. This is pre-initialized to the local BACnet device of the TwinCAT system under Devices.

SetBACnetAdapterTime.bSuccess

BOOL

The system time was read successfully from the target system. The variable is TRUE for one cycle.

SetBACnetAdapterTime.bError

BOOL

Error while reading the BACnet system time.

Parameter of GetBACnetAdapterTime

These parameters are used to configure time synchronization.

Name

Type

Description

GetBACnetAdapterTime.bTrig

BOOL

A rising edge at this input determines the local BACnet system time of a TwinCAT system.

GetBACnetAdapterTime.nTiAuto

UDINT

The local BACnet system time of a TwinCAT system is automatically determined on a regular basis using this time specification from the parameter menu.

The time specification must be greater than or equal to 500ms. The default value is 1800s.

GetBACnetAdapterTime.fbAdapter

fbAdapter

The function block fbAdapter represents a BACnet device. This is pre-initialized to the local BACnet device of the TwinCAT system under Devices.

GetBACnetAdapterTime.bSuccess

BOOL

The system time was read successfully from the target system. The variable is TRUE for one cycle.

GetBACnetAdapterTime.stDateTime

ST_BA_DateTime

Current BACnet system time of a TwinCAT system.

GetBACnetAdapterTime.stTimeStruct

TIMESTRUCT

Current BACnet system time of a TwinCAT system.

GetBACnetAdapterTime.bError

BOOL

Error while reading the BACnet system time.

Requirements

Development environment

Necessary function

TwinCAT from v3.1.4024.35

TF8040 | TwinCAT Building Automation from V5.0.0.0