FB_BACnet_Adapter

Function block for linking the PLC program with a local BACnet adapter (network card). 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.

Attention:

This block must not be instantiated in the PLC program! An instance of the block is already included in the global data of the PLC library (fbBACnet_Adapter), where it is automatically detected by the PLC automapping. Instantiation in the PLC program is only necessary if several BACnet adapters are used in a PLC program!

 

FB_BACnet_Adapter 1:

 

Application

The function block FB_BACnet_Adapter is used to read the state of the local BACnet adapter (process data Device Status) and output it in the PLC program. In addition, the process dataAmsNetId is used to read the AMS NetID of the BACnet adapter and output it to sAmsNetId.

FB_BACnet_Adapter 2:
Fig. 1: Process data of the BACnet adapter in the System Manager.

As described above, one instance of the block FB_BACnet_Adapter is already provided by the PLC library as a global instance and must therefore not be explicitly created. The global instance is recognized by the PLC automapping and automatically linked to the corresponding BACnet adapter in the System Manager.

The block instance is required by the BACnet function blocks FB_BACnet_Device and FB_BACnet_RemoteDevice. The hierarchy between FB_BACnet_Adapter, FB_BACnet_Device and a BACnet object of type AnalogValue is shown below:

FB_BACnet_Adapter 3:
Fig. 2: Relationship between FB_BACnet_Adapter, FB_BACnet_Device and a BACnet function block (e.g. FB_BACnet_AnalogValue).

Notes re. the figure:

  • Red dashed: Function block call FB_BACnet_Adapter from the global data of the PLC Library. Each call updates the global pointer pBACnet_Adapter, which is used by the blocks FB_BACnet_Device and FB_BACnet_RemoteDevice as adapter reference.
  • Red: Device blocks FB_BACnet_Device and FB_BACnet_RemoteDevice will use the global instance of the BACnet adapter internally to check the status of the BACnet connection and read the AMS NetID. The instance is determined via the global pointer pBACnet_Adaper. The global pointer can also be overwritten in the PLC program with its own adapter instance, before FB_BACnet_Device and FB_BACnet_RemoteDevice are called. In this way it is possible to realize PLC programs with multiple adapters, for example.
  • Orange dashed: Function block call FB_BACnet_Device with the instance from the PLC program. The user creates the instance locally or globally in the PLC program. It is linked to the corresponding device in the TwinCAT System Manager through PLC automapping.
  • Orange: Transfer of the device instance (FB_BACnet_Device) to the function block of the BACnet object. The function block of the BACnet object reads among other things the device status of the instance.

Tip:

The instance of the block FB_BACnet_Adapter does not have to called in the PLC program. If required, the adapter is called automatically by the blocks FB_BACnet_Device or FB_BACnet_RemoteDevice.

VAR_OUPUT

eAdapterStatus  : E_BACNETADAPTERSTATUS;
bEthLinkOk      : BOOL;
bGatewayOk      : BOOL;
sAmsNetId       : T_AmsNetId;
bFirstCycle     : BOOL;
bError          : BOOL;
nErrorId        : UINT;

eAdapterStatus: Status of the BACnet adapter; see: E_BACNETADAPTERSTATUS.

bEthLinkOk: The local Ethernet connection is active (cable connected, adapter linked) if the output is set to TRUE.

bGatewayOk: The configured gateway can be reached if the output is set to TRUE.

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

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 code, see BACnet_Globals for an overview.

 

FB_BACnet_Adapter 4:

If there is no network connection (bEthLinkOk = FALSE) or the gateway cannot be reached (bGatewayOk = FALSE), all remote objects (BACnet objects under one client) are blocked. Objects of the local BACnet server are not affected.