Meine SIM-Bank verfügt über 256 Steckplätze (8 Ports, 32 Steckplätze) und 8 serielle Ports sind an jedem Port der Box angeschlossen.
Wie Kann ich die Portnummer einer Bank erhalten, die 8 COM-Ports zugeordnet ist?
Code: Select all
import serial.tools.list_ports
import logging
import time
def execute_command(modem, command, wait_time=2):
try:
modem.write(f"{command}\r".encode())
time.sleep(wait_time)
return modem.readlines()
except serial.SerialException as e:
print(f"Error executing command {command} in {modem.port}: {str(e)}")
return []
try:
modem = serial.Serial("COM" + str(real_port), 115200, timeout=1)
for i in range(132, 164):
sub_modem.append(serial.Serial("COM" + str(i), 115200, timeout=1))
print(f"########## Real Port: {real_port} ##########")
for index, modem_cop in enumerate(sub_modem):
for port in range(1, 9):
formatted_string = "AT+SWIT{:02d}-{:04d}".format(port, 1)
response = execute_command(modem, formatted_string)
try:
operator = ''.join([line.decode('utf-8', errors='ignore') for line in response])
except UnicodeDecodeError as e:
print(f"Decoding error: {e}")
continue
if str("SWITCH OK") in operator:
try:
res_cop = execute_command(modem_cop, "AT+COPS=?")
try:
oper_cop = ''.join([line.decode('utf-8', errors='ignore').strip() for line in res_cop])
except UnicodeDecodeError as e:
print(f"Decoding error: {e}")
continue
except Exception as e:
print(e)
for index in enumerate(sub_modem):
sub_modem[index].close()
modem.close()
print(f"########## Real Port: {real_port} ##########")
logging.info(f"########## Real Port: {real_port} ##########")
except Exception as e:
print(f"Error: {e}")