feat:当下料完成后,自增,不清空

This commit is contained in:
zhu-mengmeng 2025-07-20 08:57:15 +08:00
parent 67374c5513
commit dcc778ede6

View File

@ -2733,7 +2733,6 @@ class MainWindow(MainWindowUI):
modbus.write_register_until_success(client, 3, 0) modbus.write_register_until_success(client, 3, 0)
# 如果当前下料层数小于总层数则将层数加1并写入寄存器4 # 如果当前下料层数小于总层数则将层数加1并写入寄存器4
if self._current_unload_num < self._total_unload_num:
# 保存当前完成的层数用于消息显示 # 保存当前完成的层数用于消息显示
completed_tier = self._current_unload_num completed_tier = self._current_unload_num
@ -2752,30 +2751,7 @@ class MainWindow(MainWindowUI):
# 恢复开始按钮原始样式 # 恢复开始按钮原始样式
self.restore_start_button_style() self.restore_start_button_style()
else:
# 所有层都下料完成,重置寄存器和计数器
modbus.write_register_until_success(client, 3, 0) # 确保下料启动寄存器为0
modbus.write_register_until_success(client, 4, 0) # 重置下料层数寄存器为0
# 记录完成的信息用于消息显示
final_tier = self._current_unload_num
total_tier = self._total_unload_num
tray_code = self._current_unload_info.get('tray_code', '') if self._current_unload_info else ''
# 重置计数器和信息
self._current_unload_num = 0
# 不重置总层数,以便可以继续使用相同的总层数
# self._total_unload_num = 0
self._current_unload_info = None
logging.info(f"托盘 {tray_code} 的所有 {total_tier} 层下料完成,重置当前层数")
# 通过信号触发UI更新而不是直接操作UI
message = f"托盘 {tray_code} 的所有 {total_tier} 层下料已全部完成"
self.unloading_feedback_signal.emit("output", message)
# 恢复开始按钮原始样式
self.restore_start_button_style()
except Exception as e: except Exception as e:
logging.error(f"处理下料反馈时发生错误: {str(e)}") logging.error(f"处理下料反馈时发生错误: {str(e)}")
# 不在这里显示对话框,而是通过信号传递错误信息 # 不在这里显示对话框,而是通过信号传递错误信息
@ -3725,7 +3701,7 @@ class MainWindow(MainWindowUI):
self.print_tray_button.clicked.connect(lambda: self.handle_tray_complete(ismt=False)) self.print_tray_button.clicked.connect(lambda: self.handle_tray_complete(ismt=False))
# 打印选中行按钮 # 打印选中行按钮
self.print_row_button = QPushButton("打印选中行") self.print_row_button = QPushButton("打印")
self.print_row_button.setFont(self.normal_font) self.print_row_button.setFont(self.normal_font)
self.print_row_button.setStyleSheet(""" self.print_row_button.setStyleSheet("""
QPushButton { QPushButton {
@ -3880,6 +3856,25 @@ class MainWindow(MainWindowUI):
else: else:
QMessageBox.information(self, "成功", "托盘号已打印") QMessageBox.information(self, "成功", "托盘号已打印")
logging.info(f"托盘号 {tray_id} 已打印") logging.info(f"托盘号 {tray_id} 已打印")
# 向D12寄存器写入1触发打印
from utils.modbus_utils import ModbusUtils
modbus = ModbusUtils()
client = modbus.get_client()
if not client:
QMessageBox.critical(self, "错误", "无法连接到Modbus服务器")
return
try:
# 向D12寄存器写入1表示打印请求
success = modbus.write_register(client, 12, 1)
if success:
logging.info(f"已向D12寄存器写入1")
else:
QMessageBox.warning(self, "警告", "发送打印请求失败请检查PLC连接")
finally:
# 释放客户端连接
modbus.close_client(client)
else: else:
error_msg = response.get('message', '未知错误') error_msg = response.get('message', '未知错误')
QMessageBox.warning(self, "失败", f"标记托盘完成失败: {error_msg}") QMessageBox.warning(self, "失败", f"标记托盘完成失败: {error_msg}")