cushy-serial


Namecushy-serial JSON
Version 1.1.1 PyPI version JSON
download
home_pagehttps://github.com/Undertone0809/cushy-serial
SummaryA lightweight serial library
upload_time2023-03-12 12:35:49
maintainer
docs_urlNone
authorZeeland
requires_python
licenseApache 2.0
keywords serial cushy-serial
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <h1 align="center">
    cushy-serial
</h1>
<p align="center">
  <strong>一个轻量级的Python Serial框架</strong>
</p>

<p align="center">
    <a target="_blank" href="">
        <img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg?label=license" />
    </a>
    <a target="_blank" href=''>
        <img src="https://static.pepy.tech/personalized-badge/broadcast-service?period=total&units=international_system&left_color=grey&right_color=blue&left_text=Downloads/Total"/>
   </a>
    <a target="_blank" href=''>
        <img src="https://static.pepy.tech/personalized-badge/broadcast-service?period=month&units=international_system&left_color=grey&right_color=blue&left_text=Downloads/Week"/>
   </a>
</p>

# 简介
cushy-serial是一个轻量级的Serial框架,初衷是希望使Serial编程变得更加简单、快捷,因此,相较于传统的pyserial,该框架可以更加快速地构建起一个serial程序。

# 主要特性

- 兼容pyserial的所有特性
- 自定义serial消息异步回调,无需花费精力在多线程上
- 方便实现和管理多个serial连接
- 可自定义消息协议,兼容性强

# 快速上手
```bash
pip install cushy-serial --upgrade 
```

- 下面是一个简单的serial程序,当python客户端接收到来自串口的信息时会自动回调
```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的所有功能。
 
- 运行结果如下

<img src="https://zeeland-bucket.oss-cn-beijing.aliyuncs.com/images/20230310173226.png"/>


- 如果你想要执行定时任务,`CushySerial`也提供了相关的解决方案,你可以方便的轮询发送指令,并获取来自串口的信息,示例如下:

```python
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包解析功能,减少在包解析上所花费的工作
- [ ] 提供相关持久化解决方案
- [ ] 提供数据流监控,提高数据稳定性
- [ ] 提供更加细力度的数据包调控,降低丢包率
- [x] 提供串口定时任务调度
- [ ] 完善单元测试

