python 串列埠讀取+儲存+輸出處理例項
阿新 • • 發佈:2020-01-09
研究了一晚上的成果。
import serial import win32com.client import matplotlib.pyplot as plt import numpy as np ser = serial.Serial("COM6",115200,bytesize = 8,timeout=0.5) # 開啟串列埠 print("我要開始了:") res=[] while (1): ch = ser.readline(1) result = '' hLen = len(ch) for i in range(hLen): hvol = ch[i] hhex = '%02x' % hvol result += hhex + ' ' sz=[] res.append(result) if len(res)==100: j=0 for i in range(len(res)-1): # 十六進位制轉十進位制 if "fc" in res[i]: print(i) sz.append(int(res[i + 1],16)*256+int(res[i],16)) #print(sz) else: continue print("asd") print(type(sz[1])) speaker = win32com.client.Dispatch("SAPI.SpVoice") speaker.Speak("請保持均勻呼吸") x = [] for i in range(0,len(sz)): x.append(i) plt.plot(x,sz) plt.show() print(res) break
以上這篇python 串列埠讀取+儲存+輸出處理例項就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援我們。