Skip to main content

Modbus Serial Overview

The MODBUS_SERIAL route enables communication with industrial devices using Modbus RTU protocol over serial connections (RS-232 or RS-485). It supports the same TAG-based configuration as Modbus TCP but adds serial-specific parameters for baud rate, parity, and data bits.
Modbus Serial (RTU) is commonly used for legacy equipment, long-distance communication, and multi-drop RS-485 networks where multiple devices share a single bus.

Basic Syntax

DEFINE ROUTE SerialDevice WITH TYPE MODBUS_SERIAL
    ADD MODBUS_CONFIG
        WITH CONNECTION_TYPE "SERIAL"
        WITH COM_PORT "COM1"
        WITH BAUD_RATE '9600'
        WITH PARITY "NONE"
        WITH DATA_BITS '8'
        WITH STOP_BITS "ONE"
        WITH SLAVE_ID '1'
    ADD MAPPING SensorReadings
        WITH EVERY 1 SECOND
        ADD TAG Temperature
            WITH ADDRESS "100"
            WITH ADDRESS_TYPE "HOLDING_REGISTER"
            WITH DATA_TYPE "FLOAT"
            WITH SOURCE_TOPIC "serial/temperature"

Serial Configuration

MODBUS_CONFIG Parameters

CONNECTION_TYPE
string
required
Must be set to SERIAL for serial communication.
COM_PORT
string
required
Serial port name. Windows: COM1, COM2, etc. Linux: /dev/ttyUSB0, /dev/ttyS0, etc.
BAUD_RATE
integer
required
Communication speed in bits per second. Common values: 9600, 19200, 38400, 57600, 115200.
PARITY
string
Parity checking: NONE, ODD, EVEN, MARK, or SPACE. Default: NONE.
DATA_BITS
integer
Number of data bits per character: 7 or 8. Default: 8.
STOP_BITS
string
Number of stop bits: ONE, TWO, or ONEPOINTFIVE. Default: ONE.
SLAVE_ID
integer
required
Modbus slave/unit ID (1-247). Each device on the bus must have a unique ID.
READ_TIMEOUT
integer
Read operation timeout in milliseconds. Default: 1000.
WRITE_TIMEOUT
integer
Write operation timeout in milliseconds. Default: 1000.
RETRY_COUNT
integer
Number of retry attempts on failure. Default: 3.
RETRY_DELAY
integer
Delay between retries in milliseconds. Default: 100.

Common Serial Settings

Different devices use different serial settings. Here are common configurations:
ADD MODBUS_CONFIG
    WITH CONNECTION_TYPE "SERIAL"
    WITH COM_PORT "COM1"
    WITH BAUD_RATE '9600'
    WITH PARITY "NONE"
    WITH DATA_BITS '8'
    WITH STOP_BITS "ONE"
    WITH SLAVE_ID '1'
Settings: 9600 8N1 (9600 baud, 8 data bits, No parity, 1 stop bit)

RS-485 Multi-Drop Networks

RS-485 allows multiple devices on a single bus. Each device must have a unique slave ID:

Multi-Device Configuration

Create separate routes or use different slave IDs:
DEFINE ROUTE TemperatureController WITH TYPE MODBUS_SERIAL
    ADD MODBUS_CONFIG
        WITH CONNECTION_TYPE "SERIAL"
        WITH COM_PORT "COM1"
        WITH BAUD_RATE '9600'
        WITH SLAVE_ID '1'
    ADD MAPPING TempController
        WITH EVERY 1 SECOND
        ADD TAG Temperature
            WITH ADDRESS "0"
            WITH ADDRESS_TYPE "HOLDING_REGISTER"
            WITH DATA_TYPE "FLOAT"
            WITH SOURCE_TOPIC "modbus/device1/temperature"

DEFINE ROUTE FlowMeter WITH TYPE MODBUS_SERIAL
    ADD MODBUS_CONFIG
        WITH CONNECTION_TYPE "SERIAL"
        WITH COM_PORT "COM1"
        WITH BAUD_RATE '9600'
        WITH SLAVE_ID '2'
    ADD MAPPING FlowMeter
        WITH EVERY 1 SECOND
        ADD TAG FlowRate
            WITH ADDRESS "0"
            WITH ADDRESS_TYPE "INPUT_REGISTER"
            WITH DATA_TYPE "FLOAT"
            WITH SOURCE_TOPIC "modbus/device2/flow"