# 贡献
如果你想为这个项目做贡献,你可以提交pr或issue。我很高兴看到更多的人参与并优化它。

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Undertone0809/cushy-serial",
    "name": "cushy-serial",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "serial,cushy-serial",
    "author": "Zeeland",
    "author_email": "zeeland@foxmail.com",
    "download_url": "https://files.pythonhosted.org/packages/0c/ed/00964903398b486eb607355253da4500778dfdde9e9ba135abd7358b1f7d/cushy-serial-1.1.1.tar.gz",
    "platform": null,
    "description": "<h1 align=\"center\">\r\n    cushy-serial\r\n</h1>\r\n<p align=\"center\">\r\n  <strong>\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684Python Serial\u6846\u67b6</strong>\r\n</p>\r\n\r\n<p align=\"center\">\r\n    <a target=\"_blank\" href=\"\">\r\n        <img src=\"https://img.shields.io/badge/License-Apache%202.0-blue.svg?label=license\" />\r\n    </a>\r\n    <a target=\"_blank\" href=''>\r\n        <img src=\"https://static.pepy.tech/personalized-badge/broadcast-service?period=total&units=international_system&left_color=grey&right_color=blue&left_text=Downloads/Total\"/>\r\n   </a>\r\n    <a target=\"_blank\" href=''>\r\n        <img src=\"https://static.pepy.tech/personalized-badge/broadcast-service?period=month&units=international_system&left_color=grey&right_color=blue&left_text=Downloads/Week\"/>\r\n   </a>\r\n</p>\r\n\r\n# \u7b80\u4ecb\r\ncushy-serial\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684Serial\u6846\u67b6\uff0c\u521d\u8877\u662f\u5e0c\u671b\u4f7fSerial\u7f16\u7a0b\u53d8\u5f97\u66f4\u52a0\u7b80\u5355\u3001\u5feb\u6377\uff0c\u56e0\u6b64\uff0c\u76f8\u8f83\u4e8e\u4f20\u7edf\u7684pyserial\uff0c\u8be5\u6846\u67b6\u53ef\u4ee5\u66f4\u52a0\u5feb\u901f\u5730\u6784\u5efa\u8d77\u4e00\u4e2aserial\u7a0b\u5e8f\u3002\r\n\r\n# \u4e3b\u8981\u7279\u6027\r\n\r\n- \u517c\u5bb9pyserial\u7684\u6240\u6709\u7279\u6027\r\n- \u81ea\u5b9a\u4e49serial\u6d88\u606f\u5f02\u6b65\u56de\u8c03\uff0c\u65e0\u9700\u82b1\u8d39\u7cbe\u529b\u5728\u591a\u7ebf\u7a0b\u4e0a\r\n- \u65b9\u4fbf\u5b9e\u73b0\u548c\u7ba1\u7406\u591a\u4e2aserial\u8fde\u63a5\r\n- \u53ef\u81ea\u5b9a\u4e49\u6d88\u606f\u534f\u8bae\uff0c\u517c\u5bb9\u6027\u5f3a\r\n\r\n# \u5feb\u901f\u4e0a\u624b\r\n```bash\r\npip install cushy-serial --upgrade \r\n```\r\n\r\n- \u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684serial\u7a0b\u5e8f\uff0c\u5f53python\u5ba2\u6237\u7aef\u63a5\u6536\u5230\u6765\u81ea\u4e32\u53e3\u7684\u4fe1\u606f\u65f6\u4f1a\u81ea\u52a8\u56de\u8c03\r\n```python\r\nfrom cushy_serial import CushySerial\r\n\r\nserial = CushySerial(\"COM1\", 9600)\r\nserial.send(\"I am python client\")\r\n\r\n\r\n@serial.on_message()\r\ndef handle_serial_message(msg: bytes):\r\n    str_msg = msg.decode(\"utf-8\")\r\n    print(f\"[serial] rec msg: {str_msg}\")\r\n\r\n```\r\n\r\n> \u9700\u8981\u8bf4\u660e\u7684\u662f\uff0cCushySerial\u517c\u5bb9\u4e86Serial\u4e2d\u6240\u6709\u7684\u529f\u80fd\uff0c\u56e0\u6b64\uff0c\u4f60\u53ef\u4ee5\u5728CushySerial\u4e2d\u4f7f\u7528Serial\u7684\u6240\u6709\u529f\u80fd\u3002\r\n \r\n- \u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\r\n\r\n<img src=\"https://zeeland-bucket.oss-cn-beijing.aliyuncs.com/images/20230310173226.png\"/>\r\n\r\n\r\n- \u5982\u679c\u4f60\u60f3\u8981\u6267\u884c\u5b9a\u65f6\u4efb\u52a1\uff0c`CushySerial`\u4e5f\u63d0\u4f9b\u4e86\u76f8\u5173\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u4f60\u53ef\u4ee5\u65b9\u4fbf\u7684\u8f6e\u8be2\u53d1\u9001\u6307\u4ee4\uff0c\u5e76\u83b7\u53d6\u6765\u81ea\u4e32\u53e3\u7684\u4fe1\u606f\uff0c\u793a\u4f8b\u5982\u4e0b\uff1a\r\n\r\n```python\r\nfrom cushy_serial import CushySerial, enable_log\r\n\r\nenable_log()\r\nserial = CushySerial(\"COM1\", 9600)\r\ninstruction = bytes([0x01, 0x06, 0x00, 0x7F, 0x00, 0x01, 0x79, 0xD2])\r\n\r\n# msg\u4e3a\u4f60\u8981\u8f6e\u8be2\u53d1\u9001\u7684\u6307\u4ee4\uff0cinterval\u4e3a\u8f6e\u8be2\u7684\u65f6\u95f4\u95f4\u9694\uff0ctimes\u4e3a\u6267\u884c\u6b21\u6570\uff0c\u53ef\u4e0d\u586b\u5199\r\n@serial.polling_task(msg=instruction, interval=0.5, times=5)\r\ndef handle_rec_msg(rec_msg):\r\n    print(f\"[serial] rec polling message: {rec_msg}\")\r\n```\r\n\r\n\r\n# \u5f85\u529e\r\n\r\n- [ ] \u63d0\u4f9bpolling_task\u7684\u51fd\u6570\u56de\u8c03\u7248\u672c\r\n- [ ] \u63d0\u4f9bbytes\u5305\u89e3\u6790\u529f\u80fd\uff0c\u51cf\u5c11\u5728\u5305\u89e3\u6790\u4e0a\u6240\u82b1\u8d39\u7684\u5de5\u4f5c\r\n- [ ] \u63d0\u4f9b\u76f8\u5173\u6301\u4e45\u5316\u89e3\u51b3\u65b9\u6848\r\n- [ ] \u63d0\u4f9b\u6570\u636e\u6d41\u76d1\u63a7\uff0c\u63d0\u9ad8\u6570\u636e\u7a33\u5b9a\u6027\r\n- [ ] \u63d0\u4f9b\u66f4\u52a0\u7ec6\u529b\u5ea6\u7684\u6570\u636e\u5305\u8c03\u63a7\uff0c\u964d\u4f4e\u4e22\u5305\u7387\r\n- [x] \u63d0\u4f9b\u4e32\u53e3\u5b9a\u65f6\u4efb\u52a1\u8c03\u5ea6\r\n- [ ] \u5b8c\u5584\u5355\u5143\u6d4b\u8bd5\r\n\r\n# \u8d21\u732e\r\n\u5982\u679c\u4f60\u60f3\u4e3a\u8fd9\u4e2a\u9879\u76ee\u505a\u8d21\u732e\uff0c\u4f60\u53ef\u4ee5\u63d0\u4ea4pr\u6216issue\u3002\u6211\u5f88\u9ad8\u5174\u770b\u5230\u66f4\u591a\u7684\u4eba\u53c2\u4e0e\u5e76\u4f18\u5316\u5b83\u3002\r\n",
    "bugtrack_url": null,
    "license": "Apache 2.0",
    "summary": "A lightweight serial library",
    "version": "1.1.1",
    "split_keywords": [
        "serial",
        "cushy-serial"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0ced00964903398b486eb607355253da4500778dfdde9e9ba135abd7358b1f7d",
                "md5": "68a441a6c81bcb742722114ad84ac992",
                "sha256": "23a80ab3eff78c74b428774af58eeff5a2d2811cfcfb79ffc9f7e68488bf20b4"
            },
            "downloads": -1,
            "filename": "cushy-serial-1.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "68a441a6c81bcb742722114ad84ac992",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8321,
            "upload_time": "2023-03-12T12:35:49",
            "upload_time_iso_8601": "2023-03-12T12:35:49.391510Z",
            "url": "https://files.pythonhosted.org/packages/0c/ed/00964903398b486eb607355253da4500778dfdde9e9ba135abd7358b1f7d/cushy-serial-1.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-12 12:35:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "Undertone0809",
    "github_project": "cushy-serial",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "cushy-serial"
}
        
Elapsed time: 1.14943s