访问modbus设备的命令行工具
modbus_cli的Python项目详细描述
Author: | favalex@gmail.com |
---|---|
Date: | 2017-06-04 |
Copyright: | MPL 2.0 |
Version: | 0.1 |
Manual section: | 1 |
概要
modbus [-h] [-r REGISTERS] [-s SLAVE_ID] [-b BAUD] [-p STOP_BITS] [-v] device access [access …]
说明
modbus允许从命令行读取和写入modbus设备的寄存器。
它可以与TCP和RTU(即串行)设备通信,并可以编码和解码 在modbus 16位寄存器中输入大于16位的类型(例如浮点)。
寄存器定义(由寄存器地址及其类型组成)可以是 直接在命令行上提供或从文件加载并由 象征性的名字,为了方便。
modbus是在提供的协议实现之上用python实现的 通过umodbus python库。
选项
- 设备
- /dev/ttyXXX表示串行设备,或hostname[:port]表示TCP设备
- 访问
- 一个或多个读或写操作。请参阅下面的访问语法。
-r FILE, --registers=FILE | |
Read registers definitions from FILE. | |
-v, --verbose | Print on screen the bytes transferred on the wire. |
-b BAUD, --baud=BAUD | |
Set the baud rate for serial connections. | |
-p BITS, --stop-bits=BITS | |
Set the number of stop bits for serial connections. | |
-h, --help | Show this help message and exit. |
访问语法
[modbus类型@]地址[/二进制类型][=值]
- modbus类型=H I C D
modbus类型,其中之一
code name size writable ^{tt3}$ holding register 16 bits yes ^{tt4}$ input register 16 bits no ^{tt5}$ coil 1 bit yes ^{tt6}$ discrete input 1 bit no - 地址=<;数字>;
- 基于0的寄存器地址
- 二进制类型=<;压缩格式>;
python标准pack模块接受的任何格式描述。一些常见的格式是:
code type ^{tt3}$ 16 bits signed integer ^{tt9}$ 16 bits unsigned integer ^{tt4}$ 32 bits signed integer ^{tt11}$ 32 bits unsigned integer ^{tt12}$ 32 bits IEEE 754 float 默认字节顺序是big endian,使用格式中的<前缀指定little endian。
- 值=<;数字>;
- 要写入寄存器的值。如果不存在,将读取寄存器。
示例
^{tt14}$ | read the 32-bits unsigned integer stored in holding registers at addresses 39 and 40 |
^{tt15}$ | same as above (h is the default modbus type) |
^{tt16}$ | write the integer 42 to that register |
^{tt17}$ | same as above, provided the registers file contains the definition ^{tt18}$ |
^{tt19}$ | the value can be specified in hexadecimal |
^{tt20}$ | read coil at address 5 |
^{tt21}$ | write a floating point value to holding registers at addresses 24 and 25 |
^{tt22}$ | read six unsigned bytes stored in input registers at addresses 1, 2 and 3 |
寄存器文件语法
一个#开始一个注释。
每行包含一个符号名,后跟寄存器定义,用空格分隔。