The IEC library CmpBACnet
represents the integration of the BACnet stack into a CODESYS IEC environment and provides the BACnet data types as well as the BACstack
methods. The sole use of the IEC library CmpBACnet
(without the BACnet
and BACnetDefaultImpl
libraries) would result in complex and lengthy IEC application code.
The BACnet
library simplifies BACnet application development considerably as compared to the
sole use of CmpBACnet
, especially in the following areas:
-
Starting and stopping the BACnet stack
-
Using BACnet server objects and their properties
-
Triggering asynchronous requests (mainly client service requests) and processing the request transaction
-
Processing of callbacks from the BACnet stack (see
IBACnetEventConsumer
) and distributing the callbacks to multiple receivers in the application
Furthermore, the BACnet
library provides a plug-in mechanism (BACnetServerPlugin
) for extending certain aspects of the BACnet
library. BACnetServerPlugin
is the basis for the BACnetDefaultImpl
library.
The BACnetDefaultImpl
library is used for the additional simplification of BACnet application development.
The BACnet standard ASHRAE 135 leaves some aspects of the practical use of BACnet
open. The most notable examples include the following:
-
Persistence of server objects
-
Storage and persistence of
Trend Log
,Trend Log Multiple
, andEvent Log
entries -
Update of the date/time information of the device object
The IEC library BACnet
is intended as a layer over the IEC library CmpBACnet
. However, the layer does not hide the library because this would require the BACnet
library to have "facade" functions for CmpBACnet
functions. These facade functions would result in larger application code and increased
runtime requirements. This is difficult for the PLC to accept. For this reason, it
is necessary to know when elements from the BACnet
library or CmpBACnet
library are to be used.
General rules:
-
Starting and stopping the BACnet stack
Always use
BACnetServer.StartBACnetStack
andBACnetServer.StopBACnetStack
orAutoStart
. Never directly use the corresponding functions of theCmpBACnet
library, such asCmpBACnet.BACnetServerInit
. -
Using BACnet server objects and their properties
Always use the specified function blocks in IEC-lib-BACnet, such as
BACnetAnalogValue
. Never directly use the corresponding functions of theBACnet
library, such asCmpBACnet.BACnetStorePropertyInstance
. -
Triggering of asynchronous requests
Always use the specified client function blocks of the
BACnet
library, such asBACnetClientReadProperty
. Never directly use the corresponding functions of theCmpBACnet
library, such asCmpBACnet.BACnetReadProperty
. All functions of theCmpBACnet
library that require aBACnetAsyncTransactionToken
belong to this category and should never be used directly. -
Processing of callbacks from the BACnet stack and distributing the callbacks to multiple receivers in the application
Always use
IBACnetEventConsumer
andBACnetServer.RegisterHook
/UnregisterHook/RegisterCallback
/UnregisterCallback
. Never directly use the corresponding functions of theCmpBACnet
library, such asCmpBACnet.BACnetSetHook
orCmpBACnet.BACnetSetCallback
.
When is it appropriate and safe to directly call the functions of the CmpBACnet
library?
Basically, it is only necessary to call functions of CmpBACnet
directly when a corresponding functionality is not provided in the BACnet
library. Check the BACnet
library first before trying to use CmpBACnet
directly. It is possible to use blocking functions in CmpBACnet
, such as BACnet*CbCompletion
, BACnetIam(Ex)
, or BACnetIHave(Ex), BACnetUnconf*
.
Most often, you will use BACnet*CbCompletion
to implement your specific IBACnetEventConsumer.BACnetEventCallback
s. But first check whether or not the BACnetDefaultImpl
library already contains an appropriate standard implementation.
The open BACnetDefaultImpl.library
is provided in the example folder and can be used for user customization.