try to init modem one by one

This commit is contained in:
2022-03-03 13:08:31 +01:00
parent db82f042a0
commit f4c6528c5e
2 changed files with 25 additions and 21 deletions
+18 -21
View File
@@ -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)