添加根据托盘号获取托盘类型的方法,更新主窗口以支持上料操作的对话框和托盘类型选择,完成上料下料的按钮操作。
This commit is contained in:
parent
27f844da9c
commit
4b214ee4a6
@ -61,6 +61,31 @@ class PalletTypeDAO:
|
|||||||
logging.error(f"获取托盘类型失败: {str(e)}")
|
logging.error(f"获取托盘类型失败: {str(e)}")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
def get_pallet_type_by_pallet_id(self, pallet_id):
|
||||||
|
"""根据托盘号获取托盘类型
|
||||||
|
|
||||||
|
Args:
|
||||||
|
pallet_id: 托盘号
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: 托盘类型信息,未找到则返回None
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
sql = """
|
||||||
|
SELECT DISTINCT sort_order
|
||||||
|
FROM pallet_archives t1
|
||||||
|
LEFT JOIN pallet_types t2 ON t1.type_id = t2.id
|
||||||
|
WHERE pallet_id = ? AND t1.is_deleted = FALSE
|
||||||
|
"""
|
||||||
|
params = (pallet_id,)
|
||||||
|
self.db.cursor.execute(sql, params)
|
||||||
|
row = self.db.cursor.fetchone()
|
||||||
|
if row:
|
||||||
|
return row[0]
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"获取托盘类型失败: {str(e)}")
|
||||||
|
return None
|
||||||
|
|
||||||
def get_pallet_types_by_operation(self, operation_type, include_disabled=False):
|
def get_pallet_types_by_operation(self, operation_type, include_disabled=False):
|
||||||
"""根据操作类型获取托盘类型
|
"""根据操作类型获取托盘类型
|
||||||
|
|
||||||
|
|||||||
BIN
db/jtDB.db
BIN
db/jtDB.db
Binary file not shown.
@ -102,3 +102,14 @@ INSERT OR IGNORE INTO pallet_types (
|
|||||||
('小型托盘', 'output', '小型下料托盘', TRUE, 5, CURRENT_TIMESTAMP, 'system'),
|
('小型托盘', 'output', '小型下料托盘', TRUE, 5, CURRENT_TIMESTAMP, 'system'),
|
||||||
('大型托盘', 'output', '大型下料托盘', TRUE, 6, CURRENT_TIMESTAMP, 'system');
|
('大型托盘', 'output', '大型下料托盘', TRUE, 6, CURRENT_TIMESTAMP, 'system');
|
||||||
|
|
||||||
|
|
||||||
|
-- 创建托盘档案
|
||||||
|
create table if not exists pallet_archives (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
pallet_id VARCHAR(50) ,
|
||||||
|
type_id VARCHAR(50),
|
||||||
|
create_time TIMESTAMP ,
|
||||||
|
create_by VARCHAR(50) ,
|
||||||
|
update_time TIMESTAMP,
|
||||||
|
update_by VARCHAR(50)
|
||||||
|
)
|
||||||
@ -285,13 +285,13 @@ class MainWindowUI(QMainWindow):
|
|||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.input_button = QPushButton("上料")
|
# self.input_button = QPushButton("上料")
|
||||||
self.input_button.setFont(self.normal_font)
|
# self.input_button.setFont(self.normal_font)
|
||||||
self.input_button.setStyleSheet(button_style + "background-color: #e3f2fd; border: 1px solid #2196f3;")
|
# self.input_button.setStyleSheet(button_style + "background-color: #e3f2fd; border: 1px solid #2196f3;")
|
||||||
|
|
||||||
self.output_button = QPushButton("下料")
|
# self.output_button = QPushButton("下料")
|
||||||
self.output_button.setFont(self.normal_font)
|
# self.output_button.setFont(self.normal_font)
|
||||||
self.output_button.setStyleSheet(button_style + "background-color: #fff8e1; border: 1px solid #ffc107;")
|
# self.output_button.setStyleSheet(button_style + "background-color: #fff8e1; border: 1px solid #ffc107;")
|
||||||
|
|
||||||
self.start_button = QPushButton("开始")
|
self.start_button = QPushButton("开始")
|
||||||
self.start_button.setFont(self.normal_font)
|
self.start_button.setFont(self.normal_font)
|
||||||
@ -302,10 +302,10 @@ class MainWindowUI(QMainWindow):
|
|||||||
self.stop_button.setStyleSheet(button_style + "background-color: #ffebee; border: 1px solid #f44336;")
|
self.stop_button.setStyleSheet(button_style + "background-color: #ffebee; border: 1px solid #f44336;")
|
||||||
|
|
||||||
# 使用网格布局排列按钮
|
# 使用网格布局排列按钮
|
||||||
self.button_layout.addWidget(self.input_button, 0, 0)
|
# self.button_layout.addWidget(self.input_button, 0, 0)
|
||||||
self.button_layout.addWidget(self.output_button, 0, 1)
|
# self.button_layout.addWidget(self.output_button, 0, 1)
|
||||||
self.button_layout.addWidget(self.start_button, 0, 2)
|
self.button_layout.addWidget(self.start_button, 0, 1)
|
||||||
self.button_layout.addWidget(self.stop_button, 0, 3)
|
self.button_layout.addWidget(self.stop_button, 0, 2)
|
||||||
|
|
||||||
self.control_layout.addWidget(self.button_container)
|
self.control_layout.addWidget(self.button_container)
|
||||||
|
|
||||||
|
|||||||
@ -150,3 +150,14 @@ class PalletTypeManager:
|
|||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
def get_pallet_type_by_pallet_id(self, pallet_id):
|
||||||
|
"""根据托盘号获取托盘类型
|
||||||
|
|
||||||
|
Args:
|
||||||
|
pallet_id: 托盘号
|
||||||
|
"""
|
||||||
|
result = self.dao.get_pallet_type_by_pallet_id(pallet_id)
|
||||||
|
if result:
|
||||||
|
return result
|
||||||
|
else:
|
||||||
|
return None
|
||||||
@ -179,8 +179,8 @@ class MainWindow(MainWindowUI):
|
|||||||
self.tray_edit.activated.connect(self.load_finished_inspection_data) # 当用户选择一项时触发
|
self.tray_edit.activated.connect(self.load_finished_inspection_data) # 当用户选择一项时触发
|
||||||
|
|
||||||
# 连接按钮事件
|
# 连接按钮事件
|
||||||
self.input_button.clicked.connect(self.handle_input)
|
# self.input_button.clicked.connect(self.handle_input)
|
||||||
self.output_button.clicked.connect(self.handle_output)
|
# self.output_button.clicked.connect(self.handle_output)
|
||||||
self.start_button.clicked.connect(self.handle_start)
|
self.start_button.clicked.connect(self.handle_start)
|
||||||
self.stop_button.clicked.connect(self.handle_stop)
|
self.stop_button.clicked.connect(self.handle_stop)
|
||||||
|
|
||||||
@ -381,26 +381,93 @@ class MainWindow(MainWindowUI):
|
|||||||
modbus.close_client(client)
|
modbus.close_client(client)
|
||||||
|
|
||||||
def handle_start(self):
|
def handle_start(self):
|
||||||
"""处理启动按钮点击事件"""
|
"""
|
||||||
modbus = ModbusUtils()
|
处理开始按钮点击事件
|
||||||
client = modbus.get_client()
|
"""
|
||||||
try:
|
# 创建对话框
|
||||||
# 启动 D1 寄存器写入 1
|
dialog = QDialog(self)
|
||||||
if not modbus.write_register_until_success(client, 1, 1):
|
dialog.setWindowTitle("上料操作")
|
||||||
QMessageBox.information(self, "操作提示", "启动失败")
|
dialog.setFixedSize(300, 200)
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"启动操作失败: {str(e)}")
|
# 对话框布局
|
||||||
QMessageBox.critical(self, "错误", f"启动操作失败: {str(e)}")
|
layout = QVBoxLayout(dialog)
|
||||||
finally:
|
|
||||||
modbus.close_client(client)
|
# 添加提示信息
|
||||||
|
info_label = QLabel("请选择上料托盘类型:")
|
||||||
|
info_label.setFont(self.normal_font)
|
||||||
|
layout.addWidget(info_label)
|
||||||
|
|
||||||
|
# 添加托盘类型选择
|
||||||
|
pallet_combo = QComboBox()
|
||||||
|
pallet_combo.setFont(self.normal_font)
|
||||||
|
# 复制当前托盘类型选择器的内容
|
||||||
|
for i in range(1,4):
|
||||||
|
pallet_combo.addItem(str(i))
|
||||||
|
layout.addWidget(pallet_combo)
|
||||||
|
|
||||||
|
# 添加按钮
|
||||||
|
button_layout = QHBoxLayout()
|
||||||
|
confirm_button = QPushButton("确认")
|
||||||
|
confirm_button.setFont(self.normal_font)
|
||||||
|
confirm_button.setStyleSheet("background-color: #e3f2fd; border: 1px solid #2196f3; padding: 8px 16px; font-weight: bold; border-radius: 4px;")
|
||||||
|
|
||||||
|
cancel_button = QPushButton("取消")
|
||||||
|
cancel_button.setFont(self.normal_font)
|
||||||
|
cancel_button.setStyleSheet("padding: 8px 16px; font-weight: bold; border-radius: 4px;")
|
||||||
|
|
||||||
|
button_layout.addStretch()
|
||||||
|
button_layout.addWidget(confirm_button)
|
||||||
|
button_layout.addWidget(cancel_button)
|
||||||
|
layout.addLayout(button_layout)
|
||||||
|
|
||||||
|
# 连接按钮信号
|
||||||
|
confirm_button.clicked.connect(dialog.accept)
|
||||||
|
cancel_button.clicked.connect(dialog.reject)
|
||||||
|
|
||||||
|
# 显示对话框
|
||||||
|
result = dialog.exec()
|
||||||
|
|
||||||
|
# 如果用户确认,则执行上料操作
|
||||||
|
if result == QDialog.Accepted:
|
||||||
|
stow_num = pallet_combo.currentText()
|
||||||
|
|
||||||
|
# 获取托盘号对应的托盘类型
|
||||||
|
tray_id = self.tray_edit.currentText()
|
||||||
|
pallet_type = self.pallet_type_manager.get_pallet_type_by_pallet_id(tray_id)
|
||||||
|
if not pallet_type:
|
||||||
|
QMessageBox.warning(self, "错误", "未查到对应下料托盘类型")
|
||||||
|
return
|
||||||
|
|
||||||
|
# 执行Modbus操作
|
||||||
|
modbus = ModbusUtils()
|
||||||
|
client = modbus.get_client()
|
||||||
|
try:
|
||||||
|
success0 = modbus.write_register_until_success(client, 0, int(stow_num))
|
||||||
|
success1 = modbus.write_register_until_success(client, 1, int(pallet_type))
|
||||||
|
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 success1 and success3 :
|
||||||
|
# 创建状态标签并显示在右上角
|
||||||
|
self.show_operation_status("码垛层数", "input", stow_num)
|
||||||
|
else:
|
||||||
|
QMessageBox.information(self, "操作提示", "上料失败")
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"上料操作失败: {str(e)}")
|
||||||
|
QMessageBox.critical(self, "错误", f"上料操作失败: {str(e)}")
|
||||||
|
finally:
|
||||||
|
modbus.close_client(client)
|
||||||
|
|
||||||
def handle_stop(self):
|
def handle_stop(self):
|
||||||
"""处理停止按钮点击事件"""
|
"""处理停止按钮点击事件"""
|
||||||
modbus = ModbusUtils()
|
modbus = ModbusUtils()
|
||||||
client = modbus.get_client()
|
client = modbus.get_client()
|
||||||
try:
|
try:
|
||||||
# 停止 D1 寄存器写入 0
|
success2 = modbus.write_register_until_success(client, 2, 0)
|
||||||
if not modbus.write_register_until_success(client, 1, 0):
|
success3 = modbus.write_register_until_success(client, 3, 0)
|
||||||
|
# 停止 D1 寄存器2、3写入 0
|
||||||
|
if not success2 and not success3:
|
||||||
QMessageBox.information(self, "操作提示", "停止失败")
|
QMessageBox.information(self, "操作提示", "停止失败")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"停止操作失败: {str(e)}")
|
logging.error(f"停止操作失败: {str(e)}")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user