go-modbus
Modbus client and server for the functions of the specification: TCP, RTU, ASCII, TLS and UDP, typed register codecs, pooling, retries and a PDU tap for recording.
go get github.com/otfabric/go-modbusIdentify, fingerprint, scan, poll, decode and write Modbus devices over TCP, serial and TLS. Record them to MBCAP capture files and replay those as a simulated device.
Linux and macOS
curl -fsSL https://get.otfabric.io/modbusctl | shWindows (PowerShell)
irm https://get.otfabric.io/modbusctl.ps1 | iexCI, containers and device images
curl -fsSL https://get.otfabric.io/modbusctl | env OTF_UNMANAGED_INSTALL=/usr/local/bin shOne static binary for Linux (x86-64, ARM64, ARMv7), macOS (Intel, Apple silicon) and Windows (x86-64, ARM64), with no runtime to install. The installer checks the release's SHA-256 checksum, installs per user without sudo, and upgrades in place when you run it again. Pin a release withOTF_VERSION. All install options. To build from source: make build in a checkout.
# What is this device? Device identification and Report Server ID
modbusctl client identify --ip 192.168.1.10 --server-id
# Which read function codes does each unit support?
modbusctl client fingerprint --ip 192.168.1.10 --unit 1-10
# Which register blocks are readable? Saved to an MBCAP capture
modbusctl client scan --ip 192.168.1.10 --algo smart --start 0 --end 5000 --output scan.mbcap
# Read and decode a 32-bit float, as JSON
modbusctl client decode --ip 192.168.1.10 --start 40001 --codec float32/layout:4321 --format json
# Poll four holding registers every second, until Ctrl-C
modbusctl client poll --ip 192.168.1.10 --start 100 --count 4
# Serve the scan as a simulated device on port 1502
modbusctl server static --input scan.mbcap --port 1502The modbusctl guide walks through every command group, connection option and safety rule.
modbusctl is as easy to read for a pipeline as for a person. It follows the same conventions as every OT Fabric tool, so a script written for one protocol carries over to the next.
--format json, or MODBUSCTL_FORMAT=json for a whole job. One JSON document per command, JSON Lines for streams, and a single {"error": {"kind", "code", "message"}} object on failure. Field names are a documented contract: json-output.md.modbusctl version --json prints name, version,tag, commit, built, libraries (the OT Fabric stacks inside the binary), go andplatform, with the same keys in every tool.OTF_VERSION, and OTF_UNMANAGED_INSTALL for images that must not touch PATH or shell profiles.| Code | Meaning |
|---|---|
0 | Success |
1 | Findings: the command completed and its result reports problems, such as a file that does not validate or a diagnosis with a failing check |
2 | Usage: unknown command or flag, a missing argument |
3 | Invalid input: a flag value, a file or a combination that does not make sense. Nothing was sent |
4 | Transport: the connection could not be made, or was lost |
5 | Timeout: the device did not answer in time |
6 | Protocol: the device refused the request, or broke the protocol |
7 | Partial success: a valid result was written, and it holds failures |
8 | Unsupported: the device, or this platform, does not support what was asked |
9 | Permission: the device or the operating system refused, such as raw-socket access without the capability |
10 | Output or internal error |
130 | Interrupted by Ctrl-C or SIGTERM before a result |
Each tool uses the codes that apply to it; a code never changes meaning between tools.
In a Dockerfile
FROM debian:bookworm-slim
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates curl \
&& curl -fsSL https://get.otfabric.io/modbusctl \
| env OTF_UNMANAGED_INSTALL=/usr/local/bin sh \
&& rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["modbusctl"]Scripts, CI and containers has GitHub Actions and GitLab CI examples and shows how to use a simulator as a test fixture.
The README on GitHub has the full feature list, examples and changelog.
Modbus client and server for the functions of the specification: TCP, RTU, ASCII, TLS and UDP, typed register codecs, pooling, retries and a PDU tap for recording.
go get github.com/otfabric/go-modbusMBCAP, the capture format for what Modbus devices answered and when, so a virtual device can serve it again. Go library and mbcapctl to inspect, verify, convert, filter, merge and repair captures.
go get github.com/otfabric/go-modbus-captureRead pcap and pcapng traces of Modbus/TCP offline: transactions, devices, poll patterns and address coverage. Library and mbtracectl, with timeline, sub-trace and MBCAP export.
go get github.com/otfabric/go-modbus-traceSunSpec over Modbus, both sides: discovers and decodes 112 built-in models into typed, scaled values, and serves simulated or real SunSpec devices.
go get github.com/otfabric/go-sunspecDeterministic, stateful Modbus TCP and TLS device simulator driven by JSON fixtures, with fault injection, request traces and CI assertions.
Detect, list, read and poll SunSpec inverters, meters and batteries, and serve a simulated device from a JSON file or a capture of a real one.
Cross-platform serial ports for RS-232 and RS-485, with a Modbus RTU preset.
go get github.com/otfabric/go-serialModbus reference stacks: libmodbus, PyModbus, digitalpetri, NModbus, tokio-modbus, j2mod, jsmodbus, modbus-esp8266 and modbus4j, over TCP, UDP and RTU over TCP.
SunSpec reference stacks in containers behind one contract: the SunSpec Alliance's pysunspec2 and cB-Sigma's sunspec and sunspec-sim, as devices and clients, with fixtures from the common models to the IEEE 1547 DER curves.
Open a packet trace of Modbus/TCP traffic and see it in Modbus terms: every request with its response, per device, per poll and per register. Then export the real traffic to replay as a simulated device.
Connect to a SunSpec inverter, meter or battery and see every model it exposes fully decoded. Read once or poll, record and export, without ever writing to the device.