Skip to main content

Access to BACnet Objects and Their Properties

Each function block of an BACnet object inserted as a device in the project tree is derived from the BACnetStaticObjectBase function block (library BACnet) and therefore from BACnetObjectBase.

BACnetObjectBase provides the capability of changing any BACnet property for any BACnet object function block by means of the general function SetPropertyInstance.

The data for the BACnet properties to be set are transferred to SetPropertyInstance in the form of the IEC_BACNET_PROPERTY_CONTENTS structure. Besides an enumeration that describes the data type, this structure also contains a buffer that has a POINTER TO BYTE to the actual BACnet property data. This makes it possible to transfer any BACnet property data structures within the IEC_BACNET_PROPERTY_CONTENTS structure. The specified data type defines the structures or data to which the buffer points.

The enumeration CmpBACnet.IEC_BACNET_DATA_TYPE provides the selection of CODESYS BACnet data types; the corresponding data type is specified in the comment.

The basic function block BACnetObjectBase provides auxiliary functions (example: SetBACnetRealProperty, SetBACnetBooleanProperty) for some of the frequently used data types.

Example 1. Example of the correct usage of IEC_BACNET_PROPERTY_CONTENTS
METHOD SetBACnetRealProperty
VAR_INPUT
    propID: CmpBACnet.IEC_BACNET_PROPERTY_ID;
    rVal : REAL;
END_VAR
VAR
    BACreal : CmpBACnet.IEC_BACNET_REAL := 0.0;
    conts : CmpBACnet.IEC_BACNET_PROPERTY_CONTENTS := ( tag := CmpBACnet.IEC_BACNET_DATA_TYPE.DATA_TYPE_REAL,
        nElements := 1,
        buffer := ( nBufferSize := SIZEOF(REAL), pBuffer := ADR(BACreal) ),
        rawBuffer := ( nBufferSize := 0, pBuffer :=0) );
END_VAR
BACreal := rVal;
SetPropertyInstance(propID, -1, conts);

This code sets a BACnet property of type REAL to the value 0.0.



Accordingly, in order to read BACnet properties in the most general case, the BACnetObjectBase function block provides the GetPropertyInstance function. Within the IEC_BACNET_PROPERTY_CONTENTS structure, you can transfer either 1) a buffer pre-initialized with the correct data type, which is then filled, or 2) a buffer of size 0, which is initialized automatically, but which you release again by means of the FreeStackAllocatedMemory function.

Regardless of this general case, auxiliary functions are provided for the most frequent cases. Furthermore, for all properties defined in the BACnet standard, there is a selection of function block properties for each BACnet object function block which allows for direct, typed access.