ADSRDWRTEX
This function block allows execution of a combined ADS write/read instruction. Data is transmitted to an ADS device (write) and its response data read with one call.
VAR_INPUT
VAR_INPUT
NETID : T_AmsNetId;
PORT : T_AmsPort;
IDXGRP : UDINT;
IDXOFFS : UDINT;
WRITELEN : UDINT;
READLEN : UDINT;
SRCADDR : DWORD;
DESTADDR : DWORD;
WRTRD : BOOL;
TMOUT : TIME;
END_VAR
NETID : is a string containing the AMS network ID of the target device to which the ADS command is directed.
PORT : contains the port number of the ADS device.
IDXGRP : contains the index group number (32-bit, unsigned) of the requested ADS service. This value is to be found in the ADS table of the addressed device.
IDXOFFS : contains the index offset number (32-bit, unsigned) of the requested ADS service. This value is to be found in the ADS table of the addressed device.
WRITELEN : contains the number of data to be written in bytes.
READLEN : contains the number of data to be read in bytes.
SRCADDR : contains the address of the buffer from which the data to be written is to be fetched. The programmer is responsible for dimensioning the buffer such that it can accommodate WRITELEN bytes. The buffer can be a single variable, an array or a structure, whose address can be found with the ADR operator.
DESTADDR : contains the address of the buffer which is to receive the data that has been read. The programmer is responsible for dimensioning the buffer such that it can accommodate READLEN bytes. The buffer can be a single variable, an array or a structure, whose address can be found with the ADR operator.
WRTRD : the ADS command is triggered by a rising edge at this input.
TMOUT : specifies the time until the abortion of the function.
VAR_OUTPUT
VAR_OUTPUT
BUSY : BOOL;
ERR : BOOL;
ERRID : UDINT;
COUNT_R : UDINT;
END_VAR
BUSY : if the function block is activated, this output is set. It remains set until feedback is received.
ERR : if an ADS error should occur during the transfer of the command, then this output is set once the BUSY output is reset.
ERRID: supplies the ADS error number or the device-specific error number when the ERR output is set.
COUNT_R: number of successfully read data bytes.
Sample of a call in FBD:
PROGRAM MAIN
VAR
fbAdsRdWrtEx : ADSRDWRTEX;
sSymName : STRING:='MAIN.VARCOUNTER';
iSymHandle : UDINT;
bWriteRead : BOOL;
bBusy : BOOL;
bError : BOOL;
nErrId : UDINT;
cbRealReadLen: UDINT;
END_VAR
In this sample, an ADS command is sent to an ADS device with network address '172.16.2.209.1.1' and port number 801. Port number 801 could, for instance, be used to address the PLC's first runtime system. The ADS service is encoded in the index group and the index offset. The handle of a PLC variable with the symbol name 'MAIN.VARCOUNTER' is to be read here and returned to the caller. The WRITELEN input parameter contains the string length of the symbol name, plus one byte for the closing NULL. If successful, 4 bytes of data are copied to the address of the iSymHandle variable.
Requirements
Development environment |
Target platform |
PLC libraries to include |
---|---|---|
TwinCAT v2.7.0 & TwinCAT v2.8.0 |
BC9xxx (165) firmware version >= 0xB6 |
TcAdsBC.Lb6 |