A command-line interface tool for Modbus RTU and TCP communication.
npm install -g mb-toolOr use it directly from the project directory:
npm install
npm linkmb-tool connect rtu --port /dev/ttyUSB0 --baudRate 9600 --dataBits 8 --stopBits 1 --parity none --id 1mb-tool connect tcp --host 192.168.1.100 --port 502 --id 1mb-tool connectRead holding registers:
mb-tool read --type holding --address 0 --count 10Read input registers:
mb-tool read --type input --address 0 --count 10Read coils:
mb-tool read --type coil --address 0 --count 10Read discrete inputs:
mb-tool read --type discrete --address 0 --count 10Write to a single holding register:
mb-tool write --type holding --address 0 --values 123Write to multiple holding registers:
mb-tool write --type holding --address 0 --values 123,456,789Write to a single coil:
mb-tool write --type coil --address 0 --values trueWrite to multiple coils:
mb-tool write --type coil --address 0 --values true,false,true--help: Display help information--version: Display version information
--port, -p: Serial port path (e.g., /dev/ttyUSB0, COM1)--baudRate, -b: Baud rate (default: 9600)--dataBits, -d: Data bits (default: 8)--stopBits, -s: Stop bits (default: 1)--parity, -a: Parity (none, even, odd) (default: none)--id, -i: Slave ID (default: 1)
--host, -h: Host IP address or hostname (default: localhost)--port, -p: TCP port (default: 502)--id, -i: Slave ID (default: 1)
--type, -t: Register type (holding, input, coil, discrete) (default: holding)--address, -a: Starting address (default: 0)--count, -c: Number of registers to read (default: 1)
--type, -t: Register type (holding, coil) (default: holding)--address, -a: Starting address (default: 0)--values, -v: Values to write (comma-separated)
MIT License