When sharing a serial port between multiple slave IDs, ensure polling intervals are set to avoid bus collisions. The route handles sequencing automatically, but very fast polling across many devices may cause timeouts.

TAG Configuration

The TAG configuration for Modbus Serial is identical to Modbus TCP. See the Modbus TCP documentation for complete TAG parameter reference.

Quick Reference

ADD TAG SensorValue
    WITH ADDRESS "100"
    WITH ADDRESS_TYPE "HOLDING_REGISTER"
    WITH DATA_TYPE "FLOAT"
    WITH SOURCE_TOPIC "serial/sensor"
    WITH SCALING "0.1"
    WITH OFFSET "0"
    WITH UNIT "°C"
    WITH DEADBAND "0.5"
    WITH PUBLISH_MODE "JSON"
    WITH WRITABLE "true"
    WITH DESTINATION_TOPIC "serial/sensor/set"
    WITH BYTE_ORDER "BIGENDIAN"
    WITH WORD_ORDER "BIGENDIAN"

Complete Examples

Basic connection to a single Modbus RTU device:
DEFINE ROUTE EnergyMeter WITH TYPE MODBUS_SERIAL
    ADD MODBUS_CONFIG
        WITH CONNECTION_TYPE "SERIAL"
        WITH COM_PORT "COM3"
        WITH BAUD_RATE '9600'
        WITH PARITY "EVEN"
        WITH DATA_BITS '8'
        WITH STOP_BITS "ONE"
        WITH SLAVE_ID '1'
        WITH READ_TIMEOUT '1000'
        WITH RETRY_COUNT '3'
    ADD MAPPING Readings
        WITH EVERY 1 SECOND
        ADD TAG Voltage
            WITH ADDRESS "0"
            WITH ADDRESS_TYPE "INPUT_REGISTER"
            WITH DATA_TYPE "FLOAT"
            WITH SOURCE_TOPIC "meter/voltage"
            WITH UNIT "V"
        ADD TAG Current
            WITH ADDRESS "2"
            WITH ADDRESS_TYPE "INPUT_REGISTER"
            WITH DATA_TYPE "FLOAT"
            WITH SOURCE_TOPIC "meter/current"
            WITH UNIT "A"
        ADD TAG Power
            WITH ADDRESS "4"
            WITH ADDRESS_TYPE "INPUT_REGISTER"
            WITH DATA_TYPE "FLOAT"
            WITH SOURCE_TOPIC "meter/power"
            WITH UNIT "kW"

Troubleshooting

  • Verify COM port is correct and not in use by another application
  • Check physical wiring (TX/RX, A/B for RS-485)
  • Ensure baud rate matches device settings
  • Verify slave ID is correct
  • Check device power and status indicators
  • CRC errors indicate data corruption
  • Check cable quality and length
  • For RS-485, ensure proper termination resistors (120Ω at each end)
  • Reduce baud rate for long cable runs
  • Check for electrical interference
  • Increase READ_TIMEOUT value
  • Verify serial settings match device exactly
  • Check for bus conflicts (multiple masters)
  • For RS-485, ensure proper biasing
  • Verify register addresses in device documentation
  • Check BYTE_ORDER and WORD_ORDER settings
  • Confirm DATA_TYPE matches register size
  • Some devices use 1-based addressing (subtract 1 from documented address)
  • Windows: Check Device Manager for correct COM port number
  • Linux: Check /dev/tty* with ls -l /dev/tty*
  • Ensure USB-to-serial driver is installed
  • Verify user has permissions to access serial port

RS-485 Wiring Tips

Proper wiring is critical for reliable RS-485 communication.
WireFunctionDescription
A (D-)Data -Negative data line
B (D+)Data +Positive data line
GNDGroundSignal ground reference
Best Practices:
  • Use twisted pair cable for A and B lines
  • Add 120Ω termination resistors at both ends of the bus
  • Keep cable length under 1200m (4000ft)
  • Use bias resistors if experiencing idle-line issues
  • Ensure all grounds are connected

Next Steps