Skip to main content

CODESYS Modbus

A Modbus network consists of a Modbus Client and one or more Modbus Servers. A maximum of 64 servers can be inserted below a client. 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 Client.

  • (2): The CODESYS runtime acts as a Modbus Server. This Modbus Server 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 Modbus Client.

    A Modbus TCP Server can also act as a gateway for serial Modbus Servers.

  • (4): The CODESYS runtime acts as a Modbus 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 client 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 Clients (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.

For more general information about fieldbus support in CODESYS, see: Fieldbus Support