ModbusRtuMasterV2_KL6x5B

ModbusRtuMasterV2_KL6x5B 1:

The function block ModbusRtuMasterV2_KL6x5B realizes a Modbus master, which communicates via a serial Bus Terminal KL6001, KL6011 or KL6021. The function block ModbusRtuMasterV2_PcCOM is available for communication via a serial PC interface (COM port).

ModbusRtuMasterV2_KL6x5B 2:

Hardware connection

The data structures required for the link with the communication port are included in the function block. On a PC, the assignment in the TwinCAT System Manager is analogous to the description in the chapter Serial bus terminal of the TF6340 TC3 Serial Communication documentation.

The function 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.

Supported Modbus functions (actions)

Supported Modbus functions (actions) of the MasterV2 function blocks

ModbusRtuMasterV2_KL6x5B 3: Inputs

VAR_INPUT
    UnitID      : BYTE;
    Quantity    : WORD;
    MBAddr      : WORD;
    cbLength    : UINT;
    pMemoryAddr : POINTER TO BYTE;

    AuxQuantity    : WORD;
    AuxMBAddr      : WORD;
    AuxcbLength    : UINT;
    pAuxMemoryAddr : POINTER TO BYTE;

    Execute     : BOOL;
    Timeout     : TIME;
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 (see UnitID)

Quantity

WORD

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

WORD

Modbus data address, from which the data are read from the end device (slave). This address is transferred unchanged to the slave and is interpreted there as data address.
With the Diagnostics function (8) the function code (subfunction code) is transferred here.

cbLength

UINT

Size of the data variable used for send or read actions in bytes. cbLength must be greater than or equal to the amount of data transferred as determined by Quantity. For word accesses, for example: [cbLength >= Quantity * 2]. cbLength can be calculated with SIZEOF(Modbus data).

pMemoryAddr

BYTE

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.

AuxQuantity

WORD

Additional parameter which is only used for read/write functions, see ReadWriteRegs/UserReadWrite

AuxMBAddr

WORD

Additional parameter which is only used for read/write functions, see ReadWriteRegs/UserReadWrite.

AuxcbLength

UINT

Additional parameter which is only used for read/write functions, see ReadWriteRegs/UserReadWrite

pAuxMemoryAddr

BYTE

Additional parameter which is only used for read/write functions, see ReadWriteRegs/UserReadWrite

Execute

BOOL

Start signal. The action is triggered by a rising edge at the Execute input.

Timeout

TIME

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

ModbusRtuMasterV2_KL6x5B 4: Outputs

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

Name

Type

Description

Busy

BOOL

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

BOOL

Indicates that an error occurred during execution of an action.

ErrorId

MODBUS_ERRORS

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

cbRead

UINT

Provides the number of read data bytes for a read action.

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.0

PC or CX (x86, x64, ARM)

Tc2_ModbusRTU