ModbusRtuSlave_PcCom

ModbusRtuSlave_PcCom 1:

The function block ModbusRTUslave_PcCom implements a Modbus slave that communicates via a serial PC interface (COM port). The block is passive until it receives telegrams from a connected Modbus master.

An example program explains the operating principle.

The function block ModbusRTUslave_KL6x5B is available for communication via a serial Bus Terminal KL6001, KL6011 or KL6021.

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

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. 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 as described in Chapter Serial PC Interface.

Requirements

Development environment

Target system type

PLC libraries to be linked

TwinCAT from V2.8

PC (i386), CX1000

ModbusRTU.lib