wait more time for modemPool reset

This commit is contained in:
2022-04-26 00:21:59 +02:00
parent 5748572cb5
commit 08f205c6b3
2 changed files with 20 additions and 11 deletions
+2 -3
View File
@@ -122,6 +122,5 @@ def get_proxy(phone_number):
if __name__ == '__main__':
# 修改起始行,结束行
# 第三个参数store等于0的时候是随机,传入1的时候是总店
start_book(32, 32, store=0)
# 修改起始行,结束行, 第三个参数store等于0的时候是随机,传入1的时候是总店
start_book(3, 3, store=0)
+18 -8
View File
@@ -33,11 +33,11 @@ class ModemPool:
def reset_all_modems(self):
self.logger.info("will reset modem pool")
for ser in self._serial_list:
# may encontre exception here, multi-access to serial port
time.sleep(2)
self._send_command("AT+CFUN=1,1\r", ser)
# wait for 10 second, so that the modem can init all the sims
time.sleep(10)
#等待4秒
time.sleep(4)
self._send_command("AT+CFUN=1,1\r", ser, 10)
#等待15秒,加载新的SIM卡
time.sleep(15)
def _generate_error_msg(self, slot_position, index, error: SIMError):
msg = "slot({}) SIM({}), error:{}".format(slot_position, index + 1,
@@ -105,13 +105,22 @@ class ModemPool:
else:
return True
def check_response(self, msg:str) -> bool:
print("msg is "+msg)
# if 'NOT READY' in msg:
# return False
if 'OK' in msg:
return True
else:
return False
def _send_command(self, cmd: str, ser, wait_time_in_s: int = 0) -> bytes:
ser.write(cmd.encode())
msg = None
try:
msg = ser.read(100)
count = 0
while 'OK' not in str(msg) and count < wait_time_in_s:
while not self.check_response(str(msg)) and count < wait_time_in_s:
time.sleep(1)
count = count + 1
msg = ser.read(100)
@@ -125,5 +134,6 @@ class ModemPool:
return self._send_command(cmd, ser, 120)
def close(self):
for serial in self._serial_list:
serial.close()
pass
# for serial in self._serial_list:
# serial.close()