ADSRDWRT

ADSRDWRT 1:

This 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 identifier 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, in bytes, of the data that is to be written.

READLEN : Contains the number, in bytes, of the data to be read.

SRCADDR : Contains the address of the buffer from which the data to be written is to be fetched. The programmer is himself responsible for dimensioning the buffer to such a size that ‘WRITELEN’ bytes can be taken from it. 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 himself responsible for dimensioning the buffer to a size that can accept ‘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 : States the time before the function is cancelled.

VAR_OUTPUT

VAR_OUTPUT
    BUSY        : BOOL;
    ERR         : BOOL;
    ERRID       : UDINT;
END_VAR

BUSY : This output remains TRUE until the block has executed a command, but at the longest for the duration supplied to the ‘Timeout’ input. While Busy = TRUE, no new command will be accepted at the inputs. Please note that it is not the execution of the service but its acceptance whose time is monitored.

ERR : This output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in ‘ErrorId’. If the block has a timeout error, ‘Error’ is TRUE and ‘ErrorId’ is 1861 (hexadecimal 0x745). Is reset to FALSE by the execution of a command at the inputs.

ERRID : Contains the command-specific error code of the most recently executed command. Is reset to 0 by the execution of a command at the inputs.

 

Example of calling the block in FBD:

ADSRDWRT 2:

The value of the variable with the name ‘aLRealVar’ is here read from the PLC which is running on the computer with the Net-Id ‘1.1.1.2.7.1’. For this purpose, the computer address mentioned, the port number of the PLC’s first run-time system, the index group, and the index offset for reading the variable by name (F004 hex, 0) are given. The name of the variable is to be supplied to the PLC server; it is placed for this purpose in a buffer. Since the variable is global, it has a leading dot. This makes the length of the data to be written 10 characters (1 dot and 9 letters). Since the variable to be read is of type LREAL, the number of bytes to be read is 8. The address of the name buffer is given as the address for the data to be written, while for the receive data the address of an LREAL variable (‘resultVar’) is given. The diagram shows the state of the block in flow control after execution of the WriteRead instruction: the value 1234.567, which was previously contained in aLRealVar is now also contained in resultVar.

Requirements

Development environment

Target system type

PLC libraries to include

TwinCAT v2.7.0

PC or CX (x86)

PLCSystem.Lib

TwinCAT v2.8.0

PC or CX (x86)

TcSystem.Lib

TwinCAT v2.10.0 Build >= 1301

CX (ARM)

TcSystem.Lib