使用pyserial从串行端口输入数据

时间:2019-12-03 16:20:56

标签: python pyserial

我有一个连接到PC的体重秤,它正在通过串行端口传输数据。它突然停止工作,当我检查发送的体重秤数据时,只是b'\ xff'重复了很多次。 python无法对其进行解码。我的脚本是:

import serial
import struct
ser = serial.Serial("COM4", baudrate=9600)
readings = []
done = False
a=0
while not done:
    current_char = ser.read()
    print("va 1")
    readings.append(current_char)
    a=a+1
    if a==10:
        done = True
print (readings)
a=readings[0]

h=a.decode()
z=float(h)
print(type(z))
print(z)

是体重秤或我的脚本上的错误,我该如何解决。谢谢您的时间

0 个答案:

没有答案
相关问题