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

协议插件新需求 #75

Closed diqiu114 closed 1 year ago

diqiu114 commented 2 years ago

image 想要协议接受数据中含有回车换行符时,在接受数据界面中直接显示为换行(不显示转义字符),但在发送时允许含有转义字符(因为在协议插件里,发送时无法直接以按Enter表示回车换行符)

Neutree commented 2 years ago

改下decode函数,return data.decode('utf-8')

diqiu114 commented 2 years ago

哇,可以了,好牛逼,太神奇了 冒昧的问下,这两个函数是干什么的,以及怎么用? def decode(data): return data

def encode(data): return data

Neutree commented 2 years ago

就是把收到的数据通过这段代码解码,return回去的就是最终显示的内容,参数传进来的就是收到的字节数据。

代码是python语法,参数是bytes类型,我这里就是将bytes类型的字节数据转换为str类型的字符串,用了bytes_data.decode("utf-8")函数,utf-8是字符编码,也就是说你甚至可以发送emoji表情什么的🍊 🍇 😀 😅 😇,你也可以在函数里面进行其它操作,只要符合python语法就可以, 比如在后面加上一串字符串return data.decode("utf-8") + "\n==== hello ====="