Search

General

A Modbus network consists of a Modbus master and one or more Modbus slaves. A maximum of 64 slaves can be attached to a master. The Modbus devices can be linked via serial port or Ethernet.

_mod_img_device_tree.png

Modbus devices, linked via the serial port using the Modbus COM Port device.

  • (1): The CODESYS runtime acts as a Modbus Master.

  • (2): The CODESYS runtime acts as a Modbus Slave. This Modbus Slave is named "Modbus Device" in the following text.

    For Modbus serial, the operating type "Modbus RTU" is supported.

Modbus devices, linked in an Ethernet network using the Ethernet Adapter device.

  • (3): The CODESYS runtime acts as a Modus Master (Client).

    A Modbus TCP slave can also act as a gateway for serial Modbus slaves.

  • (4): The CODESYS runtime acts as a Modbus Slave (Server).

You can configure communication parameters in the Modbus configuration pages and then create Modbus channels. A Modbus channel includes a single Modbus command (read/write data) as well as the respective I/O channels.

Supported function codes

If there are no specific PLC restrictions, then the master generally supports the following function codes:

  • FC01 Read Coils

  • FC02 Read Discrete Inputs

  • FC03 Read Holding Registers

  • FC04 Read Input Registers

  • FC05 Write Single Coil

  • FC15 Write Multiple Coils

  • FC06 Write Single Register

  • FC16 Write Multiple Registers

  • FC23 Read/Write Multiple Registers

Access to Modbus devices from the application

If you insert a Modbus device in the device tree, then an instance of the respective function block is created automatically. The variable name of the instance corresponds to the name of the device in the device tree. Using this function block, you can access the functions of the Modbus devices from the application. For example, via the outputs of this function block, you can query the status of the last Modbus command (whether successful or not).

You will find the device instance in the <device name> IEC Objects tab of the corresponding device editor. Refer also to the description of this dialog.

Tip

For Modbus masters (RTU/TCP)

In addition to the Modbus commands defined in the configurator (and the implicitly generated I/O mapping), programmed Modbus requests can also be executed using the block ModbusRequest.