Modbus Server Engineering

Modbus Server Simulator: Test Modbus TCP & RTU Servers Without Physical Hardware

Developing automation systems, SCADA supervisory dashboards, and industrial IoT data pipelines requires rigorous end-to-end communication testing long before plant hardware arrives on-site. When physical PLCs, RTUs, power meters, and variable frequency drives (VFDs) are unavailable, a reliable Modbus Server Simulator bridges the gap. By standing up virtual Modbus TCP servers on port 502 and emulating serial RTU slaves across virtual COM ports, control engineers can validate register maps, test multi-client connection scaling, and simulate dynamic process variables from their workstation.

1. Modbus Terminology: Server vs. Client, Slave vs. Master

In modern industrial Ethernet protocols, standard terminology can occasionally cause confusion for engineers transitioning from serial communication to TCP/IP. The official Modbus Application Protocol Specification explicitly correlates the terminology:

Architecture Aspect Modbus Server (Slave) Modbus Client (Master)
Network Role Listens passively (TCP Port 502 or Serial COM RX) Initiates connections and polls cyclically
Data Ownership Stores Coils (0x), Discrete Inputs (1x), Input Regs (3x), Holding Regs (4x) Reads from or writes to server memory tables
Connection Handling Multi-socket server daemon; serves multiple simultaneous clients Maintains socket connection pools to target servers
Message Framing Receives request frame, validates CRC/MBAP, returns response frame Constructs request frame, tracks transaction IDs, handles timeouts

2. Modbus TCP Protocol Architecture & MBAP Header

Unlike Modbus RTU which appends a 2-byte Cyclic Redundancy Check (CRC-16) at the end of the frame, Modbus TCP encapsulates the standard Modbus PDU (Protocol Data Unit) inside a 7-byte MBAP Header (Modbus Application Protocol Header). The underlying Ethernet/IP and TCP layers ensure transmission integrity, eliminating the need for application-layer CRC checksums.

+---------------------------------------------------------------------------------+
|                                 Modbus TCP ADU                                  |
+----------------------------------------------------------------+----------------+
|                         MBAP Header (7 Bytes)                  |   Modbus PDU   |
| Transaction ID (2B) | Protocol ID (2B) | Length (2B) | Unit ID | FC (1B) | Data |
+----------------------------------------------------------------+----------------+

A compliant Modbus TCP server simulator must correctly parse and validate every field in the MBAP header:

  1. Transaction Identifier (2 Bytes): Used by the client to pair asynchronous request and response frames. The server simulator must echo the exact Transaction ID back to the client.
  2. Protocol Identifier (2 Bytes): Always 0x0000 for standard Modbus protocol communications.
  3. Length Field (2 Bytes): Specifies the number of following bytes in the message, including the Unit Identifier and PDU payload.
  4. Unit Identifier (1 Byte): Represents the Slave ID (1–247). In routed architectures with serial gateways, the simulator uses this byte to direct requests to the appropriate virtual slave instance.

3. Core Memory Tables in Modbus Server Simulation

A Modbus server maintains four distinct memory tables. Each table addresses specific types of industrial I/O signals:

4. Setting Up a Virtual Modbus Server in Modbus Simulator Desktop

Modbus Simulator Desktop provides a modern 64-bit simulation environment that replaces dated 32-bit legacy tools like ModSim32. Follow these steps to configure a virtual server on your PC:

  1. Launch Modbus Simulator: Select New Server Configuration from the main toolbar.
  2. Select Protocol Mode: Choose Modbus TCP Server to listen on Ethernet, or Modbus RTU Server to bind to a virtual serial COM port (using tools like com0com or Virtual Serial Port Driver).
  3. Bind Network Interface & Port: By default, the TCP server binds to 0.0.0.0:502 (listening across all network adapters). For local-only loopback testing, bind to 127.0.0.1:502. If port 502 requires administrative rights or conflicts with existing services, you can designate an alternate port (such as 5020).
  4. Define Slave ID & Memory Allocation: Configure the active Unit ID (e.g., Slave ID 1) and allocate register blocks (e.g., Holding Registers 40001 to 40100).
  5. Configure Data Simulation Profiles: Rather than serving static numbers, enable dynamic automation profiles:
    • Sine Wave Generator: Simulates fluctuating analog temperature or vibration values.
    • Incremental Ramp / Counter: Generates automated heartbeat watchdog signals or production part counters.
    • Random Noise Generator: Injects realistic sensor jitter to verify filter algorithms in your SCADA platform.
  6. Start Listening: Click Start Server. The status bar immediately confirms active socket listening and ready state.

Download Native 64-Bit Modbus Simulator Desktop

Run multiple virtual Modbus TCP and RTU servers on Windows 10 & 11. Built-in script engine, floating point registers, traffic logger, and zero lag.

