FB_BACnet_Device

FB_BACnet_Device 1:

Application

Function block for interfacing of the PLC program with a local BACnet device object (server). The function block is linked with the aid of process data and ADS (evaluate AMS port, read object list, determine the stack revision and backup).

FB_BACnet_Device 2:

As a rule, the function block is backward compatible (revision 6). The BACnet revision in use can be read at output nRevision.
If revision 6 is used, some ADS services of the BACnet stack are limited; e.g. the AMS port of the BACnet device (server and client) can only be determined automatically from revision 12. If revision 6 is used, the AMS port (Ads port) shown in the TwinCAT System Manager must therefore be transferred at input nAmsPort (see Figure 1)!

FB_BACnet_Device 3:
Fig. 1: AMS port of the BACnet device in the TwinCAT System Manager

VAR_INPUT

FB_BACnet_Device 4:

Inputs are optional and do not have to be assigned if Revision 12 or higher is used.

bReset          : BOOL;
bSupportBackup  : BOOL;
bWritePersis    : BOOL;
bDisableWOC     : BOOL;
bReload         : BOOL;
nAmsPort        : T_AmsPort:=1000;  (*siehe Info*)

bReset: resets the error state in the event of a signal change FALSETRUE.

bSupportBackup: if the input is set to TRUE, saving of the persistent PLC runtime data via BACnet is supported. If this mode is activated, the persistent files of the PLC (by default under: "C:\TwinCAT\Boot\") must be created as BACnet file objects and provided with the value "TwinCAT Configuration File" of the property File_Type (thus the BACnet stack takes care of the backup and transfer of the files to the backing up remote system).
When using the BACnet-side backup of the persistent PLC data, no further instance of the function block FB_WritePersistentData has to be used in the PLC runtime (FB_WritePersistentData is executed by FB_BACnet_Device) - The input bWritePersis triggers the writing of the persistent data independently of the BACnet backup.

bWritePersis: signal change FALSETRUE triggers writing of the persistent PLC data, independent from the BACnet backup. Within the function block, the call is triggered by FB_WritePersistentData.

bDisableWOC: state TRUE at the input disables writing of process data to the BACnet objects of the respective BACnet device. All property write access is blocked.

bReload: the ADS connection is renewed. Subsequent function blocks, which use the ADS connection, are also triggered.

nAmsPort: only if revision 6 is used, otherwise do not use: AMS port of the local BACnet server. The default number is 1000 (provided the BACnet server is the first element under the BACnet adapter in the TwinCAT System Manager). The port number can be read in the System Manager (see Figure 1).

VAR_OUPUT

nRevision           : DINT:=-1;
stAdsConn           : ST_BACnet_AdsConnection;
eSystemStatus       : E_BACNETDEVICESTATUS;
bBackupActive       : BOOL;
bWritePersisActive  : BOOL;
bOperational        : BOOL;
bWOCDisabled        : BOOL;
bFirstCycle         : BOOL;
dtLocalTime         : ST_BACnet_DateTime;
bError              : BOOL;
nErrorId            : UINT;

nRevision: Output of the BACnet revision number in use.

stAdsConn: Structure with the ADS connection data (from Revision 12 the included AMS port is determined automatically).

eSystemStatus: Status of the BACnet server object (see BACnet specification DIN EN ISO 16484-5 for BACnet device object and property System_Status).

bBackupActive: Feedback to indicate that a backup via BACnet is executed if the output is set to TRUE.

bWritePersisActive: Writing of the persistent PLC data is executed. Writing of the persistent PLC data can be triggered by BACnet backup or by setting the input bWritePersis.

bOperational: Device adapter is no longer in Init state. If the output falls to FALSE, all linked BACnet object function blocks in the PLC program are blocked.

bWOCDisabled: Feedback to input bDisableWOC.

bFirstCycle: Output is set to TRUE when the function block instance is called for the first time (PLC start). Subsequently the output remains on FALSE.

dtLocalTime: Current BACnet time (see properties Local_Date and Local_Time of the BACnet device object). The function block FB_BACnet_TimeSync is available for time synchronization between operating systems, BACnet stack and BACnet network.

bError: An error is pending.

nErrorId: see global constants (BACnet_Globals).