feat: 更新Modbus寄存器写入逻辑,调整托盘层数和状态反馈,优化加载对话框与主窗口的交互
This commit is contained in:
parent
26e835e25a
commit
f5c813e7a4
BIN
db/jtDB.db
BIN
db/jtDB.db
Binary file not shown.
@ -2,10 +2,10 @@ from pymodbus.client import ModbusTcpClient
|
||||
|
||||
client = ModbusTcpClient('localhost', port=5020)
|
||||
client.connect()
|
||||
client.write_registers(address=11, values=[2222])
|
||||
client.write_registers(address=13, values=[1])
|
||||
client.write_registers(address=11, values=[2223])
|
||||
client.write_registers(address=13, values=[0])
|
||||
|
||||
# client.write_registers(address=6, values=[1])
|
||||
client.write_registers(address=20, values=[1])
|
||||
# client.write_registers(address=5, values=[16])
|
||||
# 贴标完成
|
||||
# client.write_registers(address=24, values=[1])
|
||||
|
||||
@ -95,25 +95,26 @@ class LoadingDialog(LoadingDialogUI):
|
||||
if(xpack_response.get("status",False)):
|
||||
xpack = xpack_response['xpack']
|
||||
self.tray_input.setText(xpack)
|
||||
# 发送托盘号到主窗口
|
||||
from widgets.main_window import MainWindow
|
||||
main_window = self.parent
|
||||
if main_window and isinstance(main_window, MainWindow):
|
||||
# 检查托盘号是否已存在
|
||||
existed = False
|
||||
for i in range(main_window.tray_edit.count()):
|
||||
if main_window.tray_edit.itemText(i) == xpack:
|
||||
existed = True
|
||||
break
|
||||
self.pallet_tier_value.setText('3')
|
||||
# 发送托盘号到主窗
|
||||
from widgets.main_window import MainWindow
|
||||
main_window = self.parent
|
||||
if main_window and isinstance(main_window, MainWindow):
|
||||
# 检查托盘号是否已存在
|
||||
existed = False
|
||||
for i in range(main_window.tray_edit.count()):
|
||||
if main_window.tray_edit.itemText(i) == xpack:
|
||||
existed = True
|
||||
break
|
||||
|
||||
# 如果不存在,则添加
|
||||
if not existed:
|
||||
logging.info(f"添加托盘号到主窗口: {xpack}")
|
||||
main_window.tray_edit.addItem(xpack)
|
||||
# 如果不存在,则添加
|
||||
if not existed:
|
||||
logging.info(f"添加托盘号到主窗口: {xpack}")
|
||||
main_window.tray_edit.addItem(xpack)
|
||||
|
||||
# 设置当前选中的托盘号
|
||||
main_window.tray_edit.setCurrentText(xpack)
|
||||
logging.info(f"设置主窗口当前托盘号: {xpack}")
|
||||
# 设置当前选中的托盘号
|
||||
main_window.tray_edit.setCurrentText(xpack)
|
||||
logging.info(f"设置主窗口当前托盘号: {xpack}")
|
||||
|
||||
return order_info
|
||||
except Exception as e:
|
||||
|
||||
@ -27,7 +27,7 @@ from PySide6.QtWidgets import (
|
||||
QTableWidget, QMenu, QComboBox, QFormLayout, QDialog, QVBoxLayout, QHBoxLayout, QPushButton,
|
||||
QStatusBar, QSplitter, QFrame, QHeaderView
|
||||
)
|
||||
from PySide6.QtCore import Qt, QTimer, Slot
|
||||
from PySide6.QtCore import Qt, QTimer, Slot, Signal
|
||||
from PySide6.QtGui import QBrush, QColor
|
||||
import time
|
||||
|
||||
@ -47,6 +47,9 @@ from utils.serial_manager import SerialManager
|
||||
class MainWindow(MainWindowUI):
|
||||
"""主窗口"""
|
||||
|
||||
# 定义信号作为类变量
|
||||
loading_feedback_signal = Signal(str, str) # 参数:status_type, desc
|
||||
|
||||
def __init__(self, user_id=None, user_name=None, corp_name=None, corp_id=None):
|
||||
super().__init__(user_name)
|
||||
|
||||
@ -58,6 +61,13 @@ class MainWindow(MainWindowUI):
|
||||
self._loading_data_in_progress = False # 数据加载状态标志,防止循环调用
|
||||
self._current_order_code = None # 存储当前订单号
|
||||
|
||||
# 添加拆垛相关的属性
|
||||
self._current_stow_num = 0 # 当前拆垛层数
|
||||
self._loading_info = None # 存储上料对话框的信息
|
||||
|
||||
# 连接信号到槽
|
||||
self.loading_feedback_signal.connect(self._handle_loading_feedback_ui)
|
||||
|
||||
# 称重相关变量
|
||||
self._current_weight = None # 当前称重值(千克)
|
||||
self._last_weight_time = None # 最后一次称重时间
|
||||
@ -377,6 +387,18 @@ class MainWindow(MainWindowUI):
|
||||
from widgets.loading_dialog_widget import LoadingDialog
|
||||
dialog = LoadingDialog(parent=self,user_id=self.user_id,user_name=self.user_name,corp_id=self.corp_id)
|
||||
|
||||
# 如果已有上料信息,则填充到对话框
|
||||
if self._loading_info and self._current_stow_num > 0:
|
||||
dialog.order_input.setText(self._loading_info.get('order_code', ''))
|
||||
dialog.tray_input.setText(self._loading_info.get('tray_code', ''))
|
||||
dialog.axis_value.setText(self._loading_info.get('axis_value', '--'))
|
||||
dialog.quantity_value.setText(self._loading_info.get('quantity_value', '--'))
|
||||
dialog.weight_value.setText(self._loading_info.get('weight_value', '--'))
|
||||
dialog.pallet_tier_value.setText(str(self._current_stow_num))
|
||||
# 禁用输入框,防止修改
|
||||
dialog.order_input.setEnabled(False)
|
||||
dialog.tray_input.setEnabled(False)
|
||||
|
||||
# 连接订单号信号
|
||||
dialog.order_code_signal.connect(self.handle_order_code_received)
|
||||
|
||||
@ -390,19 +412,32 @@ class MainWindow(MainWindowUI):
|
||||
if stow_num == "--" or not stow_num:
|
||||
QMessageBox.warning(self, "错误", "未获取到托盘料信息,请重试")
|
||||
return
|
||||
|
||||
# 如果是新的上料操作(没有存储的信息或层数为0)
|
||||
if not self._loading_info or self._current_stow_num == 0:
|
||||
self._current_stow_num = int(stow_num)
|
||||
# 保存上料信息
|
||||
self._loading_info = {
|
||||
'order_code': dialog.order_input.text(),
|
||||
'tray_code': dialog.tray_input.text(),
|
||||
'axis_value': dialog.axis_value.text(),
|
||||
'quantity_value': dialog.quantity_value.text(),
|
||||
'weight_value': dialog.weight_value.text(),
|
||||
}
|
||||
|
||||
# 执行Modbus操作
|
||||
modbus = ModbusUtils()
|
||||
client = modbus.get_client()
|
||||
try:
|
||||
# 上料 D2 寄存器写入 1, D0 寄存器写入拆垛层数
|
||||
success0 = modbus.write_register_until_success(client, 0, int(stow_num))
|
||||
success0 = modbus.write_register_until_success(client, 0, self._current_stow_num)
|
||||
success2 = modbus.write_register_until_success(client, 2, 1)
|
||||
success3 = modbus.write_register_until_success(client, 3, 1)
|
||||
|
||||
# 上料 D2 寄存器写入 1, D0 寄存器写入拆垛层数
|
||||
if success0 and success2 and success3:
|
||||
# 创建状态标签并显示在右上角
|
||||
self.show_operation_status("拆垛层数", "input", stow_num)
|
||||
self.show_operation_status("拆垛层数", "input", str(self._current_stow_num))
|
||||
else:
|
||||
QMessageBox.information(self, "操作提示", "上料失败")
|
||||
except Exception as e:
|
||||
@ -482,15 +517,28 @@ class MainWindow(MainWindowUI):
|
||||
|
||||
def handle_start(self):
|
||||
"""
|
||||
2,3 寄存器设置为 1
|
||||
处理开始按钮点击事件
|
||||
每次点击开始时,将当前层数写入D0寄存器,并将D2,D3寄存器设置为1
|
||||
"""
|
||||
if self._current_stow_num <= 0:
|
||||
QMessageBox.warning(self, "提示", "请先进行上料操作")
|
||||
return
|
||||
|
||||
modbus = ModbusUtils()
|
||||
client = modbus.get_client()
|
||||
try:
|
||||
# 写入当前层数到D0寄存器
|
||||
success0 = modbus.write_register_until_success(client, 0, self._current_stow_num)
|
||||
success2 = modbus.write_register_until_success(client, 2, 1)
|
||||
success3 = modbus.write_register_until_success(client, 3, 1)
|
||||
|
||||
if success0 and success2 and success3:
|
||||
logging.info(f"开始操作:当前层数 {self._current_stow_num}")
|
||||
else:
|
||||
QMessageBox.warning(self, "错误", "开始操作失败")
|
||||
except Exception as e:
|
||||
logging.error(f"启动操作失败: {str(e)}")
|
||||
logging.error(f"开始操作失败: {str(e)}")
|
||||
QMessageBox.critical(self, "错误", f"开始操作失败: {str(e)}")
|
||||
finally:
|
||||
modbus.close_client(client)
|
||||
|
||||
@ -1851,8 +1899,26 @@ class MainWindow(MainWindowUI):
|
||||
client = modbus.get_client()
|
||||
modbus.write_register_until_success(client, 2, 0)
|
||||
modbus.close_client(client)
|
||||
self.show_operation_status("上料完成", "input", desc)
|
||||
QMessageBox.information(self, "上料操作", f"上料操作已完成: {desc}")
|
||||
|
||||
# 更新当前层数
|
||||
if self._current_stow_num > 0:
|
||||
self._current_stow_num -= 1
|
||||
if self._current_stow_num == 0:
|
||||
# 如果所有层都完成,清空上料信息
|
||||
self._loading_info = None
|
||||
logging.info("所有层拆垛完成,清空上料信息")
|
||||
else:
|
||||
logging.info(f"当前层拆垛完成,剩余层数: {self._current_stow_num}")
|
||||
|
||||
# 通过信号触发UI更新
|
||||
self.loading_feedback_signal.emit("input", desc)
|
||||
|
||||
def _handle_loading_feedback_ui(self, status_type, desc):
|
||||
"""在主线程中处理UI更新"""
|
||||
try:
|
||||
self.show_operation_status("上料完成", status_type, desc)
|
||||
except Exception as e:
|
||||
logging.error(f"处理UI更新失败: {str(e)}")
|
||||
|
||||
@Slot(int, str)
|
||||
def handle_unloading_feedback(self, status, desc):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user