FB_BACnet_ReadProp
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 NetID. The AMS port and 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;
DataType : E_BACNETDATATYPES;
ObjectInstance : DINT;
ptrValue : POINTER TO BYTE;
nLenValue : UDINT;
BACnetDevicePort: AMS port under which the desired object was created.
bExecute: Rising edge at the input starts the read 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...).
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 read data are to be stored (can be determined with ADR()).
nLenValue: Byte length of the variable in which the read data are to be stored (can be determined with SIZEOF()).
VAR_OUPUT
bDone : BOOL;
bBusy : BOOL;
bError : BOOL;
nErrID : UDINT;
nProcessedLen : UDINT;
bDone: Read 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.
nProcessedLen: Byte length of the read data. The length may differ from the target length nLenValue (smaller/equal). The gap between the input data length nLenValue and the actual read data length nProcessedLen is filled with zeros in the transferred data range.