ModbusRtuSlave_PcCOM
The function block ModbusRtuSlave_PcCOM
implements a Modbus slave that communicates via a serial PC interface (COM port). The function block ModbusRtuSlave_KL6x5B is available for communication via a serial Bus Terminal KL6001, KL6011 or KL6021.
The function block is passive until it receives telegrams from a connected Modbus master. A sample program explains the operating principle.
![]() | Hardware connection The data structures required for the link with the communication port are included in the function block. They are displayed in the TwinCAT System Manager once the PLC program has been integrated and can be connected with a COM port. The procedure is analogous to the description in the chapter Serial PC Interface of the TF6340 TC3 Serial Communication documentation. |
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). |
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.0 | PC or CX (x86, x64, ARM) | Tc2_ModbusRTU |