Download Free Trial →

5. Testing Modbus Server Simulator with Python (PyModbus)

You can verify your virtual Modbus TCP server simulator using a lightweight Python script with pymodbus. The following script connects as a Modbus client, writes setpoints to holding registers, and reads back simulated sensor variables:

from pymodbus.client import ModbusTcpClient
import struct
import time

def test_modbus_server():
    # Connect to local Modbus TCP Server Simulator
    SERVER_IP = "127.0.0.1"
    SERVER_PORT = 502
    UNIT_ID = 1

    client = ModbusTcpClient(SERVER_IP, port=SERVER_PORT)
    
    if not client.connect():
        print(f"[-] Connection to Modbus server at {SERVER_IP}:{SERVER_PORT} failed.")
        return

    print(f"[+] Successfully connected to Modbus Server Simulator ({SERVER_IP}:{SERVER_PORT})")

    try:
        # 1. Write single holding register (FC 06)
        # Register 40001 (Address 0) = Setpoint 1500
        client.write_register(0, 1500, slave=UNIT_ID)
        print("[+] Written Setpoint: 1500 to Register 40001")

        # 2. Write 32-bit Float to Registers 40002-40003 (FC 16)
        # Temperature = 78.45 °C (IEEE 754 Big-Endian)
        temp_val = 78.45
        float_bytes = struct.pack(">f", temp_val)
        reg_high, reg_low = struct.unpack(">HH", float_bytes)
        client.write_registers(1, [reg_high, reg_low], slave=UNIT_ID)
        print(f"[+] Written Float: {temp_val} to Registers 40002-40003")

        # 3. Read back holding registers (FC 03)
        rr = client.read_holding_registers(0, 4, slave=UNIT_ID)
        if not rr.isError():
            print(f"[+] Raw Read Registers: {rr.registers}")
            # Unpack float
            read_bytes = struct.pack(">HH", rr.registers[1], rr.registers[2])
            read_float = struct.unpack(">f", read_bytes)[0]
            print(f"[+] Decoded Temperature Float: {read_float:.2f} °C")
        else:
            print(f"[-] Read error: {rr}")

    finally:
        client.close()
        print("[+] Connection closed.")

if __name__ == "__main__":
    test_modbus_server()

6. Advanced Simulation: Multi-Slave Routing & Floating Point Endianness

In production plant environments, complex architectures present subtle edge cases that a robust server simulator must replicate:

Multi-Slave Emulation on a Single Port

When testing supervisory SCADA drivers designed to poll solar farms or submetering panels behind an Ethernet gateway, you may need a single server to respond to 32 different Unit IDs. Modbus Simulator Desktop allows you to assign unique register tables to each Unit ID, enabling realistic gateway simulation without creating multiple TCP sockets.

32-Bit and 64-Bit Word Byte Order (Endianness)

Because the standard Modbus specification only defines 16-bit register registers, storing 32-bit integers or IEEE 754 floating-point values requires spanning two consecutive registers. Manufacturers handle word and byte ordering differently:

Modbus Simulator Desktop provides real-time byte ordering toggles, ensuring your SCADA driver displays accurate process engineering values rather than garbage numeric overflow errors.

7. Troubleshooting Modbus Server Connections

When testing communication between a client and a virtual Modbus server, control engineers frequently encounter standard network hurdles:

8. Frequently Asked Questions (FAQs)

What is the difference between a Modbus Server and a Modbus Client?

In Modbus TCP terminology, a Modbus Server is equivalent to a traditional Modbus Slave: it listens on TCP port 502, holds data tables, and responds to queries. A Modbus Client is equivalent to a Modbus Master: it initiates TCP connections and queries data.

Why use a Modbus server simulator instead of physical hardware?

A server simulator allows developers and engineers to test SCADA screens, PLC drivers, and IoT pipelines without buying physical hardware, enabling stress testing, error injection, and edge-case validation.

Can a Modbus server simulator simulate multiple slave IDs simultaneously?

Yes. Modbus Simulator Desktop can run multi-slave simulations where a single Modbus TCP server responds to multiple Unit IDs (Slave IDs 1 to 247) on port 502.

How does Modbus TCP handle Unit ID (Slave ID) addressing?

In direct Modbus TCP devices, the IP address uniquely identifies the unit. However, when passing through an Ethernet-to-serial gateway, the Unit ID is used to address the downstream RS-485 serial slave device.

How do I test a Modbus TCP server simulator with Python?

Use Python's pymodbus library to instantiate ModbusTcpClient with server IP ('127.0.0.1') and port (502), connect, and call read_holding_registers() or write_register() to verify live communication.

Can Modbus Simulator Desktop run offline without an internet connection?

Yes. Modbus Simulator Desktop is a native 64-bit Windows executable that runs 100% locally and offline without requiring internet connectivity once activated.