feat: 修复扫码器 BUG

This commit is contained in:
zhu-mengmeng 2025-06-30 17:35:19 +08:00
parent 7a2351cbe6
commit 486cdb0cad
3 changed files with 23 additions and 7 deletions

View File

@ -90,6 +90,6 @@
}
},
"electricity": {
"auto_start": false
"auto_start": true
}
}

View File

@ -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,))

View File

@ -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()