— Hardware, Simulators & Workflow

(Module 5 · Development & Implementation – Bringing Modbus to Life)


Why this chapter matters

Theory is useless until bytes hit copper. Whether you are a student with a Raspberry Pi, an automation engineer doing a factory FAT, or an IIoT developer bridging brown-field devices to the cloud, you need a repeatable, instrumented lab. This chapter delivers a blueprint—from the exact USB-to-RS-485 dongle to Wireshark capture filters—so you can reproduce every example in the rest of Module 5.


Learning objectives

  1. Select cost-effective yet industry-realistic hardware for RTU and TCP experiments.
  2. Install & configure the four reference simulators (master + slave, GUI + CLI).
  3. Wire a robust, bias-correct RS-485 loop and verify signal quality with an oscilloscope.
  4. Capture & decode Modbus traffic using serial monitors and Wireshark.
  5. Document your lab in a way that future you—or the audit team—can reconstruct in minutes.

14.1 Bill-of-materials (BOM)

QtyComponentModel / spec₹ / US$Role
1Laptop / PCAny ×64 Win 10+/LinuxPrimary master & analysis node
1USB-to-RS-485 converterWaveshare FT232 / CH340 + MAX485₹650 / $12Serial gateway
1Industrial-grade RS-485 slaveWago 750-652 RTD input₹14 k / $160Real hardware realism
1DIY slave (optional)ESP32 DevKit v4 + MAX3485₹800 / $10Firmware exercises
1Ethernet switchFan-less 5-port GigE, VLAN-capable₹2 k / $25TCP segment
2RJ-45 patch cablesCat-5e, 2 m₹200 / $3LAN
10 mRS-485 cable2-pair + shield, 120 Ω₹1 k / $12Field bus
2120 Ω terminators0.25 W metal-filmEnd-of-line
2680 Ω bias resistorsFail-safe idle
1USB oscilloscope / LAPicoScope 2204A or Saleae Logic 8₹9 k / $110Signal timing & CRC debug

Budget path: Replace industrial slave with Simply Modbus slave simulator and the ESP32 board for ~₹1 500 total outlay.


14.2 Lab topology overview — [Fig-14-1]

┌──────────────┐         Cat-5e        ┌──────────────┐
│   Laptop     │—LAN—►  5-Port Switch  ├─► Modbus TCP
│ (Master +    │                      (Gateway)      │
│  Wireshark)  │                       └──┬───────────┘
└──────────────┘        USB/FT-232         │  RS-485 (2-wire)
                                           │ Bias+Term
                                  ┌────────▼─────────┐
                                  │  Wago 750-652    │
                                  │ (Slave address17)│
                                  └──────────────────┘

14.3 Step 1 — Wire the serial loop

  1. Daisy-chain the twisted pair: A-, B+ on every node. No star tees.
  2. Terminate at both physical ends with 120 Ω.
  3. Apply bias resistors (680 Ω) at exactly one point—preferably the gateway.
  4. Verify idle differential: VAB≈+300mVV_{AB} ≈ +300 mV with multimeter.

Quick oscilloscope check – Send a single 8-byte RTU frame. Confirm clean 0–5 V differential edges; frame ends 3.5-char (~4 ms @ 9 600 Bd) before line idle.


14.4 Step 2 — Install reference simulators

RoleWindows GUICross-platform CLIInstall hint
MasterModscan32 (Win)modpollchoco install modscan / brew install modpoll
SlaveSimply Modbus Slavembserver.py (Pymodbus)pip install pymodbus
GatewayHMS Anybus SG-gateway Lite (demo)socat (rtu⇄tcp-l:502)apt install socat

Create shortcuts:

modpoll.exe -b 9600 -p none -r 1 -c 10 -1 -a 17 COM5

14.5 Step 3 — Verify RTU communications

  1. Open Modscan32Connection: COM5, 9600-8-E-1, RTU.
  2. Add scan block 03/00001/6 → you should see incrementing register data.
  3. Force an error: change slave ID to 18 → observe timeout then incrementing FC = 0x83 exceptions (Wireshark).

