如何在Python(数字测斜仪)中读取串行数据

时间:2019-03-26 08:45:39

标签: python python-3.x pyserial

如何在Python(数字测斜仪)中读取串行数据。

这是文档:

enter image description here

这是我的代码:

import binascii
import serial

SERIAL_PORT = 'COM1'
SERIAL_RATE = 9600

def main():
    ser = serial.Serial(SERIAL_PORT, SERIAL_RATE)

    while True:
        if ser.isOpen():
            s = ser.read()
            hex_string = binascii.hexlify(s).decode('utf-8')
            print(hex_string)
        else:
            print("Can not open serial port")


if __name__ == "__main__":
    main()

ser = serial.Serial的输出(port = SERIAL_PORT,baudrate = SERIAL_RATE,bytesize = serial.EIGHTBITS,stopbits = serial.STOPBITS_ONE,parity = serial.PARITY_NONE,timeout = 1)

enter image description here

这是我使用出厂软件的时间 enter image description here

0 个答案:

没有答案