diff --git a/config/app_config.json b/config/app_config.json index 3871033..2786c98 100644 --- a/config/app_config.json +++ b/config/app_config.json @@ -90,6 +90,6 @@ } }, "electricity": { - "auto_start": false + "auto_start": true } } \ No newline at end of file diff --git a/utils/serial_manager.py b/utils/serial_manager.py index 151431a..9c2ae4b 100644 --- a/utils/serial_manager.py +++ b/utils/serial_manager.py @@ -272,6 +272,9 @@ class SerialManager: elif port_type == 'scanner': # 扫码器数据需要特殊处理 thread = threading.Thread(target=self._read_scanner_thread, args=(port_name,)) + thread.daemon = True + thread.start() + self.read_threads[port_name] = thread else: # 其他类型使用通用处理 thread = threading.Thread(target=self._read_thread, args=(port_name,)) diff --git a/widgets/main_window.py b/widgets/main_window.py index 68138fc..ae2c283 100644 --- a/widgets/main_window.py +++ b/widgets/main_window.py @@ -404,10 +404,13 @@ class MainWindow(MainWindowUI): # 重新打开已配置的串口 self.serial_manager.auto_open_configured_ports() + # 重新注册串口回调函数 + self.register_serial_callbacks() + # 重新加载托盘号 self.load_pallet_codes() - logging.info("设置已更新,重新加载配置并重新打开串口") + logging.info("设置已更新,重新加载配置并重新打开串口,已重新注册扫码器回调") def handle_input(self): """处理上料按钮点击事件""" @@ -2075,8 +2078,18 @@ class MainWindow(MainWindowUI): def handle_register_change(self, address, value): """处理寄存器变化""" logging.info(f"[处理] 寄存器D{address}变化: {value}") - # 这里可以添加通用寄存器变化处理逻辑 - + + # 当D11寄存器变为0时,复位D10寄存器为0 + if address == 11 and value == 0: + try: + logging.info("检测到D11寄存器变为0,正在复位D10寄存器") + modbus = ModbusUtils() + client = modbus.get_client() + modbus.write_register_until_success(client, 10, 0) + logging.info("成功复位D10寄存器为0") + modbus.close_client(client) + except Exception as e: + logging.error(f"复位D10寄存器失败: {str(e)}") @Slot(int, str) def handle_loading_feedback(self, status, desc): """处理上料信息反馈""" @@ -2256,8 +2269,8 @@ class MainWindow(MainWindowUI): self.error_1 = error_code self._update_error_status() - # 如果有故障,显示提示(对任何错误码都弹框) - if error_code > 0: + # 只有当错误码为1、2或3时才弹框提示 + if error_code in [1, 2, 3]: QMessageBox.warning(self, "机器人视觉报警", f"机器人视觉报警: {detailed_desc}") # 获取Modbus连接 modbus = ModbusUtils() @@ -2281,7 +2294,7 @@ class MainWindow(MainWindowUI): self._update_error_status() # 如果有故障,显示提示(对任何错误码都弹框) - if error_code > 0: + if error_code in [1, 2]: QMessageBox.warning(self, "滚筒线报警", f"滚筒线报警: {detailed_desc}") # 获取Modbus连接 modbus = ModbusUtils()