Neutree / COMTool

Cross platform communicate assistant(Serial/network/terminal tool)( 跨平台 串口调试助手 网络调试助手 终端工具 linux windows mac Raspberry Pi )支持插件和二次开发
https://neucrack.com/p/186
GNU Lesser General Public License v3.0
1.85k stars 338 forks source link

功能建议-自动发送附加位 #63

Closed clan4456 closed 2 years ago

clan4456 commented 2 years ago

希望能增加发送数据时自动发送附加位的功能,可在发送数据时自动在数据末端增加常见的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校验算法计算字节数据)

参考:

Neutree commented 2 years ago

有自定义协议功能, 可以实现此功能,并且更强大

clan4456 commented 2 years ago

是在这个页面下使用吗?是通过改写decode和encode?decode是接收,encode是发送?但如果我要输入自定义的内容,也好像没有文本框可以输入发送内容啊?例如我要实现,发送时自动在发送内容后增加0x01 0x02两个字节数据,该如何实现?还望指点一下!

Neutree commented 2 years ago
def encode(data):
    return data + b'\x01\x02'

发送内容修改右边的输入框就好了,比如hello,点击 image 按钮就能发送了

另外, 如果你是用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")
clan4456 commented 2 years ago

明白了,非常感谢!