FB_BACnet_Device

The following function block is used for linking the PLC program to a local BACnet device object (server). The linking of the function block takes place with the aid of process data.

The process data can be linked manually or automatically via PLC automapping. The comments required for PLC automapping ( (* ~ (BACnet... | ??? | ??? ) *) ) are already included in the declaration of the function block. The process data for the BACnet device object also include the required process data for linking the BACnet server.

FB_BACnet_Device 1:
Fig. 1: Process data of the BACnet device object and server in the System Manager.
FB_BACnet_Device 2:
Fig. 2: Function block of the BACnet device object and server in the PLC program.

Use

The function block "FB_BACnet_Device" is used to read the state of the local BACnet device object (System_Status) and output it in the PLC program. In addition, the process data "Server Control" is used to control the local BACnet server (activation and handling of the PLC backup).

The function block "FB_BACnet_Device" also requires a global instance of the function block FB_BACnet_Adapter for each PLC project. The function block FB_BACnet_Adapter establishes the connection between PLC and BACnet adapter in the System Manager. This global instance is already provided by the PLC library. The hierarchy between FB_BACnet_Adapter, "FB_BACnet_Device" and FB_BACnet_RemoteDevice and an object of type AnalogValue (AV) is shown below:

FB_BACnet_Device 3:
Figure 3: Example for linking the FB instances in the PLC.

For information on the use of the function blocks FB_BACnet_Adapter and _RemoteDevice, see FB_BACnet_Adapter and FB_BACnet_RemoteDevice respectively.

VAR_INPUT

bReset           : BOOL;
bSupportBackup   : BOOL;
nAdsPort         : UINT := 1000; (* Optional setting: Ads port of local BACnet-Server, default = 1000 *)

bReset: Resets the error state in the event of a signal change FALSE --> TRUE.

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 PLC data (by default under: "C:\TwinCAT\Boot\") have to be created as BACnet file objects and associated with the value "TwinCAT Configuration File" of the property File_Type (in this way the BACnet stack ensures that the files are saved).
If BACnet-based backup of the persistent PLC data is used, no further instance of the block FB_WritePersistentData should be used in the PLC runtime (FB_WritePersistentData is executed by FB_BACnet_Device)

nAdsPort: ADS 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 System Manager). The port number can be read in the System Manager (see Fig. 4):

FB_BACnet_Device 4:
Fig. 4: ADS port in the System Manager

VAR_OUTPUT

eSystemStatus    : E_BACnetDeviceStatus;
sAmsNetId        : T_AmsNetId;
bBackupActive    : BOOL;
bOperational     : BOOL;
bFirstCycle      : BOOL;
bError           : BOOL;
nErrorId         : UINT;

eSystemStatus: Status of the BACnet server object (see BACnet specification DIN EN ISO 16484-5 for BACnet device object and property System_Status).
0: BACnetDeviceStatus_Operational
1: BACnetDeviceStatus_OperationalReadOnly (only read access to properties)
2: BACnetDeviceStatus_DownloadRequired (loading of the configuration required)
3: BACnetDeviceStatus_DownloadInProgress (configuration download in progress)
4: BACnetDeviceStatus_NonOperational
5: BACnetDeviceStatus_BackupInProgress

sAmsNetId: Output of the AMS NetID of the local BACnet adapter (can be used for asynchronous access to BACnet objects via ADS).

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

bOperational: BACnet device object (of the local server) reports "operational" and the device adapter reports the status "GetGatewayMAC" (0x03xx) or "WaitGatewayMAC" (0x04xx) or "Complete" (0x08xx). If the output becomes FALSE, all linked objects are blocked (block instances).

bFirstCycle: Is set for one cycle when the block instance is first called after a PLC reset or restart.

bError: An error is pending.

nErrorId: Error number
0 = no error
1 = no valid AMS NetID
20 = error during writing of the persistent data
The error numbers can be queried as block constants via the FB instance (FB_BACnet_Device.nERR_xxx). All errors with error number equal or greater than 20 have to be acknowledged with bReset.

An instance of function block FB_BACnet_Device is required whenever access to objects of a local BACnet server from the PLC is required. In principle, several instances of the function block FB_BACnet_Device can be created, although this would result in an error message in the System Manager when PLC automapping is used. This is due to the BACnet architecture. Under a BACnet adapter (network device) only one BACnet server can be created at a time. If PLC automapping is not used, any number of BACnet adapters and servers can be used in a PLC project. In this case the instances are linked manually.

The function block FB_BACnet_Device accesses the global variable "pBACnet_Adapter" internally. It contains a reference to the global instance of the function block FB_BACnet_Adapter. If several instances of the function block FB_BACnet_Device are to be created and manually linked in the System Manager with the corresponding BACnet servers, several instances of the function block FB_BACnet_Adapter have to be created. Before the instance of the BACnet server block is called, it is essential to call the corresponding instance of the BACnet adapter function block. A CFC example is provided below (Please note the order in which the function blocks are called!):

FB_BACnet_Device 5:
Figure 5: Example for using several adapter and server instances in a PLC project.
FB_BACnet_Device 6:
Figure 6: Example for calling function blocks of type FB_BACnet_AnalogValue with different local BACnet servers in a PLC project.

The use of several local BACnet servers (adapters) in a PLC project is a special case and is not recommended. It could make sense (e.g. in cases where several network cards and therefore separate BACnet networks are used) to use several PLC projects and therefore several PLC runtimes. Data exchange between the individual runtimes can be realized via process data mapping or ADS communication. In this case PLC automapping could be used for BACnet objects.