首页 > 解决方案 > 使用 pyserial 从 COM 端口读取数据,但输出为空

问题描述

我想从温度测量中读取数据。该设备通过 USB 连接到 PC。下面显示的代码仅提供此输出:

Serial port is open
b''
b''
b''
b''

有人对我有帮助吗,我已经查找了所有熟悉的问题及其解决方案,但没有一个可以帮助我:/

import serial

ser = serial.Serial(port='COM10', baudrate = 9600, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE,timeout=2)
try:
    ser.isOpen()
    print("Serial port is open")
except:
    print("ERROR")
    exit()

if(ser.isOpen()):
    try: 
        while( True ) :
            print(ser.read())
    except:
        print("error")
else:
    print("Cannot open serial port")

标签: pyserial

解决方案


推荐阅读