---
name: modbuspilot
description: Read, write, scan and troubleshoot Modbus RTU and Modbus TCP devices (PLCs, energy meters, inverters, power supplies, sensors, drives) with the ModbusPilot command line, modbuspilot-cli. Use it when the user asks for live values such as voltage, current, temperature, humidity, status or alarms, wants to write a setpoint, find devices on an RS-485 or serial bus, decode a Modbus frame, or turn a datasheet register table (PDF, Excel, Word, CSV) into a device profile.
---

# ModbusPilot: Modbus devices from the command line

ModbusPilot talks to Modbus RTU (RS-485, RS-232, USB serial) and Modbus TCP devices. Its command line, `modbuspilot-cli`,
gives you real values from real hardware: voltages, temperatures, status words, alarms and setpoints.

## How to run

- Command: `modbuspilot-cli` (Windows: `modbuspilot-cli.exe` next to `ModbusPilot.exe`; macOS: `./modbuspilot-cli` from the zip; from source: `python modbuspilot_cli.py`). If it is not on PATH, use the full path.
- Check it works: `modbuspilot-cli --version`
- Every option, JSON shape and error: `reference.md` next to this skill, or run `modbuspilot-cli ai guide`.

## Workflow

1. **Connection.** If the user did not give it, run `modbuspilot-cli ports --json`, then ask for the port, baud rate and
   slave ID (typical: 9600, 19200 or 115200 baud, 8N1, slave 1). For Modbus TCP use `--host IP` instead of `--port`.
2. **Profile first.** A device profile (`-P device.json`) gives names, units, scaling and status texts.
   - Learn the names: `modbuspilot-cli profile show device.json --json`
   - No profile but a datasheet? `modbuspilot-cli profile import datasheet.pdf --out device.json --json`
3. **Read.**
   - Named values: `modbuspilot-cli get -p COM20 -b 115200 -P device.json "Battery voltage" "Power state" --json`
   - Whole device: `modbuspilot-cli poll -p COM20 -b 115200 -P device.json --json`
   - Raw addresses: `modbuspilot-cli read -p COM20 -b 115200 -s 1 -a 40001 -c 10 --json`
   - With type and scale: `modbuspilot-cli read -p COM20 -a 40036 -t uint16 --scale 0.001 --unit V --json`
   - Trend: `modbuspilot-cli get -P device.json "Temperature" --watch 1 --samples 30 --format csv`
4. **Answer.** Always use `--json` and check `"ok"`. Report each `name`, `value` and `unit`, and say so when an
   `alarm` field is present. Keep the raw hex (`raw`) for troubleshooting.
5. **Write only with consent.** Repeat the register, value and effect, and wait for the user's clear yes:
   - `modbuspilot-cli set -P device.json "Output enable" ON --json`
   - `modbuspilot-cli write -p COM20 -a 40039 -v 7 --json` (`-v 1,2,3` writes several registers)

## Addresses

| Reference | Area | Read with |
|-----------|------|-----------|
| 00001-09999 | Coils (read/write bits) | `read --fc 1` |
| 10001-19999 | Discrete inputs (read-only bits) | `read --fc 2` |
| 30001-39999 | Input registers (read-only) | `read --fc 4` |
| 40001-49999 | Holding registers (read/write) | `read` (default `--fc 3`) |

`-a 40001` is protocol address 0. Datasheets that list 0-based offsets (0x0000, 0x0010 ...) need `-z`:
`read -a 0x10 -z`. 32-bit values use two registers: add `-t float32` or `-t uint32` and, if the number looks wrong,
try `--order CDAB` (word swap), `BADC` or `DCBA`.

## Errors

| `kind` / exit code | Meaning | What to do |
|--------------------|---------|------------|
| `timeout` (1) | No answer | Check port, baud, parity, slave ID, A/B wiring; some devices need `--break-data BRK` |
| `exception` (1) | Device refused (02 = address does not exist) | Check the address and 40001 vs `-z` |
| `crc` / `invalid` (1) | Damaged or unexpected reply | Wrong baud or parity, noise, two masters on the bus |
| `transport` (1) | Port missing or busy | Another program (often the ModbusPilot app) has the port open: ask the user to close it |
| `usage` (2) | Bad option or unknown name | Fix the command; `profile show` lists names |
| `license` (3) | Needs the Pro edition (evaluation used up) | The user buys a key and runs `modbuspilot-cli license --activate KEY` |

## Rules

- Reads are safe. Never run `write`, `set` or a `raw` frame that changes the device without explicit approval.
- Only one program can open a serial port at a time.
- Do not invent scaling or meanings; use the profile or ask for the datasheet.
- Poll gently (`--watch 1` or slower) and always stop (`--samples N`).
- If an MCP server named `modbuspilot` is connected, you may use its tools (`get_values`, `read_device`,
  `read_registers`, `describe_profile` ...) instead of the shell; the same rules apply.
