ModbusRtuMaster_KL6x22B

ModbusRtuMaster_KL6x22B 1:

The function block ModbusRtuMaster_KL6x22B implements a Modbus master that communicates via a serial Bus Terminal KL6021 or KL6041. The block is not called in its basic form, but individual actions of that block are used within a PLC program. Each Modbus function is implemented as an action.

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

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

Supported Modbus functions (actions)

VAR_INPUT


VAR_INPUT
    UnitID     : UINT;
    Quantity    : WORD;
    MBAddr     : WORD;
    cbLength    : UINT;
    pMemoryAddr : DWORD;    
    Execute     : BOOL;
    Timeout     : TIME;
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.

Quantity: Number of data words to be read or written for word-oriented Modbus functions. For bit-oriented Modbus functions, Quantity specifies the number of bits (inputs or coils).

MBAddr: Modbus data address, from which the data are read from the end device (slave). This address is transferred to the slave unchanged and interpreted as a data address.
MBAddr holds a subfuntion code when the Diagnostics function is used.

cbLength : Size of the data variable used for send or read actions in bytes. cbLength must be greater than or equal to the transferred data quantity as specified by Quantity. Example for word access: [cbLength >= Quantity * 2]. cbLength can be calculated via SIZEOF (Modbus data).

pMemoryAddr: Memory address in the PLC, calculated with ADR (Modbus data). For read actions, the read data are stored in the addressed variable. For send actions, the data are transferred from the addressed variable to the end device.

Execute : Start signal. The action is initiated via a rising edge at the Execute input.

Timeout : Timeout value for waiting for a response from the addressed slave.

VAR_OUTPUT

VAR_OUTPUT
BUSY : BOOL;
Error : BOOL;
ErrorId : MODBUS_ERRORS;
cbRead : UINT;
END_VAR

Busy: Indicates that the function block is active. Busy becomes TRUE with a rising edge at Execute and becomes FALSE again once the started action is completed. At any one time, only one action can be active.

Error: Indicates that an error occurred during execution of an action.

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

cbRead: Provides the number of read data bytes for a read action

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.

Requirements

Development environment

Target system type

PLC libraries to be linked

TwinCAT from V2.8

PC(i386), CX1000

ModbusRTU.lb (Version 2.2 or higher)

TwinCAT from V2.8

Bus controller BC

ModbusRTU.lb6 (Version 2.2 or higher)