FB_BACnet_WriteProp
Function block for access to BACnet properties via ADS. All BACnet properties of server and client objects that are shown in the Online tab of the respective BACnet object can be read or written via ADS. If a client (remote BACnet server) is accessed via ADS, the ADS accesses are converted to BACnet queries and sent to the remote server.
Application
The function block instance is created by the PLC program and called cyclically. The input BACnetDevicePort and sNetId must be assigned the appropriate AMS port and AMS NetID. The AMS port and AMS NetID for each BACnet server and client can be queried via the corresponding BACnet device function block.
The AMS NetID does not match the local AMS NetID and always has to be specified - empty strings cannot be used! |
The current AMS NetID and AMS port are output by the corresponding FB_BACnet_Device or FB_BACnet_RemoteDevice:
AMS NetID and AMS port in the output structure stAdsConn of the device function block.
TYPE ST_BACnet_AdsConnection :
STRUCT
bValid : BOOL;
nReload : USINT;
sAmsNetId : T_AmsNetId;
nAmsPort : T_AmsPort;
bServer : BOOL;
bClient : BOOL;
bNSink : BOOL;
nDeviceId : UDINT;
END_STRUCT
END_TYPE
In addition, the AMS port and the AMS NetID can be displayed in the TwinCAT System Manager (see Figures 3 and 4). Ports for servers and clients may vary, depending on the configuration.
VAR_INPUT
BACnetDevicePort : UINT:=16#FFFF;
bExecute : BOOL;
sNetId : T_AmsNetId;
ObjectType : E_BACNETOBJECTTYPE;
PropertyID : E_BACNETPROPERTYIDENTIFIER;
Priority : E_BACNETPRIORITY;
DataType : E_BACNETDATATYPES;
ObjectInstance : UDINT;
ptrValue : POINTER TO BYTE;
nLenValue : UDINT;
BACnetDevicePort: AMS port under which the desired object was created.
bExecute: Rising edge at the input start the write process. Falling edge deletes the output bDone.
sNetId: AMS NetID of the BACnet device (adapter) under which the server or client was configured.
ObjectType: Enumeration of the object type (AnalogValue, BinaryInput...).
PropertyID: Enumeration of the property ID (Present_Value, Status_Flags...).
Priority: Enumeration of the write access priority. The priority is required for write accesses to prioritisable properties (e.g. Present_Value). Access with priority x then generates an entry at location x in the corresponding Priority_Array.
DataType: Data type of the property (Bool, BinaryPV, Real, Unsigned Integer...).
ObjectInstance: Object number of the BACnet object (the lower 22 bits of the Object_Identifier).
ptrValue: Pointer to the variable in which the data are to be stored (can be determined with ADR()).
nLenValue: Byte length of the variable in which the data are to be stored (can be determined with SIZEOF()).
VAR_OUPUT
bDone : BOOL;
bBusy : BOOL;
bError : BOOL;
nErrID : UDINT;
bDone: Writing of the data completed successfully. bDone remains set until bExecute is reset. If bExecute is reset before bDone is active, bDone is set for one cycle.
bBusy: The block is busy.
bError: Error during processing.
nErrID: ADS error code.