Skip to main content

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.

. General rules:
  • Starting and stopping the BACnet stack

    Always use BACnetServer.StartBACnetStack and BACnetServer.StopBACnetStack or AutoStart. Never directly use the corresponding functions of the CmpBACnet library, such as CmpBACnet.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 the BACnet library, such as CmpBACnet.BACnetStorePropertyInstance.

  • Triggering of asynchronous requests

    Always use the specified client function blocks of the BACnet library, such as BACnetClientReadProperty. Never directly use the corresponding functions of the CmpBACnet library, such as CmpBACnet.BACnetReadProperty. All functions of the CmpBACnet library that require a BACnetAsyncTransactionToken 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 and BACnetServer.RegisterHook/UnregisterHook/RegisterCallback/UnregisterCallback. Never directly use the corresponding functions of the CmpBACnet library, such as CmpBACnet.BACnetSetHook or CmpBACnet.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.BACnetEventCallbacks. But first check whether or not the BACnetDefaultImpl library already contains an appropriate standard implementation.