ReadWriteTerminalReg

ReadWriteTerminalReg 1:

The "ReadWriteTerminalReg" function block permits convenient access to the registers of the terminal via the terminal channel's status/control byte (register communication). In the standard operating mode, the data inputs and outputs of the intelligent terminal (e.g. an analog output terminal) are used to exchange the analog output data. A handshake via the status/control byte permits register access. The data input and output variables are used here 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 not visible to the bus controller). 
A positive edge at the READ or WRITE input causes the register with number REGNO to be read or written to. Write protection of the register is disabled by the function block for a write access and enabled once more afterwards. When a register is written to, the new register value is read, and is available at the CURRREGVALUE output. If changes made to the register values are to be stored permanently, the power supply to the coupler must be interrupted or a software reset of the coupler must be executed. 

 

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 a read or write access is to be made.
READ: a positive edge at this input activates the function block and reads the current register value. If successful, the register value is available in the output variable CURRREGVALUE.
WRITE: a positive edge at this input activates the function block, and the value in the input variable NEWREGVALUE is written into the register REGNO. Subsequently, the current value of the register is read and is available in the output variable CURREGVALUE if successful.
TMOUT: specifies the timeout time that must not be exceeded when executing the function.
NEWREGVALUE: data word that is to be written to 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 during the execution of the function, then this output is set after the BUSY output has been reset.
ERRID: returns the error number when the ERR output is set.
CURREGVALUE: in case of a successful read or write access, the current register value is output via the variable.

 

Error description:

Error number

Error description

0

No error

0x100

Timeout error. The time permitted for execution has been exceeded.

0x200

Parameter error (e.g. an invalid register number). 

0x300

The read value differs from the written value (write access to this register may not be enabled or have failed) 

 

Samples of 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

 

 Sample 1

ReadWriteTerminalReg 2:

In Sample 1 the terminal name is read from register 8 of an analog output terminal. The variables State, Control, DataIn and DataOut are linked to the terminal's corresponding I/O variables in the TwinCAT System Manager. The terminal name is KL4002.

 

Sample 2

ReadWriteTerminalReg 3:

In Sample 2 the user-scaling is activated in the feature register (register 32) of a KL4002 analog output terminal. The new value in the feature register is then read by the function block, and can be checked through the output variable CURREGVALUE.

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v2.7.0 and above

BCxxxx (165)

Standard.Lb6, PlcSystemBC.Lb6, TcPlcUtilitiesBC.Lb6