我有一个循环将命令写入调制解调器,然后读取调制解调器,直到找到“OK”或“ERROR”。循环有效;一次。出于某种原因,一旦循环第一次完成,它就会中断。这是代码:
for modem in ser:
for port in modem:
print port.name
port.write('ati\r\n')
a=port.read(size=2000)
a=a.splitlines()
t=False
while t!=True:
for line in a:
print line
if line=='OK' or line=='ERROR' or '$GP' in line:
t=True
print 'howdy ho diddly doo'
我也像这样在里面制作了while循环:
while True:
for line in a:
print line
if line=='OK' or line=='ERROR' or '$GP' in line:
t=True
if t==True:
break
但是,对于这两个版本,结果如下:
COM71
ati
Manufacturer: Sierra Wireless, Incorporated
Model: MC8705
Revision: T3_5_2_1AP R517 CNSZXD00000128 2012/02/07 13:03:25
IMEI: 353567040568900
IMEI SV: 5
FSN: CC30942172510
3GPP Release 7
+GCAP: +CGSM,+FCLASS,+DS
OK
howdy ho diddly doo
>>> len(Ports) #Ports is ser (the list that I pass through for the function)
4
>>>
我可以肯定地知道 ser 的长度大于一,并且循环应该运行不止一次。我究竟做错了什么?