Python使用線程來接收串口數(shù)據(jù)的示例
更新時間:2019年07月02日 21:28:26 作者:csdn_Flying
今天小編就為大家分享一篇Python使用線程來接收串口數(shù)據(jù)的示例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
如下所示:
#!/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使用線程來接收串口數(shù)據(jù)的示例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
python實(shí)現(xiàn)對svn操作及信息獲取
這篇文章主要介紹了python實(shí)現(xiàn)對svn的操作及信息獲取示例過程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步2021-10-10Django request.META.get()獲取不到header頭的原因分析
這篇文章主要介紹了Django request.META.get()獲取不到header頭的原因分析,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-04-04python爬蟲數(shù)據(jù)保存到mongoDB的實(shí)例方法
在本篇文章里小編給大家整理的是一篇關(guān)于python爬蟲數(shù)據(jù)保存到mongoDB的實(shí)例方法,有需要的朋友們可以參考下。2020-07-07Python實(shí)現(xiàn)企業(yè)微信機(jī)器人每天定時發(fā)消息實(shí)例
這篇文章主要介紹了Python實(shí)現(xiàn)企業(yè)微信機(jī)器人每天定時發(fā)消息實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02JupyterNotebook 如何調(diào)整輸出窗口的顯示效果
這篇文章主要介紹了JupyterNotebook 輸出窗口的顯示效果調(diào)整實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09