ReadWriteTerminalReg
The function block ReadWriteTerminalReg enables convenient access to the terminal's registers via the control/status byte of the terminal channel (register communication). In the standard operation mode, the data inputs and outputs of the intelligent terminals (e.g. an analog output terminal) are used to exchange the analog output data. A handshake via the control/status byte permits register access. The data input and output variables are used here to transfer the register values. 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. With a write access to a register, the new register value is written first and then read. The value read is available at the output CURRREGVALUE. If changes made to the register values are to be stored permanently, the power supply to the coupler must be interrupted. The variables STATE, DATAIN, CTRL and DATAOUT must be linked in the TwinCAT System Manager to the corresponding I/O variables in the terminal channel.
Inputs
VAR_INPUT
STATE : BYTE;
DATAIN : WORD;
REGNO : BYTE;
READ : BOOL;
WRITE : BOOL;
TMOUT : TIME;
NEWREGVALUE : WORD;
END_VAR
Name | Type | Description |
---|---|---|
STATE | BYTE | Status byte of the terminal channel. |
DATAIN | WORD | Data input word of the terminal channel. |
REGNO | BYTE | Number of the register to read or write. |
READ | BOOL | A positive edge at this input activates the function block, and the current register value is read. If successful, the register value is available in the output variable CURREGVALUE. |
WRITE | BOOL | A positive edge at this input activates the function block, and the value in the input variable NEWREGVALUE is written into the register REGNO. The current value of the register is then read and, if successful, is available in the output variable CURREGVALUE. |
TMOUT | TIME | Specifies the time-out period that must not be exceeded when the function is executed. |
NEWREGVALUE | WORD | Data word to be written to the register numbered REGNO during a write access. |
Outputs
VAR_OUTPUT
CTRL : BYTE;
DATAOUT : WORD;
BUSY : BOOL;
ERR : BOOL;
ERRID : UDINT;
CURREGVALUE : WORD;
END_VAR
Name | Type | Description |
---|---|---|
CTRL | BYTE | Control byte of the terminal channel. |
DATAOUT | WORD | Data output word of the terminal channel. |
BUSY | BOOL | When the function block is activated, this output is set and remains set until the function is completed. |
ERR | BOOL | If an error occurs during the execution of the function, this output is set after the BUSY output is reset. |
ERRID | UDINT | If the ERR output is set, this parameter supplies the error number. |
Error number | Error description |
---|---|
0 | No error |
0x100 | Timeout error. The permitted execution time has been exceeded |
0x200 | Parameter error (e.g. an invalid register number) |
0x300 | The value read differs from the value written (write access to this register may not be permitted or may have failed) |
Name | Type | Description |
---|---|---|
CURREGVALUE
| WORD | This variable provides the current register value after a successful read or write access. |
Examples of calls in FBD:
Example 1
VAR
ReadWriteTerminalReg1 : ReadWriteTerminalReg;
State AT%I* : BYTE;
Control AT%Q* : BYTE;
DataIn AT%I* : WORD;
DataOut AT%Q* : WORD;
Start_ReadTerminalType : BOOL;
Start_WriteFeatureRegister : BOOL;
RWTerminalReg_Busy : BOOL;
RWTerminalReg_Err : BOOL;
RWTerminalReg_ErrId : UDINT;
TerminalType : WORD;
FeatureRegValue : WORD;
END_VAR
In Example 1 the terminal identifier 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 identifier is KL4022..
Example 2
In Example 2 the user-scaling is activated in the feature register (register 32) of a KL4022 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 system type |
PLC libraries to include (category group) |
---|---|---|
TwinCAT v3.1.0 |
PC or CX (x86, x64, ARM) |
Tc2_Coupler (IO) |