Python使用线程来接收串口数据的示例
更新时间:2019年07月02日 21:28:26 作者:csdn_Flying
今天小编就为大家分享一篇Python使用线程来接收串口数据的示例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
如下所示:
#!/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'
以上这篇Python使用线程来接收串口数据的示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
关于Python中的向量相加和numpy中的向量相加效率对比
今天小编就为大家分享一篇关于Python中的向量相加和numpy中的向量相加效率对比,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2019-08-08
Pandas.concat连接DataFrame,Series的示例代码
本文主要介绍了Pandas.concat连接DataFrame,Series的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2023-02-02


最新评论