本文来自作者博客:https://www.blog.zeeland.cn/archives/rgoihgxcoci3项目地址:https://github.com/Undertone0809/cushy-serial/Introductioncushy-serial是一个轻量级的Serial框架。初衷是为了让串口编程更简单、更快捷。因此,与传统的pyserial相比,该框架可以更快速地构建串行程序。主要功能兼容pyserial的所有功能。自定义串口消息异步回调,无需在多线程上花费精力。提供串口定时任务,方便实现和管理多个串口连接。可自定义消息协议,兼容性强快速启动pipinstallrushy-serial--upgrade下面是一个简单的串口程序,当python客户端从串口接收到信息时,会自动回调fromcushy_serialimportCushySerialserial=CushySerial("COM1",9600)serial.send("Iampythonclient")@serial.on_message()defhandle_serial_message(msg:bytes):str_msg=msg.decode("utf-8")print(f[serial]recmsg:{str_msg}")需要注意的是CushySerial是兼容所有函数的,所以你可以在CushySerial中使用Serial的所有函数。运行结果如下
