前言
代码(未完成)
import serial
import binascii
port = serial.Serial("/dev/ttyUSB0", baudrate=19200, timeout=3.0)
while True:
print("Please input the command:")
print("Modbus test...")
Single_measure_cmd ="\x02\x03\x00\x0F\x00\x02\xF4\x3B"
port.write(Single_measure_cmd)
rcv = port.read(16)
new_receive = int(binascii.hexlify(rcv[5:7]), 16)
print("The detected instance is " + str(new_receive) + " mm")