问题描述
在下面的代码中,我得到了不需要的符号/字符。例如,在这种情况下,我应该只收到“ boot.last”,而我却收到“ [0; 0mboot.last [0m”
ser = serial.Serial(
port='COM1',baudrate=9600,parity=serial.PARITY_NONE,stopbits=serial.STOPBITS_ONE,bytesize=serial.EIGHTBITS
)
ser.isopen()
print ('Enter your commands below.\r\nInsert "exit" to leave the application.')
userin=1
while 1 :
# get keyboard input
userin = input(">> ")
# Python 3 users
# input = input(">> ")
if userin == 'exit':
ser.close()
exit()
else:
# send the character to the device
# (note that I happend a \r\n carriage return and line Feed to the characters - this is requested by my device)
ser.write(userin.encode('utf-8') + '\r\n'.encode('utf-8'))
out = ''
# let's wait one second before reading output (let's give device time to answer)
time.sleep(1)
while ser.inWaiting() > 0:
out += ser.read(1).decode('ascii')
if out != '':
print(">>" + out)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)