From 08f205c6b386b5f473ad345770cbb508653d5977 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Tue, 26 Apr 2022 00:21:59 +0200 Subject: [PATCH] wait more time for modemPool reset --- main.py | 5 ++--- modems/ModemPool.py | 26 ++++++++++++++++++-------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index d371c14..4402986 100644 --- a/main.py +++ b/main.py @@ -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) diff --git a/modems/ModemPool.py b/modems/ModemPool.py index 9586b64..1c99278 100644 --- a/modems/ModemPool.py +++ b/modems/ModemPool.py @@ -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()