我在使用我的程序时遇到了问题,无法读取超过一个字符,我似乎无法弄清楚我的程序出了什么问题。
import serial
ser = serial.Serial(
port='COM5',\
baudrate=9600,\
parity=serial.PARITY_NONE,\
stopbits=serial.STOPBITS_ONE,\
bytesize=serial.EIGHTBITS,\
timeout=0)
print("connected to: " + ser.portstr)
count=1
while True:
for line in ser.read():
print(str(count) + str(': ') + chr(line) )
count = count+1
ser.close()
这是我得到的结果
connected to: COM5
1: 1
2: 2
3: 4
4: 3
5: 1
事实上,我本来就期待这个。
connected to: COM5
1:12431
2:12431
类似上述内容,能够同时读取多个字符而不是逐个读取。