网络编程
位置:首页>> 网络编程>> Python编程>> python 串口读取+存储+输出处理实例

python 串口读取+存储+输出处理实例

作者:zh-hao  发布时间:2023-03-30 01:46:26 

标签:python,串口读取,存储,输出

研究了一晚上的成果。


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

来源:https://blog.csdn.net/xiqian1513/article/details/87927993

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com