Python使用线程来接收串口数据的示例

作者:csdn_Flying 时间:2022-01-21 11:32:38 

如下所示:


#!/usr/bin/env python
import serial
import time
import thread

class MSerialPort:
message=''
def __init__(self,port,buand):
self.port=serial.Serial(port,buand)
if not self.port.isOpen():
self.port.open()
def port_open(self):
if not self.port.isOpen():
self.port.open()
def port_close(self):
self.port.close()
def send_data(self,data):
number=self.port.write(data)
return number
def read_data(self):
while True:
data=self.port.readline()
self.message+=data
if __name__=='__main__':
mSerial=MSerialPort('/dev/ttyACM0',9600)
thread.start_new_thread(mSerial.read_data,())
while True:
time.sleep(1)
print mSerial.message
print 'next line'

来源:https://blog.csdn.net/u010918541/article/details/50839578

标签:Python,线程,接收,串口,数据
0
投稿

猜你喜欢

  • ORCLE 表中列的修改

    2009-07-28 10:42:00
  • 配置SQL Server文件组对应不同的RAID系统

    2009-01-04 14:31:00
  • python 实时调取摄像头的示例代码

    2021-10-17 06:07:52
  • 使用Python实现分别输出每个数组

    2021-10-30 00:28:49
  • python 装饰器详解与应用范例

    2022-03-18 01:06:55
  • Python爬取国外天气预报网站的方法

    2022-02-22 00:39:07
  • Oracle查看逻辑读、物理读资源占用排行的SQL语句

    2023-06-25 23:53:53
  • Select的OnChange()事件

    2009-03-03 12:40:00
  • python_tkinter弹出对话框创建2

    2023-10-17 06:27:29
  • Design IT. (3),看不懂数据

    2009-02-11 10:56:00
  • python搭建虚拟环境的步骤详解

    2021-10-05 14:42:31
  • 细线表格的处理

    2008-08-06 12:53:00
  • Python爬虫之用Xpath获取关键标签实现自动评论盖楼抽奖(二)

    2021-02-11 00:58:03
  • SQL server使用自定义函数以及游标

    2011-11-03 17:26:27
  • oracle下实现恢复一个丢失的数据文件的代码

    2009-03-02 11:02:00
  • 利用XMLHTTP批量生成静态页的函数

    2008-09-10 11:07:00
  • Python区块链创建Genesis Block教程

    2022-04-17 10:44:15
  • 解决PyTorch与CUDA版本不匹配的问题

    2023-12-20 14:41:15
  • 详解CentOS升级Python2.6到Python2.7并安装pip

    2023-06-13 18:59:45
  • 利用python实现逐步回归

    2023-10-05 19:24:27
  • asp之家 网络编程 m.aspxhome.com