When to Use the BACnet Library or the CmpBACnet Library
Note
The descriptions always also apply to the corresponding library of CODESYS BACnet2 SL ("major revision 2").
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 functions of CmpBACnet
. 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.
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
.
For more information, see: Architecture, Components, and their Tasks
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.