Infosys在阅读器中打开 / AI 翻译

TF6xxx - Connectivity · 0 次阅读

ModbusRtuMaster_PcCOM

ModbusRtuMaster_PcCOM 1:

The function block ModbusRtuMaster_PcCOM implements a Modbus master that communicates via a serial PC interface (COM port). The function block ModbusRtuMaster_KL6x5B is available for communication via a serial Bus Terminal KL6001, KL6011 or KL6021.

ModbusRtuMaster_PcCOM 2:

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 analogous to the description in the chapter Serial PC Interface of the TF6340 TwinCAT 3 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)

  • ModbusMaster.ReadCoils
    Modbus function 1 = Read Coils
  • Reads binary outputs (coils) from a connected slave. The data is stored in compressed form (8 bits per byte) from the specified address pMemoryAddr.
  • ModbusMaster.ReadInputStatus
    Modbus function 2 = Read Input Status
  • Reads binary inputs from a connected slave. The data is stored in compressed form (8 bits per byte) from the specified address pMemoryAddr.
  • ModbusMaster.ReadRegs
    Modbus function 3 = Read Holding Registers
  • Reads data from a connected slave.
  • ModbusMaster.ReadInputRegs
    Modbus function 4 = Read Input Registers
  • Reads input registers from a connected slave.
  • ModbusMaster.WriteSingleCoil
    Modbus function 5 = Write Single Coil
  • Sends a binary output (coil) to a connected slave. The data must be ready to send in compressed form (8 bits per byte) from the specified address pMemoryAddr.
  • ModbusMaster.WriteSingleRegister
    Modbus function 6 = Write Single Register
  • Sends a single data word to a connected slave
  • ModbusMaster.WriteMultipleCoils
    Modbus function 15 = Write Multiple Coils
  • Sends binary outputs (coils) to a connected slave. The data must be ready to send in compressed form (8 bits per byte) from the specified address pMemoryAddr.
  • ModbusMaster.WriteRegs
    Modbus function 16 = Preset Multiple Registers
  • Sends data to a connected slave
  • ModbusMaster.Diagnostics
    Modbus function 8 = Diagnostics
  • Sends a diagnostic request to the slave with a user-specified function code (subfunction code). Since this function does not address a memory, the function code is transferred in the data word MBAddr. Any data required for the function is included in pMemoryAddr.

ModbusRtuMaster_PcCOM 3: Inputs

VAR_INPUT
    UnitID      : UINT;
    Quantity    : WORD;
    MBAddr      : WORD;
    cbLength    : UINT;
    pMemoryAddr : 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.

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.

ModbusRtuMaster_PcCOM 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