python多个串口调用_Python多线程/多个进程读取串行端口

使用Python的pySerial库读取两个串口/dev/ttyS1和/dev/ttyS2,速率19200波特。串口持续活跃,需要并行读取。考虑使用threading、thread或multiprocessing库,但担心全局解释器锁(GIL)对IO密集型操作的影响。了解到GIL在读操作期间释放,因此可能不会造成太大影响。若使用multiprocessing,可能需要在嵌入式系统上交叉编译。理想的代码结构应使每个线程分别读取一个串口并写入缓冲区,然后进一步处理。同时询问是否multiprocessing需要多核CPU。
摘要由CSDN通过智能技术生成

I'm trying to write a python class utilizing parallel processing/threading for reading two serial ports(/dev/ttyS1 and /dev/ttyS2). Both of these ports are running at a 19200 baud rate and are constantly active. I used pySerial for this purpose.

Both of the read operations need to be run continuously and concurrently. I am wondering if should use the thread library or threading library or the multiprocessing library. I'm only worried because of the global interpreter lock which doesnt' give true threading ability for heavy IO operations. But if the global interpreter lock doesn't affect me then I will use the threading/thread module. However if it does then I would need to cross compile the python multiprocessing libraries because this is on an embedded system.

So my code would typically have

thread1 or process1 = reading ttyS1 and writing to a buffer after pe

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值