What are the names in Infosys

FUNCTION_BLOCK ReadWriteTerminalReg

TwinCAT PLC Library: Utilities BC

The "ReadWriteTerminalReg" function block enables more convenient access to the terminal registers via the status / control byte of the terminal channel (register communication). In the standard operating mode, the data inputs / outputs of the intelligent terminals (e.g. an analog output terminal) are used to exchange the analog output data. A handshake via the status / control byte enables register access; the data input / output variables are used to transfer the register values. The terminal must be mapped as a complex PLC terminal so that the status / control byte is visible in the process image. The terminal registers cannot be accessed if the terminal has been mapped as a compact PLC terminal or as a fieldbus terminal (process image of the terminal is not visible to the bus controller).
The register with the number REGNO is read or written to the register via a positive edge at the READ or WRITE input. The register write protection is canceled by the function block in the event of a write access and is then set again. When a register is written to, the new register value is read and is available at the CURRREGVALUE output. In order to permanently save changes to the register values, the voltage supply of the coupler must be interrupted or a software reset of the coupler must be carried out.

VAR_INPUT

VAR_INPUT
STATE: BYTE;
DATAIN: WORD;
REGNO: BYTE;
READ: BOOL;
WRITE: BOOL;
TMOUT: TIME;
NEWREGVALUE: WORD;
END_VAR

STATE: Status byte of the terminal channel.
DATAIN: Data input word of the terminal channel.
REGNO: Number of the register to which read or write access is to take place.
READ: The block is activated via a positive edge at this input and the current register value is read. If successful, the register value is available in the output variable CURRREGVALUE.
WRITE: The block is activated via a positive edge at this input and the value of the NEWREGVALUE input variable is written to the REGNO register. The current value of the register is then read and, if successful, is available in the output variable CURREGVALUE.
TMOUT: Specifies the timeout period that must not be exceeded when executing the function.
NEWREGVALUE: Data word that is to be written in the register with the number REGNO during a write access.

VAR_OUTPUT

VAR_OUTPUT
CTRL: BYTE;
DATAOUT: WORD;
BUSY: BOOL;
ERR: BOOL;
ERRID: UDINT;
CURREGVALUE: WORD;
END_VAR

CONTROL: Control byte of the terminal channel.
DATAOUT: Data output word of the terminal channel.
BUSY: When the function block is activated, this output is set and remains set until the execution of the function has been completed.
ERR: If an error occurs when executing the function, this output is set after the BUSY output has been reset.
ERRID: Supplies the error number when the ERR output is set.
CURREGVALUE: In the event of a successful read or write access, the current register value is output via the variable.

Error Description:

Error numberError Description
0no mistake
0x100Timeout error. The permitted execution time has been exceeded.
0x200Parameter error (e.g. with an illegal register number).
0x300The value read differs from the value written (write access to this register may not be allowed or may have failed)

Examples for a call in FBD:

VAR
ReadWriteTerminalReg1: ReadWriteTerminalReg;
State AT% IB0: BYTE;
Control AT% QB0: BYTE;
DataIn AT% IW2: WORD;
DataOut AT% QW2: WORD;
Start_ReadTerminalType: BOOL;
Start_WriteFeatureRegister: BOOL;
RWTerminalReg_Busy: BOOL;
RWTerminalReg_Err: BOOL;
RWTerminalReg_ErrId: UDINT;
TerminalType: WORD;
FeatureRegValue: WORD;
END_VAR

example 1

In example 1, the terminal designation is read from register 8 of an analog output terminal. The variables State, Control, DataIn and DataOut are linked with the corresponding IO variables of the terminal in the TwinCAT System Manager. The terminal designation is: KL4002.

Example 2

In example 2, user scaling is activated in the feature register (register 32) of an analog KL4002 output terminal. The new value of the feature register is then read by the function block and can be accessed via the output variable CURREGVALUE to be checked.

Development environmentTarget platformPLC libraries to be linked
TwinCAT v2.7.0 and higherBCxxxx (165)Standard.Lb6, PlcSystemBC.Lb6, TcPlcUtilitiesBC.Lb6