首页 > 解决方案 > 在 Python 中从 ttl rs485 转换器读取数据

问题描述

我试图使用连接到 PC 的 ttl rs485 转换器和 ft232 串行转换器从智能电表读取数据。我尝试使用 Pyserial python 模块从串口读取数据并使用下面的代码,但我得到的唯一输出是(“b,”b,“,b),我想知道是否有任何错误在我的代码中!谢谢。

我使用的代码

    import serial

ser = serial.Serial(
    port= 'COM5',
    baudrate= 9600,

    parity=serial.PARITY_EVEN,

    stopbits=serial.STOPBITS_ONE,

    bytesize=serial.EIGHTBITS,
    timeout= 2 
)

print("connected to: " + ser.portstr, "Please wait" )
print('COM5 is now Open!')
ser.flushInput()
ser.flushOutput()

while True:
    data = ser.readline()
    print(data)

我得到的输出

connected to: COM5 Please wait
COM5 is now Open!
b''
b''
b''
b''
b''

标签: pythonpyserialrs485

解决方案


推荐阅读