Pitfall drill – Swap A/B wires, watch garbled CRC errors; correct wiring, confirm clean frames.


14.6 Step 4 — Bridge to TCP

Transparent mode (quick):

socat -d -d TCP-LISTEN:502,reuseaddr,fork file:/dev/ttyUSB0,raw,echo=0,b115200

Intelligent mode (Anybus):

  • RS-485 tab: 38 400 Bd, 8-E-1, timeout 250 ms.
  • TCP tab: Server mode, port 502; Unit-ID 17 routed → RS-485/17.

Test with modpoll 127.0.0.1 502 -t 3 -r 1 -c 6 -1.


14.7 Step 5 — Capture & decode

Serial
Windows: RealTerm → Port → Half-Duplex; save raw; run through pycrc for CRC check.
Linux: pyserial-asyncio tap script (provided).

Ethernet
Wireshark:

tcp.port == 502 && modbus.exception_code
  • Colour-rule: Exception frames red.
  • Right-click → Follow TCP stream to inspect MBAP header.

14.8 Step 6 — Automate smoke tests

Create pytest suite (Listing 1):

import pytest, pymodbus.client

@pytest.fixture(scope="module")
def client():
    cli = pymodbus.client.ModbusTcpClient("127.0.0.1", port=502)
    cli.connect(); yield cli; cli.close()

def test_echo(client):
    rr = client.read_holding_registers(0, 2, unit=17)
    assert rr.isError() is False

@pytest.mark.parametrize("speed", [9600, 38400, 115200])
def test_speed(speed):
    set_gateway_baud(speed)
    rr = client.read_coils(0, 100, unit=17)
    assert rr.bits[0] is True

Run nightly via GitHub Actions; fail build if any Modbus poll mis-behaves.


14.9 Field-ready lab variations

IterationAddsSkill gained
RedundancySecond gateway + VRRP IPFail-over timing
Noise testSignal generator inject 1 MHz burst on cableCRC robustness
Cloud pathWireGuard tunnel to AWS, NAT traversalKeep-alive & MTU tuning
SecurityProxy → stunnel/TLSCertificates, Wireshark decryption

14.10 Documentation checklist (print & laminate)

  • Bus wiring diagram with colours.
  • COM port mapping (FTDI #A9Y2 = COM5).
  • Device table: ID, baud, parity, register span.
  • Simulator CLI commands.
  • Capture filters & file naming convention (rtu_err_2025-06-07T1421.pcapng).

Chapter recap

  • A solid Modbus lab needs one master, one or two slaves, a gateway, capture tools, and disciplined wiring.
  • Bias & termination errors appear long before protocol errors—verify with meter + scope.
  • Mix GUI simulators for quick manual pokes and CLI tools for automated regression tests.
  • Document everything; tomorrow’s bugfix depends on yesterday’s wiring note.

Assets to create

IDVisual / file
Fig-14-1Lab topology block diagram
Fig-14-2RealTerm serial screenshot (good vs garbled)
Listing 1pytest Modbus smoke test
ZIPReady-made CLI scripts + Wireshark profile

Next: Chapter 15 – Programming Modbus Clients (Masters)—we’ll take the working lab and write full Python, C (libmodbus), and C# masters, dive into asynchronous polling, and implement exception-aware retries. Stay plugged in!

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Chapter 8 – Modbus TCP/IP Implementation

— Sockets, NAT, & Real-World Network Nuances (Module 3 · Modbus TCP/IP — Modbus over Modern Networks) Chapter promise Everything you must know to run Modbus at Ethernet speed reliably, deterministically,…

Chapter 4 – Modbus Serial Physical Layers

— RS-232, RS-422 & RS-485 (Module 2 · Modbus Serial Protocols — The Original Workhorses) Target Reader Automation engineers, embedded developers, and students who must design or debug real Modbus links—cable…