Closed clan4456 closed 2 years ago
有自定义协议功能, 可以实现此功能,并且更强大
是在这个页面下使用吗?是通过改写decode和encode?decode是接收,encode是发送?但如果我要输入自定义的内容,也好像没有文本框可以输入发送内容啊?例如我要实现,发送时自动在发送内容后增加0x01 0x02两个字节数据,该如何实现?还望指点一下!
def encode(data):
return data + b'\x01\x02'
发送内容修改右边的输入框就好了,比如hello
,点击
按钮就能发送了
另外, 如果你是用pip
安装的 comtool, 你也可以直接在代码里面 import
外部模块,比如
先安装crccheck
模块
pip install crccheck
然后修改代码
import crccheck.crc import Crc16Modbus
crc16_modbus = Crc16Modbus()
def encode(data):
sum = crc16_modbus.calc(data)
return data + sum.to_bytes(2, byteorder="little")
明白了,非常感谢!
希望能增加发送数据时自动发送附加位的功能,可在发送数据时自动在数据末端增加常见的CRC/LRC/CheckSUM等常见校验字节。这样可方便调试。
举例:进行Modbus调试时,只需在输入框输入 01 03 00 0A 00 02 (03指令读000A~000B寄存器数据),点击发送后,自动发送实际的Modbus指令 01 03 00 0A 00 02 E4 09,(E4 09为自动根据Modbus CRC-16校验算法计算字节数据)
参考: