函数
# 定义读取测力计
ser_pressure = serial.Serial('com1', 9600, timeout=0.01)
def pressure_value(): # 测力计读取
ser_pressure.write(b'9"\r') # 向端口 数据
time.sleep(0.03) # 0.03
line = ser_pressure.readlines() # 读取一行数据
# print(line)
line = str(line)
# self.print(line)
line = line[-7:-2]
print(line)
return line
line = pressure_value() # 测力值
注意
要加上串口读取:ser_pressure = serial.Serial(‘com1’, 9600, timeout=0.01)
要按照设备的读取速度,定义时间延时。