-
Notifications
You must be signed in to change notification settings - Fork 33
Commandline
Erriez edited this page Apr 19, 2018
·
3 revisions
The commandline interface is the same for Windows and Linux.
(venv) > python modbus.py --help
usage: modbus.py [-h] [-b <BAUDRATE>] <SERIAL_PORT> {monitor,send} ...
Python script to monitor/send RS485 MODBUS commands v1.0.0.
positional arguments:
<SERIAL_PORT> Serial port (such as COM1 or /dev/ttyUSB0)
{monitor,send} MODBUS command
monitor Monitor and print receiving frames
send Send MODBUS frame
optional arguments:
-h, --help show this help message and exit
-b <BAUDRATE>, --baudrate <BAUDRATE>
Serial baudrate (Default: 9600)
(venv) > python modbus.py COM3 send --help
usage: modbus.py <SERIAL_PORT> send [-h] [-n] <FRAME>
positional arguments:
<FRAME> ASCII frame, for example: ":010600010100" or "01 06 00
01 01 00" or "0x01, 0x06, 0x00, 0x01, 0x01, 0x00". CRC
is automatically added to the end of the frame, or can
be omitted with the--no-append-crc option.
optional arguments:
-h, --help show this help message and exit
-n, --no-append-crc Do not append CRC at the end of <FRAME>
(venv) > python modbus.py COM3 send ":010600010100"
TX 8 Bytes: 01 06 00 01 01 00 D9 9A
RX 8 Bytes: 01 06 00 01 01 00 D9 9A
Done
(venv) > python modbus.py COM3 send "01 06 00 01 01 00 D9 9A" --no-append-crc
TX 8 Bytes: 01 06 00 01 01 00 D9 9A
RX 8 Bytes: 01 06 00 01 01 00 D9 9A
Done
(venv) > python modbus.py COM3 send "0x01, 0x06, 0x00, 0x01, 0x01, 0x00"
TX 8 Bytes: 01 06 00 01 01 00 D9 9A
RX 8 Bytes: 01 06 00 01 01 00 D9 9A
Done
(venv) > python modbus.py COM3 monitor --help
usage: modbus.py <SERIAL_PORT> monitor [-h] [-a <ADDRESS>]
optional arguments:
-h, --help show this help message and exit
-a <ADDRESS>, --address <ADDRESS>
Address of the board [0..63] (Set DIP switches)
(venv) > python modbus.py COM3 monitor
Monitor receiving frames from all addresses.
Press CTRL+C to abort.
RX 16 Bytes: 02 06 00 02 01 00 29 9A 01 06 00 02 01 00 29 9A
RX 16 Bytes: 01 06 00 01 01 00 D9 9A 01 06 00 01 01 00 D9 9A
RX 16 Bytes: 01 06 00 01 02 00 D9 6A 01 06 00 01 02 00 D9 6A
RX 16 Bytes: 01 06 00 01 03 00 D8 FA 01 06 00 01 03 00 D8 FA
...
(venv) > python modbus.py COM3 monitor --address 1
Monitor receiving frames from address 1 only.
Press CTRL+C to abort.
RX 16 Bytes: 01 06 00 01 02 00 D9 6A 01 06 00 01 02 00 D9 6A
...
(venv) > python relay.py --help
usage: relay.py [-h]
<SERIAL_PORT> <ADDRESS>
{status,on,off,toggle,latch,momentary,delay} ...
Python script to control a 8 Channel RS485 MODBUS RTU relay board type
R421A08.
positional arguments:
<SERIAL_PORT> Serial port (such as COM1 or /dev/ttyUSB0)
<ADDRESS> Address of the board [0..63] (Set DIP switches)
{status,on,off,toggle,latch,momentary,delay}
Relay command
status Read status
on On
off Off
toggle Toggle
latch Latch
momentary Momentary
delay Delay
optional arguments:
-h, --help show this help message and exit
(venv) > python relay.py COM3 1 status
Status relays:
Relay 1: ON
Relay 2: ON
Relay 3: OFF
Relay 4: OFF
Relay 5: OFF
Relay 6: OFF
Relay 7: OFF
Relay 8: OFF
Done
(venv) > python relay.py COM3 1 on 2
Relay 2 on...
Done
(venv) > python relay.py COM3 1 off 2
Relay 2 off...
Done
(venv) > python relay.py COM3 1 toggle 2
Relay 2 toggle...
Done
(venv) > python relay.py COM3 1 delay 3 -d 5
Relay 3 delay...
Done
Replace <CMD>
with on, off or toggle.
(venv) > python relay.py COM3 1 <CMD> *
All relays <CMD>...
Done
Replace <CMD>
with on, off or toggle.
Use multiple relay numbers separated with spaces.
(venv) > python relay.py COM3 1 <CMD> 1 2 3
Relays 1, 2, 3 <CMD>...
Done
Replace <CMD>
with on, off or toggle.
Use multiple relay numbers separated with spaces.
(venv) > python relay.py COM3 1 on 1 -v
Relay 1 on...
TX 8 Bytes: 01 06 00 01 01 00 D9 9A
RX 8 Bytes: 01 06 00 01 01 00 D9 9A
Done