Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

BACnet: Cyclic Reading of a Property

Hardware

  • Raspberry Pi as a BACnet server (provides data points)
  • CODESYS Control Win V3 as a BACnet client (cyclic reading of the data points)

Requirements for the server and client

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

  • Including the BACnet component:

...

  • [ComponentManager

...

  • ]

...


  • Component.

...

  • [n+1

...

  • ]=CmpBACnet
  • Including the INI file of the BACnet stack (pay attention to the syntax):

...

  • [CmpBACnet

...

  • ]

...


  • IniFile=bacstac

...

  • d

...

  • .ini

Requirements for the BACnet server

  • Create a "Standard project" and select "CODESYS Control Raspberry Pi SL" as the device.
  • Define the target system by means of the Network scan.

Image Modified

  • Insert a "BACnet Server" and a "BACnet Analog Value" object in the device tree:

Image Modified

  • Every device in a BACnet network must have a unique ID. Set this in the tab BACnet Interface Parameters of the "BACnet Server" object.

    Image Modified

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".

Image Modified

Info
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.
  • Adapt the "PLC_PRG" as follows:

Image Modified

...

Section
Column
width7

Declaration

Column
width93

...

Code Block
themeConfluence
VAR
    xSwitch        :    BOOL;
    lrValue        :    LREAL := 0.23;

...


END_VAR
Section
Column
width7

Implementation

Column
width93
Code Block
themeConfluence
// 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 (As of BACnet-Version 1.2.0.0)

  • Create a "Standard project" and select "CODESYS Control Win V3" as the device.
  • Define the target system by means of the network scan (see BACnet server).
  • Insert a "BACnet Server" object and rename it to "BACnet_Client"

    Image Added


  • Adapt the PLC_PRG POU as follows:




    Section
    Column
    width7

    Declaration

    Column
    width93
    Code Block
    themeConfluence
    VAR
    	fbReadProperty	: BACnet.BACnetClientReadProperty;
    	xReadExecute	: BOOL;
        lrReadValue		: LREAL;
    	
    	xInitDone 		: BOOL := FALSE;
    END_VAR




    Section
    Column
    width7

    Implementation

    Column
    width93
    Code Block
    themeConfluence
    IF NOT xInitDone THEN
    	fbReadProperty.RegisterToServer(BACnet_Client);
    	fbReadProperty(dwTargetDeviceNumber := 718,
        				objType := BACnet.CmpBACnet.IEC_BACNET_OBJECT_TYPE.OBJ_ANALOG_VALUE, objInst := 1,
        				propID := BACnet.CmpBACnet.IEC_BACNET_PROPERTY_ID.PROP_PRESENT_VALUE);
    	xInitDone := TRUE;
    ELSE
    	fbReadProperty(xExecute := xReadExecute);
    	IF fbReadProperty.xDone THEN
    		xReadExecute := FALSE;
    		lrReadValue := BACnet.GetRealFromContents(fbReadProperty.result);
    	END_IF
    END_IF





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

  • Create a "Standard project" and select "CODESYS Control Win V3" as the device.
  • Define the target system by means of the network scan (see BACnet server).
  • Insert a "BACnet Server" object and a "BACnet Client Property Access" object in the device tree.

Image Modified

  • Adapt the "PLC_PRG" POU as follows:

Image Modified


...

Section
Column
width7

Declaration

Column
width93

...

Code Block
themeConfluence
VAR
    readPropertyFB     	: BACnet.ClientReadProperty;

...


    readReal         	: LREAL;
END_VAR
Section
Column
width7

Implementation

Column
Code Block
themeConfluence
//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

  • Download the application to the PLC.

Image Modified

BACnet client

  • Download the application to the PLC.

Image Modified

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:

...

Section
Column
width7

Implementation

Column
width93
Code Block
themeConfluence
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);