添加获取托盘类型信息的方法,更新主窗口以支持托盘类型的选择和显示

This commit is contained in:
zhu-mengmeng 2025-06-11 08:39:18 +08:00
parent 4db59048a6
commit 27f844da9c
4 changed files with 48 additions and 13 deletions

View File

@ -103,7 +103,6 @@ class PalletTypeDAO:
'sort_order': row[5]
}
pallet_types.append(pallet_type)
return pallet_types
except Exception as e:
logging.error(f"获取托盘类型失败: {str(e)}")
@ -144,7 +143,27 @@ class PalletTypeDAO:
except Exception as e:
logging.error(f"获取托盘类型失败: {str(e)}")
return None
def get_pallet_type_by_type(self,pallet_type):
"""根据托盘类型获取托盘信息
Args:
pallet_type: 托盘类型
Returns:
dict: 托盘类型信息未找到则返回None
"""
try:
sql = """
SELECT id, type_name, operation_type, description, enabled, sort_order
FROM pallet_types
WHERE type_name = ? AND is_deleted = FALSE
"""
params = (pallet_type, )
self.db.cursor.execute(sql, params)
results = self.db.cursor.fetchall()
pallet_type_dict = {row[1]:row[5] for row in results}
return pallet_type_dict
except Exception as e:
logging.error(f"获取托盘类型失败: {str(e)}")
return {}
def create_pallet_type(self, data, username='system'):
"""创建托盘类型

Binary file not shown.

View File

@ -135,3 +135,18 @@ class PalletTypeManager:
if result:
self.reload_pallet_types()
return result
def get_pallet_type_by_type(self, pallet_type):
"""根据托盘类型值获取托盘数据
Args:
pallet_type: 托盘类型
Returns:
dict: 托盘明细, 没有返回None
"""
result = self.dao.get_pallet_type_by_type(pallet_type)
if result:
return result
else:
return None

View File

@ -254,7 +254,7 @@ class MainWindow(MainWindowUI):
# 创建对话框
dialog = QDialog(self)
dialog.setWindowTitle("上料操作")
dialog.setFixedSize(400, 250)
dialog.setFixedSize(300, 200)
# 对话框布局
layout = QVBoxLayout(dialog)
@ -302,10 +302,10 @@ class MainWindow(MainWindowUI):
modbus = ModbusUtils()
client = modbus.get_client()
try:
# 上料 D2 寄存器写入 1
if modbus.write_register_until_success(client, 2, 1):
# 上料 D2 寄存器写入 1 ,D0 寄存器写入托盘类型
if modbus.write_register_until_success(client, 2, 1) and modbus.write_register_until_success(client, 0, selected_type):
# 创建状态标签并显示在右上角
self.show_operation_status("上料", "input", selected_type)
self.show_operation_status("上料托盘", "input", selected_type)
else:
QMessageBox.information(self, "操作提示", "上料失败")
except Exception as e:
@ -319,7 +319,7 @@ class MainWindow(MainWindowUI):
# 创建对话框
dialog = QDialog(self)
dialog.setWindowTitle("下料操作")
dialog.setFixedSize(400, 250)
dialog.setFixedSize(300, 200)
# 对话框布局
layout = QVBoxLayout(dialog)
@ -362,15 +362,16 @@ class MainWindow(MainWindowUI):
# 如果用户确认,则执行下料操作
if result == QDialog.Accepted:
selected_type = pallet_combo.currentText()
# 获取托盘的排序,该顺序影响着下料寄存器的写入值 切记,需要和 PLC 确认沟通完成后才能修改排序值
pallets_dict = self.pallet_type_manager.get_pallet_type_by_type(selected_type)
# 执行Modbus操作
modbus = ModbusUtils()
client = modbus.get_client()
try:
# 下料 D3 寄存器写入 1
if modbus.write_register_until_success(client, 3, 1):
#TODO: 下料 D3 寄存器写入 1 D1 寄存器写入托盘类型
if modbus.write_register_until_success(client, 3, 1) and modbus.write_register_until_success(client, 1, pallets_dict.get(selected_type)):
# 创建状态标签并显示在右上角
self.show_operation_status("下料", "output", selected_type)
self.show_operation_status("下料托盘", "output", selected_type)
else:
QMessageBox.information(self, "操作提示", "下料失败")
except Exception as e: