ModbusRtuSlave_KL6x22B

ModbusRtuSlave_KL6x22B 1:

The function block ModbusRtuSlave_KL6x22B implements a Modbus slave that communicates via a serial Bus Terminal KL6031 or KL6041. The block is passive until it receives telegrams from a connected Modbus master.

An example program for PC or CX1000 or for a BC bus controller explains the operating principle.

The function block ModbusRTUslave_PcCom is available for communication via a serial PC Interface (COM port).

VAR_INPUT


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

UnitID : 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: Start address of the Modbus input array. The data array is usually declared as a PLC array, and the address can be calculated with ADR (input variable).

SizeInputBytes: Size of the Modbus input array in bytes. The size can be calculated with SIZEOF (input variable).

AdrOutputs : Start address of the Modbus output array. The data array is usually declared as a PLC array, and the address can be calculated with ADR (output variable).

SizeOutputBytes: Size of the Modbus output array in bytes. The size can be calculated with SIZEOF (output variable.

AdrMemory : Start address of the Modbus memory array. The data array is usually declared as a PLC array, and the address can be calculated with ADR (memory variable).

SizeMemoryBytes : Size of the Modbus memory array in bytes. The size can be calculated with SIZEOF (memory variable).

VAR_OUTPUT


VAR_OUTPUT
    ErrorId : Modbus_ERRORS;
END_VAR

ErrorId: Indicates an error number in the event of disturbed or faulty communication.

Hardware connection

The data structures required for the link with the communication port are included in the function block. The allocation in the TwinCAT System Manager on a PC is carried out according to the description in Chapter Serial Bus Terminal. On a BC bus controller, the I/O addresses have to be assigned manually. See Hardware assignment at the BC bus controller.

Development environment

Target system type

PLC libraries to be linked

TwinCAT from V2.8

PC (i386), CX1000,

ModbusRTU.lib (Version 2.0 or higher)

TwinCAT from V2.8

Bus controller BC

ModbusRTU.lb6 (Version 2.0 or higher)