You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

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=bacstacd.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.

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

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

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


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




  • Adapt the "PLC_PRG" POU as follows:


    Declaration

    VAR

    fbReadProperty : BACnet.BACnetClientReadProperty;
    xReadExecute : BOOL;
    lrReadValue : LREAL;
    xInitDone : BOOL := FALSE;
    END_VAR


    Declaration

    VAR
    	fbReadProperty	: BACnet.BACnetClientReadProperty;
    	xReadExecute	: BOOL;
        lrReadValue		: LREAL;
    	
    	xInitDone 		: BOOL := FALSE;
    END_VAR

    Implementation

    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.

  • Adapt the "PLC_PRG" POU as follows:



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

  • Download the application to the PLC.

BACnet client

  • Download the application to the PLC.

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);
  • No labels