Skip to content

Feature Request: Modbus RTU over TCP (RTU Encapsulation) #55

@cybcon

Description

@cybcon

Summary

Extend the mock server's protocol support to handle Modbus RTU frames encapsulated over TCP connections, in addition to the existing native Modbus TCP implementation.


Motivation

While Modbus TCP is the standard for network-based communication, a significant number of real-world devices — particularly serial-to-Ethernet converters, legacy PLCs, and embedded systems — tunnel Modbus RTU frames directly over TCP without converting them to the native Modbus TCP framing (i.e. without the MBAP header). Testing against such devices requires a mock server that can speak RTU-over-TCP, which is currently not supported. Without this, teams are forced to use real hardware or build custom shims just to run integration tests against these device types.


Technical Background

There are two distinct Modbus-over-TCP variants that are often confused:

Variant MBAP Header CRC Typical Use Case
Modbus TCP ✅ Yes ❌ No Native Ethernet devices
Modbus RTU over TCP ❌ No ✅ Yes Serial-to-Ethernet converters, legacy devices

RTU over TCP uses the raw RTU frame format — including the CRC16 checksum — but transports it over a TCP socket instead of a serial line. No MBAP header is present.


Proposed Implementation

The existing protocol configuration parameter is the natural extension point for this feature:

# Current native Modbus TCP
protocol: tcp

# Proposed new option
protocol: rtu-over-tcp

The server should then expect and respond with raw RTU-framed PDUs over the TCP connection, including correct CRC16 validation and generation.


Use Cases

  • Testing against serial-to-Ethernet gateways or converters that pass through RTU frames unmodified
  • Simulating legacy PLCs and embedded controllers in CI/CD pipelines without physical hardware
  • Validating that a Modbus master correctly handles RTU framing over TCP
  • Supporting industrial IoT scenarios where RTU-over-TCP is the de facto standard for brownfield integrations

Expected Behavior

  • The server accepts incoming TCP connections and parses raw RTU frames (no MBAP header)
  • CRC16 validation is performed on all incoming frames; invalid frames are silently dropped or logged, consistent with RTU behavior
  • Responses are sent as valid RTU frames including a correctly computed CRC16
  • The rtu-over-tcp mode shares the same register space and configuration as the existing tcp mode, requiring minimal migration effort
  • Error handling and logging clearly distinguishes between the two protocol modes

Why This Matters

RTU over TCP is not an edge case — it is a daily reality in industrial environments wherever serial devices have been retrofitted with Ethernet connectivity. Adding this mode with a single protocol parameter change would make the mock server meaningfully more useful for brownfield testing scenarios, with relatively low implementation overhead given that RTU framing logic is well-defined and self-contained.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions