Skip to content

Modbus Device Service

The Modbus Device Service provides a means of integrating Modbus devices with Edge Xpert. For further 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 Remote Terminal Unit (Modbus RTU). Used in serial communication and uses a compact, binary representation of the data for protocol automation

  • Modbus Transmission Control Protocol/Internet Protocol (Modbus TCP). A Modbus variant, which is used for communications over TCP/IP networks and connecting over port 502 by default

Key Features

The Modbus Device Service supports the following key features:

  • Support for Modbus RTU connection types
  • Support for Modbus TCP/IP connection types
  • Read functionality. Data can be read from each primary table, as follows:

    Modbus Object Function Name Function Code
    Coils Read Coils 1
    Discrete Inputs Read Discrete Inputs 2
    Holding Registers Read Multiple Holding Registers 3
    Input Registers Read Input Registers 4

  • Write functionality. Data can be written to each primary table, as follows:

    Modbus Object Function Name Function Code
    Coils Write Multiple Coils 15
    Holding Registers Write Multiple Holding Registers 16

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

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

  • Support for parsing Int64, UInt64, Float32, and Float64 data types with byte swap and word swap functionality. See Modbus Swap Operations for more information

Supported Data Types

The Modbus Device Service supports the following data types:

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

Modbus Device Profile

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

Attribute Description
primaryTable Identifies the primary table. The primary table must be one of the following:
  • HOLDING_REGISTERS
  • INPUT_REGISTERS
  • COILS
  • DISCRETE_INPUT
startingAddress The address in the Modbus device

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

Once we run a command, device-modbus knows its value type and register type, starting address, and register length. With this information, it can read or write a value using the Modbus protocol.

Optional Attributes

The Modbus Device Service also allows you to define optional attributes. The following optional profile attributes can be defined in the device profile:

Attribute Description
rawtype Defines the binary data read from the Modbus device and uses a value descriptor data type to identify the data type that the user wants to receive
isByteSwap Defines whether to swap the byte on reading little-endian data to transform to big-endian format.
The Modbus Device Service uses big-endian format.
If the Modbus device uses little-endian format, set this attribute to true to correctly convert the data.
isWordSwap Defines whether to use 16-bit segments, also known as words, to re-order the byte sequence with big-endian or little-endian formats
To re-order the byte sequence, set this attribute to true
boolIndex Retrieves the bool value from the specified bit of a register
The default is 0
For HOLDING_REGISTER and INPUT_REGISTERS, the valid range is 0 to 15, inclusive
For COILS and DISCRETE_INPUT, the value is 0
stringEncoding The supported string encoding
Valid values are UTF8 or ASCII
Default is UTF8
stringRegisterSize Defines the capacity of the device resource for String data
Valid range is from 1 to 123, inclusive
Default is 1
For example, to store the "Hello World" string in ASCII encoding, we need 96 bits (12 characters multiplied by 8 bits), so the required stringRegisterSize would be 6 (96 bits divided by 16 bits)
For the read command, the Modbus device reads the data types from the specified startingAddress for the length specified in the stringRegisterSize and parses the binary data to a String with the encoding specified in stringEncoding
For the write command, the Modbus device checks that the parameter is a valid string in the specified encoding, converts the string to data bytes and writes it back to the register

Modbus Protocol Properties

The available Modbus protocol properties are described in the following table:

Protocol Property Description Valid Values
UnitID The station identifier Values up to 247
Address For Modbus TCP/IP, the IP address or host name
For Modbus RTU, the path to the serial device
Port Used for Modbus TCP/IP only
The TCP port of the Modbus device
BaudRate Used for Modbus RTU only
The baud rate for a serial device
The provided baud rate must match for devices using the same address
Unsigned integer
DataBits Used for Modbus RTU only
The number of bits of data
Valid values are as follows:
  • 5
  • 6
  • 7
  • 8
StopBits Used for Modbus RTU only
The number of stop bits
Valid values are as follows:
  • 1
  • 2
Parity Used for Modbus RTU only
The parity value
Specify N for no parity
Specify E for even parity
Specify O for odd parity
Valid values are as follows:
  • N
  • E
  • O

Using the Modbus Device Service

Examples of setting up and using devices with the Edge Xpert Modbus Device Service can be found at Modbus TCP/IP Example and Modbus RTU Example. These examples use a simulated device, see Modbus Simulator for more information.

Back to top