Hardware

Requirements for the server and client

Check that the following entries are present in the file CODESYSControl.cfg.

Requirements for the BACnet server

Within a device, every instance of a BACnet object type (BACnet Analog Value, BACnet Binary Value, etc.) receives a unique ID. This remains unchanged here as the value "1".

Both the instance ID of the device and the instance ID of the object type are reused in the source code of the BACnet client.


Declaration

VAR
    xSwitch        :    BOOL;
    lrValue        :    LREAL := 0.23;
END_VAR

Implementation

// Numeric simulation
IF xSwitch then
    lrValue := lrValue + 0.01;
    IF lrValue >= 5.0 THEN
        xSwitch := False;
    END_IF
ELSE
    lrValue := lrValue - 0.01;
    IF lrValue <= -5.0 THEN
        xSwitch := True;
    END_IF
END_IF


BACnet_Analog_Value.PresentValue := lrValue;

Requirements for the BACnet client (Up to BACnet-Version 1.2.0.0)



Declaration

VAR
    readPropertyFB     	: BACnet.ClientReadProperty;
    readReal         	: LREAL;
END_VAR

Implementation

//Simply execute the FB reading out a property
readPropertyFB(clientFB := BACnet_Client_Property_Access,
                dwTargetDeviceNumber := 718,
                objType := BACnet.CmpBACnet.IEC_BACNET_OBJECT_TYPE.OBJ_ANALOG_VALUE,
                objInst := 1,
                propID := BACnet.CmpBACnet.IEC_BACNET_PROPERTY_ID.PROP_PRESENT_VALUE);
    
//Start execution and send BACnet-request to BACnet-network
IF NOT readPropertyFB.xExecute THEN
    readPropertyFB.xExecute := TRUE;
END_IF


//Wait for the answer on the request. When xDone is TRUE, an answer has been received.
IF readPropertyFB.xDone THEN
    //Read out the answers contents
    readReal := BACnet.GetRealFromContents(readPropertyFB.ReadPropertyResult);
    //Reset FB and also its contents
    readPropertyFB.xExecute := FALSE;
END_IF

Downloading and starting the projects

BACnet server

BACnet client

Reading a device property

If for example general properties of the device be read, then you have to pay attention that the ID of the device number agrees with the object instance.
Example: Reading the revision number of the firmware:


Implementation

readPropertyFB(xExecute := xExecute,
                clientFB := BACnet_Client_Property_Access, 
                dwTargetDeviceNumber := 718,
                objType := BACnet.CmpBACnet.IEC_BACNET_OBJECT_TYPE.OBJ_DEVICE, 
                objInst := 718,
                propID := BACnet.CmpBACnet.IEC_BACNET_PROPERTY_ID.PROP_FIRMWARE_REVISION);