try to init modem one by one
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user