From 27f844da9cc9c71101dcaa18c0bdadae01fccc69 Mon Sep 17 00:00:00 2001 From: zhu-mengmeng <15588200382@163.com> Date: Wed, 11 Jun 2025 08:39:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96=E6=89=98?= =?UTF-8?q?=E7=9B=98=E7=B1=BB=E5=9E=8B=E4=BF=A1=E6=81=AF=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E6=9B=B4=E6=96=B0=E4=B8=BB=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=E6=89=98=E7=9B=98=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E7=9A=84=E9=80=89=E6=8B=A9=E5=92=8C=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/pallet_type_dao.py | 23 +++++++++++++++++++++-- db/jtDB.db | Bin 40960 -> 40960 bytes utils/pallet_type_manager.py | 17 ++++++++++++++++- widgets/main_window.py | 21 +++++++++++---------- 4 files changed, 48 insertions(+), 13 deletions(-) diff --git a/dao/pallet_type_dao.py b/dao/pallet_type_dao.py index 00869e4..a8b0c3f 100644 --- a/dao/pallet_type_dao.py +++ b/dao/pallet_type_dao.py @@ -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'): """创建托盘类型 diff --git a/db/jtDB.db b/db/jtDB.db index 95c908a912e121cc71857d1a73676cf6b19c5e27..a75867c4a8be2892013d1b57c37e5c18653ac31a 100644 GIT binary patch delta 86 zcmV-c0IC0gzyg540+1U41(6&>1qA>uc8RfMqmKarvj~uF4FLv|kDVElkDWjP1(VR7 sSpfu-DxO&Z1CxZFSOEf)-JUWDRs#$GB^enB36mI~9g{YnGLvVYnXt*XrGuMuN}Mq diff --git a/utils/pallet_type_manager.py b/utils/pallet_type_manager.py index 57ff650..be86039 100644 --- a/utils/pallet_type_manager.py +++ b/utils/pallet_type_manager.py @@ -134,4 +134,19 @@ class PalletTypeManager: result = self.dao.toggle_pallet_type(pallet_type_id, enabled, username) if result: self.reload_pallet_types() - return result \ No newline at end of file + 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 \ No newline at end of file diff --git a/widgets/main_window.py b/widgets/main_window.py index 7cf4ce3..2be467b 100644 --- a/widgets/main_window.py +++ b/widgets/main_window.py @@ -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) @@ -358,19 +358,20 @@ class MainWindow(MainWindowUI): # 显示对话框 result = dialog.exec() - + # 如果用户确认,则执行下料操作 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: