# ModbusPilot: complete guide for AI assistants > ModbusPilot is a desktop Modbus RTU/TCP poll, monitor and test tool (Windows and macOS). `modbuspilot-cli` is its command > line twin for scripts, CI and AI assistants, and `modbuspilot-cli mcp` is a Model Context Protocol server. This guide > is generated from ModbusPilot 1.0.0 itself (`modbuspilot-cli ai guide`) and is all an AI needs to operate it. ## 1. What you can do - List serial ports; read coils, discrete inputs, holding and input registers (FC01-04) with any data type, byte order and scale. - Read named values (for example "Battery voltage" in V, "Power state" = "Full operating") from a device profile. - Write coils and registers (FC05, 06, 15, 16), or write a named value in engineering units or value text. - Scan a bus for slave IDs, send raw frames, decode captured RTU/TCP frames offline. - Turn a datasheet register table (PDF, Excel, Word, CSV, text) into a device profile (Smart Import). - Repeat reads (`--watch`) and output table, JSON or CSV; give an AI live access through MCP. ## 2. Rules for AI assistants (read first) 1. Use `--json` (`-j`) for every command you parse. Check `"ok"`. Errors are JSON too: `{"ok": false, "error": "...", "kind": "..."}`. 2. Reads are safe. **Never** run `write`, `set`, or `raw` frames that change the device unless the user explicitly approved that exact register and value. Repeat what will change before asking. 3. If the port, baud rate or slave ID is unknown: run `ports`, then ask. Do not loop over random settings on a live plant. `scan` probes many IDs and is fine on a bench; ask first on a production bus. 4. Only one program can open a serial port. A `transport` error such as "Access is denied" or "busy" usually means the ModbusPilot app or a terminal holds it: ask the user to disconnect there. 5. Prefer a profile. Do not guess scaling, units or meanings; use `profile show`, or ask for the datasheet and run `profile import`. 6. Report values with name and unit, mention `alarm` fields, and keep `raw` hex for troubleshooting. 7. Poll gently: `--watch 1` (seconds) or slower, and always bound it with `--samples N`. ## 3. Install and 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. - Windows: `modbuspilot-cli.exe` ships next to `ModbusPilot.exe` (Download page, "Command line tool"). - macOS: `modbuspilot-cli` is in the zip next to `ModbusPilot.app`. First run: `chmod +x modbuspilot-cli; xattr -d com.apple.quarantine modbuspilot-cli`. - From source: `python modbuspilot_cli.py ...` (Python 3.10+, `pip install pyserial`; Smart Import also uses pdfplumber, openpyxl, python-docx). - Check: `modbuspilot-cli --version` prints `ModbusPilot CLI 1.0.0`. - The CLI shares the app's license. `ports`, `decode`, `license` and `ai guide` are free. Device commands (`read`, `poll`, `get`, `set`, `write`, `scan`, `raw`, `profile`), `mcp`, `ai setup`, `ai mcp-config` and `ai export` need the Pro edition; without it they run in a 15-minute evaluation window once per hour, then exit with code 3. `modbuspilot-cli license --json` shows the edition and evaluation state. ## 4. Modbus essentials | Function | Name | Address reference | Access | |----------|------|-------------------|--------| | 01 | Read coils | 00001+ | bits, read/write (write with 05/15) | | 02 | Read discrete inputs | 10001+ | bits, read-only | | 03 | Read holding registers | 40001+ | 16-bit, read/write (write with 06/16) | | 04 | Read input registers | 30001+ | 16-bit, read-only | | 05 / 15 | Write single / multiple coils | 00001+ | ON/OFF | | 06 / 16 | Write single / multiple registers | 40001+ | -32768..65535 per register | - Reference addresses are 1-based: `40001` = protocol address 0, `40036` = 35. `-a 40036` is enough; the function code comes from `--fc`. Hex is accepted: `-a 0x23 -z` is protocol address 35. - Use `-z/--zero-based` when the datasheet lists protocol offsets (0, 0x0000 ...). Off-by-one is the most common mistake: if every value looks shifted by one register, switch between reference and `-z`. - Data types (`-t`): int16, uint16, int32, uint32, float32, int64, uint64, float64, hex, binary, ascii (aliases: short, word, dint, udint, dword, real, float, double, lreal, string). - Byte order (`--order`) for 32/64-bit values: ABCD (big-endian, default), CDAB (word swap, common), BADC (byte swap), DCBA (little-endian). ASCII text is often BADC. - Scale and unit: `--scale 0.1 --unit V` turns raw 2305 into 230.5 V. Profiles store scale, offset, decimals, unit, alarm limits, value texts (enumerations) and bit texts (status words). - Limits: up to 125 registers or 2000 bits per read. Broadcast slave 0 is write-only. ## 5. Connection options (every device command) | Option | Meaning | Default | |--------|---------|---------| | `-p, --port` | Serial port: COM20, /dev/ttyUSB0, /dev/cu.usbserial-1410 | profile or required | | `-b, --baud` | Baud rate | 9600 or the profile | | `--bits`, `--parity`, `--stop` | 7/8, N/E/O, 1/1.5/2 | 8, N, 1 | | `--rtscts` | RTS/CTS hardware flow control | off | | `--host`, `--tcp-port` | Modbus TCP instead of serial | port 502 | | `--rtu-over-tcp` | RTU frames through a TCP serial gateway | off | | `-s, --slave` | Slave / unit ID | 1 or the profile | | `--timeout` | Response timeout in ms | 1000 | | `--delay` | Pause between requests in ms | 20 | | `--break-data` | Bytes sent before every request to wake a device: `BRK`, `0xFF`, `0x76 0x34`, `"text"`; empty = off | off | | `--break-delay` | Pause after the break data in ms, 0-1000 | 15 | | `--break-duration` | Length of a `BRK` UART line break in ms, 0.01-1000 (many USB-RS485 adapters miss a break shorter than a few ms) | 15 | | `-P, --profile` | Device profile JSON; supplies port settings, slave, names, units | none | Options typed on the command line override the profile. ## 6. Commands | Command | Purpose | |---------|---------| | `ports` | list serial ports | | `read` | read coils or registers (FC01-FC04) | | `poll` | read every poll of a device profile with names and units | | `get` | read named values from a profile | | `set` | write a named value from a profile, in engineering units or value text | | `write` | write coils or registers (FC05, FC06, FC15, FC16) | | `scan` | find devices by probing slave IDs | | `raw` | send raw bytes and print what comes back | | `decode` | explain a Modbus RTU or TCP frame | | `profile` | import a datasheet into a profile or show a profile | | `license` | show the edition/license status or activate a key | | `mcp` | run a Model Context Protocol server on stdin/stdout for AI assistants | | `ai` | AI kit: print the AI guide, install the Agent Skill, custom agent and MCP config | ### ports ```text usage: modbuspilot-cli ports [-h] [--format {table,json,csv}] [--json] options: -h, --help show this help message and exit --format, -f {table,json,csv} output format (default table) --json, -j same as --format json ``` ### read ```text usage: modbuspilot-cli read [-h] [--port PORT] [--baud BAUD] [--bits {7,8}] [--parity PARITY] [--stop {1,1.5,2}] [--rtscts] [--host HOST] [--tcp-port TCP_PORT] [--rtu-over-tcp] [--timeout TIMEOUT] [--delay DELAY] [--break-data DATA] [--break-delay BREAK_DELAY] [--break-duration MS] [--profile PROFILE] [--slave SLAVE] [--function FUNCTION] [--address ADDRESS] [--count COUNT] [--zero-based] [--type TYPE] [--order ORDER] [--scale SCALE] [--unit UNIT] [--format {table,json,csv}] [--json] [--watch SECONDS] [--samples SAMPLES] options: -h, --help show this help message and exit --profile, -P PROFILE ModbusPilot device profile JSON with names, units and texts --slave, -s SLAVE slave / unit ID (default 1 or the profile) --function, --fc FUNCTION 1, 2, 3 or 4 / coils, discrete, holding, input (default 3) --address, -a ADDRESS start address: 40001 style reference, or protocol offset with --zero-based --count, -c COUNT number of registers or bits (default 1) --zero-based, -z --address is the 0-based protocol address --type, -t TYPE int16, uint16, int32, uint32, float32, int64, uint64, float64, hex, binary, ascii --order ORDER byte/word order for 32/64-bit: ABCD, CDAB, BADC, DCBA --scale SCALE multiply raw values, for example 0.1 --unit UNIT unit text, for example V --format, -f {table,json,csv} output format (default table) --json, -j same as --format json --watch, -w SECONDS repeat every SECONDS until Ctrl+C --samples, -n SAMPLES with --watch: stop after N samples connection (serial RTU or TCP; profile settings are used when omitted): --port, -p PORT serial port, for example COM20 or /dev/ttyUSB0 --baud, -b BAUD baud rate (default 9600 or the profile) --bits {7,8} data bits (default 8) --parity PARITY N, E or O (default N) --stop {1,1.5,2} stop bits (default 1) --rtscts enable RTS/CTS hardware flow control (off by default) --host HOST Modbus TCP host or IP address (instead of --port) --tcp-port TCP_PORT TCP port (default 502) --rtu-over-tcp send raw RTU frames over TCP (serial gateways) --timeout TIMEOUT response timeout in ms (default 1000) --delay DELAY delay between requests in ms (default 20) --break-data DATA send before every request: BRK, 0xFF, 0x76 0x34, "text" ... (empty = off) --break-delay BREAK_DELAY pause after the break data in ms (default 15) --break-duration MS length of a BRK line break in ms, 0.01-1000 (default 15) ``` ### poll ```text usage: modbuspilot-cli poll [-h] [--port PORT] [--baud BAUD] [--bits {7,8}] [--parity PARITY] [--stop {1,1.5,2}] [--rtscts] [--host HOST] [--tcp-port TCP_PORT] [--rtu-over-tcp] [--timeout TIMEOUT] [--delay DELAY] [--break-data DATA] [--break-delay BREAK_DELAY] [--break-duration MS] [--profile PROFILE] [--poll POLL] [--all] [--format {table,json,csv}] [--json] [--watch SECONDS] [--samples SAMPLES] options: -h, --help show this help message and exit --profile, -P PROFILE ModbusPilot device profile JSON with names, units and texts --poll POLL only this poll (repeatable) --all include registers without a name --format, -f {table,json,csv} output format (default table) --json, -j same as --format json --watch, -w SECONDS repeat every SECONDS until Ctrl+C --samples, -n SAMPLES with --watch: stop after N samples connection (serial RTU or TCP; profile settings are used when omitted): --port, -p PORT serial port, for example COM20 or /dev/ttyUSB0 --baud, -b BAUD baud rate (default 9600 or the profile) --bits {7,8} data bits (default 8) --parity PARITY N, E or O (default N) --stop {1,1.5,2} stop bits (default 1) --rtscts enable RTS/CTS hardware flow control (off by default) --host HOST Modbus TCP host or IP address (instead of --port) --tcp-port TCP_PORT TCP port (default 502) --rtu-over-tcp send raw RTU frames over TCP (serial gateways) --timeout TIMEOUT response timeout in ms (default 1000) --delay DELAY delay between requests in ms (default 20) --break-data DATA send before every request: BRK, 0xFF, 0x76 0x34, "text" ... (empty = off) --break-delay BREAK_DELAY pause after the break data in ms (default 15) --break-duration MS length of a BRK line break in ms, 0.01-1000 (default 15) ``` ### get ```text usage: modbuspilot-cli get [-h] [--port PORT] [--baud BAUD] [--bits {7,8}] [--parity PARITY] [--stop {1,1.5,2}] [--rtscts] [--host HOST] [--tcp-port TCP_PORT] [--rtu-over-tcp] [--timeout TIMEOUT] [--delay DELAY] [--break-data DATA] [--break-delay BREAK_DELAY] [--break-duration MS] [--profile PROFILE] [--format {table,json,csv}] [--json] [--watch SECONDS] [--samples SAMPLES] names [names ...] positional arguments: names register names (exact or part of the name) options: -h, --help show this help message and exit --profile, -P PROFILE ModbusPilot device profile JSON with names, units and texts --format, -f {table,json,csv} output format (default table) --json, -j same as --format json --watch, -w SECONDS repeat every SECONDS until Ctrl+C --samples, -n SAMPLES with --watch: stop after N samples connection (serial RTU or TCP; profile settings are used when omitted): --port, -p PORT serial port, for example COM20 or /dev/ttyUSB0 --baud, -b BAUD baud rate (default 9600 or the profile) --bits {7,8} data bits (default 8) --parity PARITY N, E or O (default N) --stop {1,1.5,2} stop bits (default 1) --rtscts enable RTS/CTS hardware flow control (off by default) --host HOST Modbus TCP host or IP address (instead of --port) --tcp-port TCP_PORT TCP port (default 502) --rtu-over-tcp send raw RTU frames over TCP (serial gateways) --timeout TIMEOUT response timeout in ms (default 1000) --delay DELAY delay between requests in ms (default 20) --break-data DATA send before every request: BRK, 0xFF, 0x76 0x34, "text" ... (empty = off) --break-delay BREAK_DELAY pause after the break data in ms (default 15) --break-duration MS length of a BRK line break in ms, 0.01-1000 (default 15) ``` ### set ```text usage: modbuspilot-cli set [-h] [--port PORT] [--baud BAUD] [--bits {7,8}] [--parity PARITY] [--stop {1,1.5,2}] [--rtscts] [--host HOST] [--tcp-port TCP_PORT] [--rtu-over-tcp] [--timeout TIMEOUT] [--delay DELAY] [--break-data DATA] [--break-delay BREAK_DELAY] [--break-duration MS] [--profile PROFILE] [--format {table,json,csv}] [--json] name value positional arguments: name register name value value, for example 12.5 or Running options: -h, --help show this help message and exit --profile, -P PROFILE ModbusPilot device profile JSON with names, units and texts --format, -f {table,json,csv} output format (default table) --json, -j same as --format json connection (serial RTU or TCP; profile settings are used when omitted): --port, -p PORT serial port, for example COM20 or /dev/ttyUSB0 --baud, -b BAUD baud rate (default 9600 or the profile) --bits {7,8} data bits (default 8) --parity PARITY N, E or O (default N) --stop {1,1.5,2} stop bits (default 1) --rtscts enable RTS/CTS hardware flow control (off by default) --host HOST Modbus TCP host or IP address (instead of --port) --tcp-port TCP_PORT TCP port (default 502) --rtu-over-tcp send raw RTU frames over TCP (serial gateways) --timeout TIMEOUT response timeout in ms (default 1000) --delay DELAY delay between requests in ms (default 20) --break-data DATA send before every request: BRK, 0xFF, 0x76 0x34, "text" ... (empty = off) --break-delay BREAK_DELAY pause after the break data in ms (default 15) --break-duration MS length of a BRK line break in ms, 0.01-1000 (default 15) ``` ### write ```text usage: modbuspilot-cli write [-h] [--port PORT] [--baud BAUD] [--bits {7,8}] [--parity PARITY] [--stop {1,1.5,2}] [--rtscts] [--host HOST] [--tcp-port TCP_PORT] [--rtu-over-tcp] [--timeout TIMEOUT] [--delay DELAY] [--break-data DATA] [--break-delay BREAK_DELAY] [--break-duration MS] [--profile PROFILE] [--slave SLAVE] [--function FUNCTION] --address ADDRESS [--zero-based] --value VALUE [--format {table,json,csv}] [--json] options: -h, --help show this help message and exit --profile, -P PROFILE ModbusPilot device profile JSON with names, units and texts --slave, -s SLAVE slave / unit ID (0 = broadcast) --function, --fc FUNCTION 5, 6, 15 or 16 (default 6, or 16 for several values) --address, -a ADDRESS start address (40001 style, or 0-based with --zero-based) --zero-based, -z --address is the 0-based protocol address --value, -v VALUE value(s): 7, 0x0F, 1,2,3 or ON/OFF for coils --format, -f {table,json,csv} output format (default table) --json, -j same as --format json connection (serial RTU or TCP; profile settings are used when omitted): --port, -p PORT serial port, for example COM20 or /dev/ttyUSB0 --baud, -b BAUD baud rate (default 9600 or the profile) --bits {7,8} data bits (default 8) --parity PARITY N, E or O (default N) --stop {1,1.5,2} stop bits (default 1) --rtscts enable RTS/CTS hardware flow control (off by default) --host HOST Modbus TCP host or IP address (instead of --port) --tcp-port TCP_PORT TCP port (default 502) --rtu-over-tcp send raw RTU frames over TCP (serial gateways) --timeout TIMEOUT response timeout in ms (default 1000) --delay DELAY delay between requests in ms (default 20) --break-data DATA send before every request: BRK, 0xFF, 0x76 0x34, "text" ... (empty = off) --break-delay BREAK_DELAY pause after the break data in ms (default 15) --break-duration MS length of a BRK line break in ms, 0.01-1000 (default 15) ``` ### scan ```text usage: modbuspilot-cli scan [-h] [--port PORT] [--baud BAUD] [--bits {7,8}] [--parity PARITY] [--stop {1,1.5,2}] [--rtscts] [--host HOST] [--tcp-port TCP_PORT] [--rtu-over-tcp] [--timeout TIMEOUT] [--delay DELAY] [--break-data DATA] [--break-delay BREAK_DELAY] [--break-duration MS] [--profile PROFILE] [--from FIRST] [--to LAST] [--function FUNCTION] [--address ADDRESS] [--format {table,json,csv}] [--json] options: -h, --help show this help message and exit --profile, -P PROFILE ModbusPilot device profile JSON with names, units and texts --from FIRST --to LAST --function, --fc FUNCTION --address, -a ADDRESS protocol address to probe (0-based, default 0) --format, -f {table,json,csv} output format (default table) --json, -j same as --format json connection (serial RTU or TCP; profile settings are used when omitted): --port, -p PORT serial port, for example COM20 or /dev/ttyUSB0 --baud, -b BAUD baud rate (default 9600 or the profile) --bits {7,8} data bits (default 8) --parity PARITY N, E or O (default N) --stop {1,1.5,2} stop bits (default 1) --rtscts enable RTS/CTS hardware flow control (off by default) --host HOST Modbus TCP host or IP address (instead of --port) --tcp-port TCP_PORT TCP port (default 502) --rtu-over-tcp send raw RTU frames over TCP (serial gateways) --timeout TIMEOUT response timeout in ms (default 1000) --delay DELAY delay between requests in ms (default 20) --break-data DATA send before every request: BRK, 0xFF, 0x76 0x34, "text" ... (empty = off) --break-delay BREAK_DELAY pause after the break data in ms (default 15) --break-duration MS length of a BRK line break in ms, 0.01-1000 (default 15) ``` ### raw ```text usage: modbuspilot-cli raw [-h] [--port PORT] [--baud BAUD] [--bits {7,8}] [--parity PARITY] [--stop {1,1.5,2}] [--rtscts] [--host HOST] [--tcp-port TCP_PORT] [--rtu-over-tcp] [--timeout TIMEOUT] [--delay DELAY] [--break-data DATA] [--break-delay BREAK_DELAY] [--break-duration MS] [--profile PROFILE] --send SEND [--crc] [--wait WAIT] [--format {table,json,csv}] [--json] options: -h, --help show this help message and exit --profile, -P PROFILE ModbusPilot device profile JSON with names, units and texts --send SEND hex bytes, for example "01 03 00 00 00 01" --crc append the Modbus CRC --wait WAIT listen time in ms (default 500) --format, -f {table,json,csv} output format (default table) --json, -j same as --format json connection (serial RTU or TCP; profile settings are used when omitted): --port, -p PORT serial port, for example COM20 or /dev/ttyUSB0 --baud, -b BAUD baud rate (default 9600 or the profile) --bits {7,8} data bits (default 8) --parity PARITY N, E or O (default N) --stop {1,1.5,2} stop bits (default 1) --rtscts enable RTS/CTS hardware flow control (off by default) --host HOST Modbus TCP host or IP address (instead of --port) --tcp-port TCP_PORT TCP port (default 502) --rtu-over-tcp send raw RTU frames over TCP (serial gateways) --timeout TIMEOUT response timeout in ms (default 1000) --delay DELAY delay between requests in ms (default 20) --break-data DATA send before every request: BRK, 0xFF, 0x76 0x34, "text" ... (empty = off) --break-delay BREAK_DELAY pause after the break data in ms (default 15) --break-duration MS length of a BRK line break in ms, 0.01-1000 (default 15) ``` ### decode ```text usage: modbuspilot-cli decode [-h] [--tcp] [--start START] [--response] [--format {table,json,csv}] [--json] hex [hex ...] positional arguments: hex frame bytes in hex options: -h, --help show this help message and exit --tcp the frame is Modbus TCP (MBAP header) --start START start address of a read response (40001 style) --response treat a 4-byte read payload as a response --format, -f {table,json,csv} output format (default table) --json, -j same as --format json ``` ### profile import ```text usage: modbuspilot-cli profile import [-h] [--out OUT] [--table TABLE] [--name NAME] [--format {table,json,csv}] [--json] file positional arguments: file options: -h, --help show this help message and exit --out, -o OUT save the profile to this JSON file --table TABLE table number to use (default: all matching tables) --name NAME profile name --format, -f {table,json,csv} output format (default table) --json, -j same as --format json ``` ### profile show ```text usage: modbuspilot-cli profile show [-h] [--format {table,json,csv}] [--json] file positional arguments: file options: -h, --help show this help message and exit --format, -f {table,json,csv} output format (default table) --json, -j same as --format json ``` ### license ```text usage: modbuspilot-cli license [-h] [--activate KEY] [--deactivate [PRODUCT]] [--format {table,json,csv}] [--json] options: -h, --help show this help message and exit --activate KEY license key (MT2-... or MT1-...) or a file that contains it --deactivate [PRODUCT] remove all keys, or only the key of one edition (advanced, pro) --format, -f {table,json,csv} output format (default table) --json, -j same as --format json ``` ### mcp ```text usage: modbuspilot-cli mcp [-h] [--port PORT] [--baud BAUD] [--bits {7,8}] [--parity PARITY] [--stop {1,1.5,2}] [--rtscts] [--host HOST] [--tcp-port TCP_PORT] [--rtu-over-tcp] [--timeout TIMEOUT] [--delay DELAY] [--break-data DATA] [--break-delay BREAK_DELAY] [--break-duration MS] [--profile PROFILE] [--allow-write] options: -h, --help show this help message and exit --profile, -P PROFILE ModbusPilot device profile JSON with names, units and texts --allow-write let the AI write registers (off by default) connection (serial RTU or TCP; profile settings are used when omitted): --port, -p PORT serial port, for example COM20 or /dev/ttyUSB0 --baud, -b BAUD baud rate (default 9600 or the profile) --bits {7,8} data bits (default 8) --parity PARITY N, E or O (default N) --stop {1,1.5,2} stop bits (default 1) --rtscts enable RTS/CTS hardware flow control (off by default) --host HOST Modbus TCP host or IP address (instead of --port) --tcp-port TCP_PORT TCP port (default 502) --rtu-over-tcp send raw RTU frames over TCP (serial gateways) --timeout TIMEOUT response timeout in ms (default 1000) --delay DELAY delay between requests in ms (default 20) --break-data DATA send before every request: BRK, 0xFF, 0x76 0x34, "text" ... (empty = off) --break-delay BREAK_DELAY pause after the break data in ms (default 15) --break-duration MS length of a BRK line break in ms, 0.01-1000 (default 15) ``` ### ai guide ```text usage: modbuspilot-cli ai guide [-h] [--brief] [--out OUT] options: -h, --help show this help message and exit --brief only the short skill instructions --out, -o OUT write to this file instead of the screen ``` ### ai setup ```text usage: modbuspilot-cli ai setup [-h] [--for {copilot,claude,codex,cursor,all}] [--dir DIR] [--user] [--port PORT] [--baud BAUD] [--host HOST] [--tcp-port TCP_PORT] [--profile PROFILE] [--slave SLAVE] [--allow-write] [--format {table,json,csv}] [--json] options: -h, --help show this help message and exit --for {copilot,claude,codex,cursor,all} which AI tool (default all) --dir DIR project folder (default: the current folder) --user install in your personal folders (~/.copilot, ~/.claude, ~/.agents) for every project --format, -f {table,json,csv} output format (default table) --json, -j same as --format json default device written into the AI files (optional): --port, -p PORT serial port, for example COM20 --baud, -b BAUD baud rate --host HOST Modbus TCP host --tcp-port TCP_PORT TCP port --profile, -P PROFILE device profile JSON --slave, -s SLAVE slave ID --allow-write MCP config: let the AI write registers ``` ### ai mcp-config ```text usage: modbuspilot-cli ai mcp-config [-h] [--client {vscode,copilot-cli,claude-code,claude-desktop,cursor,codex}] [--port PORT] [--baud BAUD] [--host HOST] [--tcp-port TCP_PORT] [--profile PROFILE] [--slave SLAVE] [--allow-write] options: -h, --help show this help message and exit --client {vscode,copilot-cli,claude-code,claude-desktop,cursor,codex} AI client (default vscode) default device written into the AI files (optional): --port, -p PORT serial port, for example COM20 --baud, -b BAUD baud rate --host HOST Modbus TCP host --tcp-port TCP_PORT TCP port --profile, -P PROFILE device profile JSON --slave, -s SLAVE slave ID --allow-write MCP config: let the AI write registers ``` ### ai export ```text usage: modbuspilot-cli ai export [-h] [--format {table,json,csv}] [--json] dir positional arguments: dir output folder options: -h, --help show this help message and exit --format, -f {table,json,csv} output format (default table) --json, -j same as --format json ``` ## 7. Output and exit codes `--format table` (default, for people), `--json`/`-j` (for programs) or `--format csv`. With `--watch` JSON prints one object per line (each with `time`) and CSV adds a time column. `read` (and `get`, `poll`, which add `poll` and use the profile names): ```json {"ok": true, "slave": 1, "function": 3, "function_name": "Read Holding Registers", "start": "40036", "count": 1, "request": "01 03 00 23 00 01 75 C0", "response": "01 03 02 2C 01 65 44", "raw_values": [11265], "values": [{"address": "40036", "protocol_address": 35, "name": "Battery voltage", "value": "11.265", "numeric": 11.265, "unit": "V", "raw": "2C01", "type": "Unsigned", "alarm": "OK"}]} ``` `alarm` appears only when the profile row has `low`/`high` limits: `"OK"`, `"LOW"` or `"HIGH"`. `poll` adds `"profile"` and `"errors": [{"poll", "error", "kind"}]` for polls that failed while others worked. `write` / `set`: `{"ok": true, "function": 6, "address": "40039", "values": [7], "request": "...", "response": "...", "confirmed": true}` (`set` adds `name` and `value_text`). `scan`: `{"devices": [{"slave": 1, "answer": "data"}]}`. `raw`: `{"sent", "received", "received_bytes", "received_text"}`. `decode`: frame type, unit, CRC check, function, addresses and register values. `ports`: `{"ports": [{"device", "description", "hwid"}]}`. Errors: `{"ok": false, "error": "Timeout error", "kind": "timeout"}`. | Exit | Meaning | `kind` | |------|---------|--------| | 0 | Success | - | | 1 | Device or communication error | `timeout`, `exception` (Modbus exception code), `crc`, `invalid`, `transport` | | 2 | Wrong usage | `usage` | | 3 | Command needs a higher edition (evaluation used up) or license invalid | `license` | Modbus exception codes: 01 illegal function, 02 illegal data address, 03 illegal data value, 04 device failure, 06 busy. ## 8. Device profiles A profile is a JSON file (`"format": "modbuspilot-profile"`) with connection settings and one or more polls. Row keys are protocol addresses (0-based) as strings; the display address follows `reference_mode`. ```json { "format": "modbuspilot-profile", "version": 2, "name": "Power supply board", "manufacturer": "ACME", "model": "PSU-24", "description": "Slave 1, 115200 8N1", "connection": { "mode": "Serial RTU", "timeout_ms": 1000, "delay_ms": 20, "break_enabled": false, "break_data": "BRK", "break_delay_ms": 15, "break_duration_ms": 15 }, "serial": { "baud": "115200", "bits": "8", "parity": "None", "stop": "1" }, "polls": [ { "name": "Status", "slave_id": 1, "function": 3, "address": 29, "quantity": 12, "scan_rate_ms": 1000, "enabled": true, "reference_mode": true, "rows": { "29": { "alias": "Power state", "data_type": "Unsigned", "values": { "1": "Full operating", "3": "Limp", "4": "Brown out" } }, "30": { "alias": "Interrupt status", "data_type": "Unsigned", "bits": { "0": "Firmware update", "3": "Flash error" } }, "35": { "alias": "Battery voltage", "data_type": "Unsigned", "scale": 0.001, "decimals": 3, "unit": "V", "low": 10.5, "high": 12.8 }, "36": { "alias": "Refresh rate", "data_type": "UInt32", "byte_order": "ABCD", "unit": "ms" } } } ] } ``` Row fields: `alias` (name, max 80 chars), `data_type` (Signed, Unsigned, Hex, Binary, ASCII, Int32, UInt32, Float32, Int64, UInt64, Float64), `byte_order`, `scale`, `offset`, `decimals`, `unit`, `low`/`high` (alarm limits), `values` (number -> text), `bits` (bit number -> text). Value = raw * scale + offset. Create one: - `modbuspilot-cli profile import manual.pdf --out device.json --json` (Smart Import finds the register table, names, types, scale and units; check `warnings`). - Or the ModbusPilot app: Tools > Smart Import, or the local Profile Studio web page. - `modbuspilot-cli profile show device.json --json` lists every register with name, address, type, scale, unit and texts. ## 9. MCP server (AI tool access) `modbuspilot-cli mcp [connection options] [--profile device.json] [--allow-write]` speaks MCP (JSON-RPC 2.0) over stdio. Tool arguments can override the connection (`port`, `baud`, `parity`, `stop`, `host`, `tcp_port`, `timeout`). The serial port is released after every call. Write tools exist only with `--allow-write`. | Tool | What it does | Arguments (* = required) | |------|--------------|--------------------------| | `list_serial_ports` | List the serial ports on this computer. | - | | `read_registers` | Read Modbus coils or registers. Addresses use the 40001/30001 reference style by default. Returns raw values and, when a device profile is loaded, names, scaled values, units and status texts. | `port` (string), `baud` (integer), `parity` (N|E|O), `stop` (1|1.5|2), `host` (string), `tcp_port` (integer), `timeout` (integer), `slave` (integer), `function` (1|2|3|4), `address`* (string), `count` (integer), `zero_based` (boolean), `data_type` (string), `byte_order` (ABCD|CDAB|BADC|DCBA), `scale` (number), `unit` (string) | | `read_device` | Read every poll of the loaded device profile and return named values with units, value texts and alarms. | `port` (string), `baud` (integer), `parity` (N|E|O), `stop` (1|1.5|2), `host` (string), `tcp_port` (integer), `timeout` (integer), `polls` (array), `include_unnamed` (boolean) | | `get_values` | Read named values from the loaded device profile, for example ['Battery voltage', 'Power state']. | `port` (string), `baud` (integer), `parity` (N|E|O), `stop` (1|1.5|2), `host` (string), `tcp_port` (integer), `timeout` (integer), `names`* (array) | | `describe_profile` | List the registers of the loaded device profile (names, addresses, types, units, value and bit texts). | `path` (string) | | `load_profile` | Load a different ModbusPilot device profile JSON for the following calls. | `path`* (string) | | `import_datasheet` | Smart Import: turn a PDF, Excel, Word, CSV or text register table into a device profile (optionally saved and loaded). | `path`* (string), `out` (string), `table` (integer), `load` (boolean) | | `scan_devices` | Probe slave IDs and list the devices that answer. | `port` (string), `baud` (integer), `parity` (N|E|O), `stop` (1|1.5|2), `host` (string), `tcp_port` (integer), `timeout` (integer), `first` (integer), `last` (integer), `function` (1|2|3|4) | | `decode_frame` | Explain a Modbus RTU or TCP frame given as hex bytes. | `hex`* (string), `tcp` (boolean) | | `license_status` | Show the ModbusPilot edition and license status. | - | | `get_usage_guide` | Return the complete ModbusPilot guide for AI assistants: addressing, data types, profiles, every tool and command, errors and troubleshooting. Call it once when you are unsure how to use ModbusPilot. | `brief` (boolean) | | `write_registers` | Write Modbus coils or holding registers (FC05/06/15/16). Changes the device. Needs `--allow-write`. | `port` (string), `baud` (integer), `parity` (N|E|O), `stop` (1|1.5|2), `host` (string), `tcp_port` (integer), `timeout` (integer), `slave` (integer), `function` (5|6|15|16), `address`* (string), `zero_based` (boolean), `values`* (array) | | `set_value` | Write a named profile value in engineering units or value text (for example 12.5 or Running). Needs `--allow-write`. | `port` (string), `baud` (integer), `parity` (N|E|O), `stop` (1|1.5|2), `host` (string), `tcp_port` (integer), `timeout` (integer), `name`* (string), `value`* (string) | Also: resource `modbuspilot://guide` (this guide), resource `modbuspilot://profile` (loaded profile), prompts `health_check` and `explain_register`. Generate client configuration with `modbuspilot-cli ai mcp-config --client vscode` (also copilot-cli, claude-code, claude-desktop, cursor, codex) or install everything with `modbuspilot-cli ai setup --for copilot`. ## 10. Recipes | Task | Command | |------|---------| | Which ports exist? | `modbuspilot-cli ports --json` | | Is anything answering? | `modbuspilot-cli scan -p COM20 -b 9600 --from 1 --to 30 --json` | | First 10 holding registers | `modbuspilot-cli read -p COM20 -b 9600 -s 1 -a 40001 -c 10 --json` | | A float at 40101 | `modbuspilot-cli read -p COM20 -a 40101 -c 2 -t float32 --json` (try `--order CDAB`) | | Input registers | `modbuspilot-cli read -p COM20 --fc 4 -a 30001 -c 4 --json` | | Every named value | `modbuspilot-cli poll -P device.json --json` | | Some named values | `modbuspilot-cli get -P device.json "Voltage" "Temperature" --json` | | Log for an hour | `modbuspilot-cli get -P device.json "Voltage" -w 1 -n 3600 -f csv > log.csv` | | Set a value (after OK) | `modbuspilot-cli set -P device.json "Setpoint" 12.5 --json` | | Turn a coil on (after OK) | `modbuspilot-cli write -p COM20 --fc 5 -a 1 -v ON --json` | | Modbus TCP | `modbuspilot-cli read --host 192.168.1.10 -s 1 -a 40001 -c 10 --json` | | Explain a frame | `modbuspilot-cli decode 01 03 02 2C 01 65 44 --json` | | Datasheet to profile | `modbuspilot-cli profile import manual.pdf --out device.json --json` | ## 11. Troubleshooting | Symptom | Likely cause and fix | |---------|---------------------| | `timeout` on every ID | Wrong port or baud/parity; A/B (D+/D-) swapped; no 120 ohm termination on long lines; device needs a wake-up (`--break-data BRK --break-delay 15`) | | `timeout` only with `--break-data` | Raise `--break-delay` (the device needs time after the wake-up bytes) or `--break-duration` (the adapter or wake-up circuit misses a short BRK; try 20-50) | | Exception 02 | Register does not exist: check 40001 vs `-z`, or the device needs a debug mode enabled | | Exception 01 | Wrong function: try `--fc 4` instead of 3 | | Values off by one register | Reference vs 0-based addressing (`-z`) | | Huge or tiny 32-bit numbers | Wrong `--order` (try CDAB) or wrong type | | `crc` errors | Baud/parity mismatch, noise, two masters, missing ground | | Port busy / access denied | Close the ModbusPilot app connection or other terminals | | Exit code 3 | Needs Pro (evaluation used up): `modbuspilot-cli license --activate KEY` | | `"kind": "internal"` (exit 1) | A ModbusPilot bug: the traceback was saved as a problem report; send it from ModbusPilot (Help > Report a Problem) or the website Feedback page | ## 12. More - Human docs: the ModbusPilot website, page "CLI & AI". In the app: Help > Command Line & AI Access. - Agent Skill: `modbuspilot-cli ai setup --for copilot|claude|codex|cursor|all` installs the skill, custom agent, instructions and MCP configuration into a project (`--user` for your personal folders). `modbuspilot-cli ai export DIR` writes every file. - Editions: Free (forever), Advanced and Pro; device commands, `mcp` and the AI kit need Pro. `modbuspilot-cli license --json` shows the edition and evaluation state. Prices: the website pricing page.