Python Can';无法使用PySerial接收回复,但使用超级终端

Python Can';无法使用PySerial接收回复,但使用超级终端,python,pyserial,Python,Pyserial,我有一个设备(Pololu Wixel),我正试图通过USB串行连接与之通信。超级终端工作得很好,但我正在尝试使用Python以获得更大的灵活性。我可以向设备发送命令,但当我尝试接收时,我得到的只是刚刚发送的命令。但是,如果我打开超级终端,我将在那里收到对脚本发送的命令的回复。我的代码如下。我有点不知所措,看起来这应该是相当简单的。谢谢你的帮助 import serial import time ''' Go through 256 COM ports and try to open them

我有一个设备(Pololu Wixel),我正试图通过USB串行连接与之通信。超级终端工作得很好,但我正在尝试使用Python以获得更大的灵活性。我可以向设备发送命令,但当我尝试接收时,我得到的只是刚刚发送的命令。但是,如果我打开超级终端,我将在那里收到对脚本发送的命令的回复。我的代码如下。我有点不知所措,看起来这应该是相当简单的。谢谢你的帮助

import serial
import time

'''
Go through 256 COM ports and try to open them.
'ser' will be the highest port number. Fix this later.
'''

for i in range(256):

    currentPort = "COM" + str(i+1)

    try:
        ser = serial.Serial(currentPort,baudrate=115200,timeout=5)
        print("Success!!")
        print(ser.name)
    except:
        pass

print(ser.isOpen())
str = "batt"    #Command to request battery levels.
ser.write(str.encode())

x = ser.inWaiting()
print(x)

while ser.inWaiting() > 0:
    out = ser.readline()
    print(out.decode())
  • 在找到活动端口后添加中断
  • 尝试将不同的eol值传递给readline()、“\r”或“\r\n”

  • 我把它和这两个结合起来使用。非常感谢你!