Skip to content
Modbus Application Protocol V1.1b3

Modbus

The most widely deployed protocol in industrial automation: meters, inverters, batteries, drives and PLCs.

Transports
TCP, RTU, ASCII, TLS, UDP
Default port
502 (TCP), 802 (TLS)
Library
go-modbus
CLI
modbusctl
UI app
Modbus Trace Explorer

Modbus is the most widely deployed protocol in industrial automation. It dates from 1979, it is simple, and almost every energy meter, solar inverter, battery system, drive and PLC speaks it. A client (master) reads and writes four data tables on a server (slave): coils and discrete inputs (bits), and input registers and holding registers (16-bit words).

Where you meet it

  • Energy meters, solar inverters and battery systems, often with a SunSpec Modbus information model on top
  • PLCs, drives and remote I/O on the plant floor
  • RS-485 field buses (Modbus RTU) and serial-to-Ethernet gateways

Quickstart

From the command line

Install modbusctl with curl -fsSL https://get.otfabric.io/modbusctl | sh, or on Windows irm https://get.otfabric.io/modbusctl.ps1 | iex (all install options), then:

Terminal window
# What is this device? (FC43 Device Identification + FC17 Report Server ID)
modbusctl client identify --ip 192.168.1.10 --server-id
# Which register blocks are readable? (adaptive scan, saved to an MBCAP capture)
modbusctl client scan --ip 192.168.1.10 --algo smart --start 0 --end 5000 --output scan.mbcap
# Poll four holding registers every second until Ctrl-C
modbusctl client poll --ip 192.168.1.10 --start 100 --count 4
# Serve the scan results as a simulated device on port 1502
modbusctl server static --input scan.mbcap --port 1502

Addresses are raw Modbus PDU addresses (0–65535), not “4xxxx” register labels.

From a packet trace

Something is slow, missing or wrong between a client and its devices, and you have a tcpdump or Wireshark capture of the traffic? Modbus Trace Explorer opens it and shows it in Modbus terms: latency per device and unit, what each client polls and how regularly, exceptions explained in words, the values of a register over time, and every connection with its resets and gaps. It then exports what the devices really answered as an MBCAP capture, which modbusctl server replay serves as a simulated device. It never talks to a device. Download it from GitHub Releases for macOS, Windows or Linux; Captures and traces has the command-line route with mbtracectl.

From Go

Terminal window
go get github.com/otfabric/go-modbus

Read four holding registers from unit 1 over Modbus TCP:

main.go
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/otfabric/go-modbus"
)
func main() {
client, err := modbus.New(modbus.NewConfig(
modbus.TransportConfig{URL: "tcp://192.168.1.10:502", DialTimeout: 5 * time.Second},
modbus.ExecutionConfig{Timeout: 3 * time.Second},
modbus.ObservabilityConfig{},
))
if err != nil {
log.Fatal(err)
}
if err := client.Open(); err != nil {
log.Fatal(err)
}
defer client.Close()
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
regs, err := client.ReadRegisters(ctx, 1, 100, 4, modbus.HoldingRegister)
if err != nil {
log.Fatal(err)
}
fmt.Println(regs)
}

What go-modbus supports

Transports Modbus TCP, RTU and ASCII (RS-232/RS-485), TLS (MBAPS), UDP, RTU-over-TCP, RTU-over-UDP, ASCII-over-TCP
Roles Client and server
Function codes The function codes of the specification as client and server, except CANopen (FC43/13): coils, discrete inputs, input and holding registers, mask write, read/write multiple, FIFO, file records, diagnostics, report server ID, device identification (FC43/14)
Typed values uint16–uint64, float32/64, strings, BCD, IP addresses, timestamps, with explicit byte and word order
SunSpec Marker detection and model-chain discovery; full point decoding in go-sunspec
Go version 1.26 or later

Interoperability

modbus-interop runs go-modbus against nine independent stacks, as both client and server: libmodbus (C), PyModbus (Python), digitalpetri/modbus (Java), NModbus (C#), tokio-modbus (Rust), and since v0.4.0 j2mod (Java), jsmodbus (JavaScript), modbus-esp8266 (C++) and modbus4j (Java). The newer four also bring Modbus over UDP and RTU framing over TCP to the suite. modbus4j is GPL-3.0, so its image is built locally and not published. The suite also publishes go-modbus as an image for others to test against.

OT Fabric projects for Modbus

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-modbus
  • Modbus
GitHub

go-modbus-capture

MBCAP, 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-capture

go-modbus-trace

Read 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-trace

modbus-simulator

Deterministic, stateful Modbus TCP and TLS device simulator driven by JSON fixtures, with fault injection, request traces and CI assertions.

modbusctl

Identify, 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.

  • Modbus
GitHub

go-serial

Cross-platform serial ports for RS-232 and RS-485, with a Modbus RTU preset.

go get github.com/otfabric/go-serial

modbus-interop

Modbus reference stacks: libmodbus, PyModbus, digitalpetri, NModbus, tokio-modbus, j2mod, jsmodbus, modbus-esp8266 and modbus4j, over TCP, UDP and RTU over TCP.

Modbus Trace Explorer

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.

go-sunspec

SunSpec 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-sunspec
  • SunSpec
GitHub

sunspecctl

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.

  • SunSpec
GitHub

SunSpec Explorer

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.

  • SunSpec
GitHub

Who is behind Modbus

The organizations that publish, test, certify or host open-source work for Modbus. Listed for reference, not as partners. Compare membership and fees.