Modbus

As part of the Edge Xpert distribution, IOTech provides a Modbus Device Service. This allows Edge Xpert to read data from Modbus devices and to issue commands.

The Modbus Device Service provides a means of integrating Modbus devices with Edge Xpert. For more information, refer to the Modbus website.

The Edge Xpert Modbus Device Service can be used to communicate with devices that use either a serial port protocol or an Ethernet protocol that supports the Internet protocol suite, as follows:

  • Modbus RTU

    This is used in serial communication and uses a compact, binary representation of the data for protocol communication.

  • Modbus TCP/IP or Modbus TCP

    This is a Modbus variant used for communications over TCP/IP networks, connecting over port 1502.

The Edge Xpert Modbus Device Service is based on goburrow modbus, a fault-tolerant, fail-fast implementation of the Modbus protocol in Go.

The Modbus Device Service supports the following key features:

  • Read. Data can be read from each primary table, as follows:

    Supported Read Modbus Functions
    Primary Table Modbus Function
    Coils 1
    Discrete inputs 2
    Holding registers 3
    Input registers 4
  • Write. Data can be written to each writable primary table, as follows

    Supported Write Modbus Functions
    Primary Table Modbus Function
    Coils 15
    Holding registers 16
  • Support for Parsing Int32 and Uint32 data types with byte swap and word swap

  • Support for Modbus RTU and TCP connection types

  • Batch read operation. Read multiple values in a single Modbus call from each primary table, as described in the Supported Read Modbus Functions table above

  • Batch write operation. Write multiple values in a single Modbus call to each writable primary table, as described in the Supported Write Modbus Functions table above

The Modbus Device Service supports the following data types:

  • Boolean
  • UInt16, UInt32, UInt64
  • Int16, Int32, Int64
  • Float32
  • Float64

Modbus Attributes

The device profile defines what resources are available on a particular device. Ensure that the following profile attributes are defined in the YAML file:

Required Profile Attributes
Attribute Description
primaryTable HOLDING_REGISTERS, INPUT_REGISTERS, COILS, DISCRETES_INPUT
startingAddress The address in the Modbus device

The Property value type decides how many registers will be read. Like Holding registers, a register has 16 bits. If the device manual specifies that a value has two registers, define it as FLOAT32 or INT32 or UINT32 in the device profile.

Once we execute a command, device-modbus knows its value type and register type, startingAddress, and register length. So it can read or write a value using the Modbus protocol.

Modbus Examples

These examples use a Modbus Simulator, called ModbusPal; this is the recommended version. The simulator must be configured for the examples, as described in the following topic:

All examples assume that the Edge Xpert services have been started with at least the --xpert-manager and --device-modbus parameters. A suitable start-up command would be as follows:

edgexpert up --xpert-manager --device-modbus