cushy-serial
一个轻量级的Python Serial框架
简介
cushy-serial是一个轻量级的Serial框架,初衷是希望使Serial编程变得更加简单、快捷,因此,相较于传统的pyserial,该框架可以更加快速地构建起一个serial程序。
主要特性
- 兼容pyserial的所有特性
- 自定义serial消息异步回调,无需花费精力在多线程上
- 方便实现和管理多个serial连接
- 可自定义消息协议,兼容性强
快速上手
pip install cushy-serial --upgrade
- 下面是一个简单的serial程序,当python客户端接收到来自串口的信息时会自动回调
from cushy_serial import CushySerial
serial = CushySerial("COM1", 9600)
serial.send("I am python client")
@serial.on_message()
def handle_serial_message(msg: bytes):
str_msg = msg.decode("utf-8")
print(f"[serial] rec msg: {str_msg}")
需要说明的是,CushySerial兼容了Serial中所有的功能,因此,你可以在CushySerial中使用Serial的所有功能。
- 运行结果如下
- 如果你想要执行定时任务,
CushySerial也提供了相关的解决方案,你可以方便的轮询发送指令,并获取来自串口的信息,示例如下:
from cushy_serial import CushySerial, enable_log
enable_log()
serial = CushySerial("COM1", 9600)
instruction = bytes([0x01, 0x06, 0x00, 0x7F, 0x00, 0x01, 0x79, 0xD2])
# msg为你要轮询发送的指令,interval为轮询的时间间隔,times为执行次数,可不填写
@serial.polling_task(msg=instruction, interval=0.5, times=5)
def handle_rec_msg(rec_msg):
print(f"[serial] rec polling message: {rec_msg}")
待办
- 提供polling_task的函数回调版本
- 提供bytes包解析功能,减少在包解析上所花费的工作
- 提供相关持久化解决方案
- 提供数据流监控,提高数据稳定性
- 提供更加细力度的数据包调控,降低丢包率
- 提供串口定时任务调度
- 完善单元测试
贡献
如果你想为这个项目做贡献,你可以提交pr或issue。我很高兴看到更多的人参与并优化它。
Metadata
Release files for cushy-serial 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cushy-serial-1.1.1.tar.gz | 8.3 kB | Without provenance | Details for cushy-serial-1.1.1.tar.gz |
Release files / cushy-serial-1.1.1.tar.gz
| Download URL | cushy-serial-1.1.1.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
23a80ab3eff78c74b428774af58eeff5a2d2811cfcfb79ffc9f7e68488bf20b4
|
|
BLAKE2b-256 checksum How to use checksums |
0ced00964903398b486eb607355253da4500778dfdde9e9ba135abd7358b1f7d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.9
|
Security for cushy-serial 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.