ModbusRtuSlave_Generic
The function block ModbusRtuSlave_Generic
implements a Modbus slave that communicates via various serial interfaces (COM port, virtual COM port, EtherCAT Terminals, ...).
Due to the hardware-independent nature of ModbusRtuSlave_Generic
, its use is somewhat more complex than that of the hardware-dependent function blocks ModbusRtuSlave_PcCOM, ModbusRtuSlave_KL6x22B, ModbusRtuSlave_ KL6x5B
. All function blocks offer the same ModbusRTU functionality. However, the ModbusRtuSlave_Generic
alone allows the use of virtual COM ports.
The function block is passive until it receives telegrams from a connected Modbus master. A sample program explains the operating principle.
![]() | Connection to hardware via TF6340 TC3 Serial Communication (license required) The data structures required to link to the communication port must be instantiated separately. The data structures of type ComBuffer present at this function block are data buffers for decoupling the hardware-dependent background communication. This background communication must be implemented via corresponding function blocks (SerialLineControl, SerialLineControlADS) of the Tc2_SerialCom PLC library, for which this PLC library must first be integrated in the program. The license for TF6340 TC3 Serial Communication is also required. |
Inputs
VAR_INPUT
UnitID : UINT;
AdrInputs : POINTER TO BYTE; (* Pointer to the Modbus input area *)
SizeInputBytes : UINT;
AdrOutputs : POINTER TO BYTE; (* Pointer to the Modbus output area *)
SizeOutputBytes : UINT;
AdrMemory : POINTER TO BYTE; (* Pointer to the Modbus memory area *)
SizeMemoryBytes : UINT;
END_VAR
Name | Type | Description |
---|---|---|
UnitID | UINT | Modbus station address (1..247). The Modbus slave will only answer if it receives telegrams containing its own station address. Optionally, collective addresses can be used for replying to any requests. Address 0 is reserved for broadcast telegrams and is therefore not a valid station address. |
AdrInputs | BYTE | Start address of the Modbus input area. The data area is usually declared as a PLC array, and the address can be calculated with ADR (input variable). |
SizeInputBytes | UINT | Size of the Modbus input array in bytes. The size can be calculated with SIZEOF (input variable). |
AdrOutputs | BYTE | Start address of the Modbus output area. The data area is usually declared as a PLC array, and the address can be calculated with ADR (output variable). |
SizeOutputBytes | UINT | Size of the Modbus output array in bytes. The size can be calculated with SIZEOF (output variable). |
AdrMemory | BYTE | Start address of the Modbus memory area. The data area is usually declared as a PLC array, and the address can be calculated with ADR (memory variable). |
SizeMemoryBytes | UINT | Size of the Modbus memory array in bytes. The size can be calculated with SIZEOF (memory variable). |
Inputs/outputs
VAR_IN_OUT
RxBuffer : ComBuffer;
TxBuffer : ComBuffer;
END_VAR
Name | Type | Description |
---|---|---|
TxBuffer | Buffer with send data for the serial hardware being used. This data buffer is never directly written or read by the user, but only serves as a buffer for the communication blocks. The background communication must be realized via corresponding function blocks of the Tc2_SerialCom PLC library. | |
RxBuffer | Buffer into which received data is placed. This data buffer is never directly written or read by the user, but only serves as a buffer for the communication blocks. The background communication must be realized via corresponding function blocks of the Tc2_SerialCom PLC library. |
Outputs
VAR_OUTPUT
ErrorId : MODBUS_ERRORS;
END_VAR
Name | Type | Description |
---|---|---|
ErrorId | MODBUS_ERRORS | Indicates an error number in the event of disturbed or faulty communication. |
Requirements
Development environment | Target platform | PLC libraries to include |
---|---|---|
TwinCAT v3.1.4024.0 | PC or CX (x86, x64, ARM) | Tc2_ModbusRTU (>= v3.5.6.0) |