Python pyserial';当输出有许多行时,s readline无法读取最后几行
我正在尝试使用pyserial与一块板进行交互,我正在发送一些命令并等待它们的回复,我正在使用这段代码等待=>promptPython pyserial';当输出有许多行时,s readline无法读取最后几行,python,pyserial,Python,Pyserial,我正在尝试使用pyserial与一块板进行交互,我正在发送一些命令并等待它们的回复,我正在使用这段代码等待=>prompt # Waits till it finds the => prompt def s_uboot_prompt(ser): value = "" matcher = re.compile("\=\>") trymatcher = re.compile("try") while (not matcher.search(value)):
# Waits till it finds the => prompt
def s_uboot_prompt(ser):
value = ""
matcher = re.compile("\=\>")
trymatcher = re.compile("try")
while (not matcher.search(value)):
if( trymatcher.search(value.strip()) ):
print "******* Command failure. Exiting ..... **********"
ser.write("boot\r")
ser.close()
sys.exit(0)
value = ser.readline()
print value
time.sleep(2)
它适用于所有命令,但对于其中一个输出非常巨大的tftp命令,它永远无法读取最后几行和上面的代码循环。这有什么原因吗?我想不出任何合乎逻辑的理由。请注意,它无法阅读最后几行
thnks您是否尝试过不使用regexp并在while循环中打印所有行?我没有尝试过,但相同的代码在类似的电路板上工作了好几次!它突然停止工作了!我可以试试你说的,让我看看我会得到什么,它真的会永远循环吗?我可以想象它位于ser.readline()上,除非您将默认超时设置为其他值,而不是None。另外,巨大输出的最后几行是否包含
\n
字符,这是ser.readline()默认情况下返回任何内容所需的内容(除非超时)?我的时间为4!是的,它必须有新的生产线,因为它以前的工作,并在其他一些机器上工作!