diff --git a/__pycache__/actions.cpython-312.pyc b/__pycache__/actions.cpython-312.pyc index 2dec727..a725fae 100644 Binary files a/__pycache__/actions.cpython-312.pyc and b/__pycache__/actions.cpython-312.pyc differ diff --git a/__pycache__/check_station.cpython-312.pyc b/__pycache__/check_station.cpython-312.pyc index d3d0e8f..80eace2 100644 Binary files a/__pycache__/check_station.cpython-312.pyc and b/__pycache__/check_station.cpython-312.pyc differ diff --git a/actions.py b/actions.py index 5f1d664..9be5efa 100644 --- a/actions.py +++ b/actions.py @@ -122,6 +122,16 @@ class DeviceAutomation: def init_driver(self): """初始化Appium驱动""" try: + try: + if not driver_utils.check_session_valid(self.driver, self.device_id): + logging.warning(f"设备 {self.device_id} 会话无效,尝试重新连接驱动...") + self.driver, self.wait = driver_utils.reconnect_driver(self.device_id, self.driver) + if not self.driver: + logging.error(f"设备 {self.device_id} 驱动重连失败") + return False + except Exception as inner_e: + logging.warning(f"设备 {self.device_id} 检查会话状态时出错: {str(inner_e)}") + return False # # 使用全局函数初始化驱动 # self.driver, self.wait = driver_utils.init_appium_driver(self.device_id) # 初始化页面对象 diff --git a/check_station.py b/check_station.py index 17f59c5..76b5b89 100644 --- a/check_station.py +++ b/check_station.py @@ -34,6 +34,17 @@ class CheckStation: # # 确保Appium服务器正在运行,不在运行则启动 # if not driver_utils.check_server_status(4723): # driver_utils.start_appium_server() + try: + if not driver_utils.check_session_valid(self.driver, self.device_id): + logging.warning(f"设备 {self.device_id} 会话无效,尝试重新连接驱动...") + self.driver, self.wait = driver_utils.reconnect_driver(self.device_id, self.driver) + if not self.driver: + logging.error(f"设备 {self.device_id} 驱动重连失败") + return False + except Exception as inner_e: + logging.warning(f"设备 {self.device_id} 检查会话状态时出错: {str(inner_e)}") + return False + # 检查应用是否成功启动 if driver_utils.is_app_launched(self.driver): @@ -82,6 +93,17 @@ class CheckStation: # return True def add_transition_point(self): """添加转点""" + try: + if not driver_utils.check_session_valid(self.driver, self.device_id): + logging.warning(f"设备 {self.device_id} 会话无效,尝试重新连接驱动...") + self.driver, self.wait = driver_utils.reconnect_driver(self.device_id, self.driver) + if not self.driver: + logging.error(f"设备 {self.device_id} 驱动重连失败") + return False + except Exception as inner_e: + logging.warning(f"设备 {self.device_id} 检查会话状态时出错: {str(inner_e)}") + return False + try: # 查找并点击添加转点按钮 add_transition_btn = self.wait.until( diff --git a/ck/device_b.py b/ck/device_b.py index 1185c13..755d75f 100644 --- a/ck/device_b.py +++ b/ck/device_b.py @@ -12,6 +12,7 @@ import globals.driver_utils as driver_utils import actions import check_station from check_station import get_excel_from_url +import globals.create_link as create_link PORT = "COM9" BAUD = 115200 @@ -24,6 +25,7 @@ RESPONSE_PAYLOAD = { def main() -> int: + create_link.setup_adb_wireless() driver, wait, device_id = DriverManager.get_driver() url = f"https://database.yuxindazhineng.com/team-bucket/69378c5b4f42d83d9504560d/前测点表/20260309/CDWZQ-2标-龙家沟左线大桥-0-11号墩-平原.xlsx" station_data = get_excel_from_url(url) @@ -49,7 +51,7 @@ def main() -> int: # station等于0时启动actions.py if station_value == 0: - print("\n🚀 站点编号为0,启动 actions.py") + print("🚀 站点编号为0,启动 actions.py\n") # 启动 actions.py app = actions.DeviceAutomation(driver=driver, wait=wait, device_id=device_id) app.run_automation() @@ -57,7 +59,7 @@ def main() -> int: # station大于0时启动check_station.py elif station_value > 0 and over_station_num < station_quantity and station_value not in over_station_list: - print(f"\n🚀 站点编号为{station_value},启动 check_station.py") + print(f"🚀 站点编号为{station_value},启动 check_station.py\n") # 启动 check_station.py # driver_utils.ensure_appium_server_running() app = check_station.CheckStation(driver, wait, device_id) diff --git a/globals/__pycache__/driver_utils.cpython-312.pyc b/globals/__pycache__/driver_utils.cpython-312.pyc index ba0ea22..5daf3b1 100644 Binary files a/globals/__pycache__/driver_utils.cpython-312.pyc and b/globals/__pycache__/driver_utils.cpython-312.pyc differ diff --git a/globals/driver_utils.py b/globals/driver_utils.py index 27941c1..e03e916 100644 --- a/globals/driver_utils.py +++ b/globals/driver_utils.py @@ -122,7 +122,7 @@ def init_appium_driver(device_id, app_package="com.bjjw.cjgc", app_activity=".ac options.automation_name = "UiAutomator2" options.no_reset = True options.auto_grant_permissions = True - options.new_command_timeout = 28800 + options.new_command_timeout = 3600 options.udid = device_id # 增加uiautomator2服务器启动超时时间