From f4c6528c5e3b2966b5c6b9b90ef33d6d5fc1a396 Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Thu, 3 Mar 2022 13:08:31 +0100 Subject: [PATCH] try to init modem one by one --- main.py | 39 ++++++++++++++++++--------------------- pojo/serial_modem.py | 7 +++++++ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/main.py b/main.py index b34fe64..9b6a635 100644 --- a/main.py +++ b/main.py @@ -22,6 +22,7 @@ BAUDRATE = 115200 OTP_TIMEOUT = 70 is_finished = False commandor = Commandor() +contacts = [] card_pool = CardPool(CARD_POOL_PORT) @@ -69,16 +70,12 @@ def create_modem_for_port(port: str) -> Union[SerialModem, None]: serial_modem = None try: modem = GsmModem(port) - time.sleep(1) - modem.connect() - number = modem.ownNumber - logger.info("The SIM card phone number is:") - logger.info(number) - cmd = "AT+CCID\r" - response = modem.write(cmd, True) - ccid = response[0].split(" ")[1].replace("\"", "") - logger.info("The SIM card ccid is:" + ccid) - return SerialModem(modem=modem, ccid=ccid) + # time.sleep(1) + # modem.connect() + # number = modem.ownNumber + # logger.info("The SIM card phone number is:") + # logger.info(number) + return SerialModem(modem=modem) except Exception as ext: print(ext) return serial_modem @@ -140,16 +137,6 @@ def init_modems() -> list: serial_modem = create_modem_for_port(port) if serial_modem: modems.append(serial_modem) - # read the contact, and contact the 2 objects together - excel_reader = ExcelHelper() - contacts = excel_reader.read_contacts() - for index, modem in enumerate(modems): - contact = [contact for contact in contacts if contact.ccid == modem.ccid] - if len(contact) > 0: - modem.phone_number = contact[0].phone - modem.contact = contact[0] - else: - logger.info("contact not found for {}, position:{}".format(modem.ccid, index + 1)) return modems @@ -196,7 +183,17 @@ def start_book(): modem_pool.reset_all_modems() modem_list = init_modems() # create listeners for chaque modem - for modem in modem_list: + # read the contact, and contact the 2 objects together + excel_reader = ExcelHelper() + global contacts + contacts = excel_reader.read_contacts() + for index, modem in modem_list: + # get contact for current modem + modem.get_ccid() + contact = [contact for contact in contacts if contact.ccid == modem.ccid] + if len(contact) > 0: + modem.phone_number = contact[0].phone + modem.contact = contact[0] if modem.contact: commandor.start_page(modem.contact) start_to_handle_sms(modem) diff --git a/pojo/serial_modem.py b/pojo/serial_modem.py index b987db9..40fff8c 100644 --- a/pojo/serial_modem.py +++ b/pojo/serial_modem.py @@ -13,3 +13,10 @@ class SerialModem(): def __init__(self, modem: GsmModem, ccid: str = None): self.modem = modem self.ccid = ccid + + def get_ccid(self): + cmd = "AT+CCID\r" + self.modem.connect() + response = self.modem.write(cmd, True) + self.ccid = response[0].split(" ")[1].replace("\"", "") + print("The SIM card ccid is:" + self.ccid)