Modbus Tutorial.

Compared to other field buses, Modbus is a simple alternative for exchanging data. Modbus is an open protocol. It is based on master-slave communication. As a principle, every participant in the network may transmit data. In practice, however, communication is always initiated by the master.

Types of Transfer (selection)

  • Modbus RTU
    • Serial communication
    • Binary data transfer
    • RTU stands for Remote Terminal Unit
  • Modbus TCP
    • Extended Modbus RTU for TCP/IP networks

Modbus Master

  • Requests data from Modbus slaves
  • Acts as a client, as it does not make data available

Modbus Slave

  • Makes data available
  • Acts as the server, as it makes data available

Modbus Register

Attention: Depending on the device, the registration addresses with 1 or 0.

  • A maximum of216 registers can be addressed, i.e. 65536
  • Enables access to data
  • Access is via a register address and Modbus function and service respectively
  • Are specific to each device

Functions or Services

  • Implements access to data
  • Distinguishes
    • Reading/writing/both
  • Data width
    • Data word (2 bytes)
    • Bit
  • The implemented functions depend on the device.

Request Data

  • Configure the data connection of the Modbus Master and Modbus Slave
    • Modbus TCP – network configuration (static IP addresses, netmask)
    • Modbus RTU – serial interface (baud rate, data bits, parity, stop bits)
  • The corresponding function has to be selected on Modbus master to the one that the slave makes available.
    • Modbus RTU Slave ID:
      between 1 and 247 (0 stands for broadcast)
    • Modbus TCP Unit ID:
      It has the same functionality as the slave ID. However, there is the 255. In practice, which value has to be set depends on the connected device. Either a Modbus TCP slave is uniquely identified in the network by its IP address. Or, if this slave is a gateway from Modbus TCP to Modbus RTU, it can address several Modbus RTU slaves. The unit ID 255 is recommended to address the gateway itself.
    • Modbus register
      The kind of register is specific to the device. The registers are counted either from 0 or from 1.
    • Modbus function, e.g. READ_HOLDING_REGISTER

Example of information required for Modbus RTU

  • Serial interface parameters, e.g. 9600 baud, 8 data bits, 1 stop bit, no parity
  • Slave address, e.g. 1
  • Modbus register, e.g. 1000
  • Modbus function, e.g. READ_INPUT_REGISTER

Example of information required for Modbus TCP

  • Slave IP address, e.g. 192.168.0.103
  • Unit ID, e.g. 255
  • Slave register, e.g. 1000
  • Modbus function, e.g. READ_HOLDING_REGISTER

Modbus in RevPi

The following virtual devices are available on the RevPi and can be configured via PiCtory:

  • ModbusRTU Master
    • Application: the RevPi requests data from another Modbus device.
  • ModbusRTU Slave
    • Application: the RevPi makes data available that can be requested by a master.
  • ModbusTCP Master
    • Application: the RevPi requests data from another Modbus device.
  • ModbusTCP Slave
    • Application: the RevPi makes data available that can be requested by a master.

A maximum of 32 registers per virtual device can be used for input and output data. If you need more, you can simply configure multiple virtual Modbus devices. You can configure a total of 30 virtual devices.

With the image stretch, the following virtual Modbus devices are available. With these modules you can configure more data:

  • ModbusRTU Master
    • 150 words
  • ModbusRTU Slave
    • 512 words
  • ModbusTCP Master
    • 150 words
  • ModbusTCP Slave
    • 512 words