ModbusRtuMasterV2_Generic

ModbusRtuMasterV2_Generic 1:

The function block ModbusRtuMasterV2_Generic implements a Modbus master that communicates via various serial interfaces (COM port, virtual COM port, EtherCAT Terminals, ...).

Due to the hardware-independent nature of ModbusRtuMasterV2_Generic, its use is somewhat more complex than that of the hardware-dependent function blocks ModbusRtuMasterV2_PcCOM, ModbusRtuMasterV2_KL6x22B, ModbusRtuMasterV2_ KL6x5B. All function blocks offer the same ModbusRTU functionality. However, the ModbusRtuMasterV2_Generic alone allows the use of virtual COM ports.

ModbusRtuMasterV2_Generic 2:

Connection to hardware via TF6340 TC3 Serial Communication (license required)

The data structures required to link to the communication port must be instantiated separately. The data structures of type ComBuffer present at this function block are data buffers for decoupling the hardware-dependent background communication. This background communication must be implemented via corresponding function blocks (SerialLineControl, SerialLineControlADS) of the Tc2_SerialCom PLC library, for which this PLC library must first be integrated in the program. The license for TF6340 TC3 Serial Communication is also required.

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_Generic 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_Generic 4: Inputs/outputs

VAR_IN_OUT
    RxBuffer    : ComBuffer;
    TxBuffer    : ComBuffer;
END_VAR

Name

Type

Description

TxBuffer

ComBuffer (Tc2_SerialCom PLC library)

Buffer with send data for the serial hardware being used. This data buffer is never directly written or read by the user, but only serves as a buffer for the communication blocks. The background communication must be realized via corresponding function blocks of the Tc2_SerialCom PLC library.

RxBuffer

ComBuffer (Tc2_SerialCom PLC library)

Buffer into which received data is placed. This data buffer is never directly written or read by the user, but only serves as a buffer for the communication blocks. The background communication must be realized via corresponding function blocks of the Tc2_SerialCom PLC library.

ModbusRtuMasterV2_Generic 5: 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.4024.0

PC or CX (x86, x64, ARM)

Tc2_ModbusRTU (>= v3.5.6.0)