parent
4b26c2963b
commit
77bb4e0281
|
|
@ -37,7 +37,7 @@ class WrenchGUI:
|
||||||
|
|
||||||
def __init__(self, root):
|
def __init__(self, root):
|
||||||
self.root = root
|
self.root = root
|
||||||
self.root.title("电动扳手自动拧紧系统")
|
self.root.title("智慧车间设备协同中台")
|
||||||
# 默认全屏显示
|
# 默认全屏显示
|
||||||
self.root.state('zoomed') # Windows全屏
|
self.root.state('zoomed') # Windows全屏
|
||||||
# 如果zoomed不支持,使用geometry设置全屏
|
# 如果zoomed不支持,使用geometry设置全屏
|
||||||
|
|
@ -91,7 +91,7 @@ class WrenchGUI:
|
||||||
# 检查测试模式
|
# 检查测试模式
|
||||||
self.check_test_mode()
|
self.check_test_mode()
|
||||||
|
|
||||||
# 初始化螺栓列表显示(确保始终可见)
|
# 初始化作业列表显示(确保始终可见)
|
||||||
self.update_bolt_list()
|
self.update_bolt_list()
|
||||||
|
|
||||||
# 加载设备列表
|
# 加载设备列表
|
||||||
|
|
@ -120,7 +120,7 @@ class WrenchGUI:
|
||||||
|
|
||||||
title_label = tk.Label(
|
title_label = tk.Label(
|
||||||
title_frame,
|
title_frame,
|
||||||
text="电动扳手自动拧紧系统",
|
text="智慧车间设备协同中台",
|
||||||
font=("微软雅黑", 20, "bold"),
|
font=("微软雅黑", 20, "bold"),
|
||||||
fg="white",
|
fg="white",
|
||||||
bg="#2c3e50"
|
bg="#2c3e50"
|
||||||
|
|
@ -276,7 +276,7 @@ class WrenchGUI:
|
||||||
device_select_inner = tk.Frame(col2_frame)
|
device_select_inner = tk.Frame(col2_frame)
|
||||||
device_select_inner.pack()
|
device_select_inner.pack()
|
||||||
|
|
||||||
tk.Label(device_select_inner, text="选择扳手:", font=("微软雅黑", 9)).pack(side=tk.LEFT, padx=(0, 5))
|
tk.Label(device_select_inner, text="选择设备:", font=("微软雅黑", 9)).pack(side=tk.LEFT, padx=(0, 5))
|
||||||
|
|
||||||
# 设备状态指示器(圆点)
|
# 设备状态指示器(圆点)
|
||||||
self.device_status_indicator = tk.Label(
|
self.device_status_indicator = tk.Label(
|
||||||
|
|
@ -348,10 +348,10 @@ class WrenchGUI:
|
||||||
# 创建右侧主容器(上下布局)
|
# 创建右侧主容器(上下布局)
|
||||||
right_container = tk.Frame(self.root)
|
right_container = tk.Frame(self.root)
|
||||||
right_container.grid(row=2, column=1, sticky="nsew", padx=(5, 10), pady=5)
|
right_container.grid(row=2, column=1, sticky="nsew", padx=(5, 10), pady=5)
|
||||||
# 配置行权重:日志区域可压缩,螺栓列表可压缩
|
# 配置行权重:日志区域可压缩,作业列表可压缩
|
||||||
right_container.grid_rowconfigure(0, weight=0) # 工单信息不扩展
|
right_container.grid_rowconfigure(0, weight=0) # 工单信息不扩展
|
||||||
right_container.grid_rowconfigure(1, weight=0) # 当前螺栓不扩展
|
right_container.grid_rowconfigure(1, weight=0) # 当前作业不扩展
|
||||||
right_container.grid_rowconfigure(2, weight=3) # 螺栓列表可扩展可压缩(主要区域)
|
right_container.grid_rowconfigure(2, weight=3) # 作业列表可扩展可压缩(主要区域)
|
||||||
right_container.grid_rowconfigure(3, weight=1, minsize=100) # 日志区域可压缩,最小100像素
|
right_container.grid_rowconfigure(3, weight=1, minsize=100) # 日志区域可压缩,最小100像素
|
||||||
right_container.grid_columnconfigure(0, weight=1)
|
right_container.grid_columnconfigure(0, weight=1)
|
||||||
|
|
||||||
|
|
@ -377,8 +377,8 @@ class WrenchGUI:
|
||||||
self.device_label = tk.Label(info_frame, text="扳手设备: --", font=("微软雅黑", 10), fg="#2c3e50")
|
self.device_label = tk.Label(info_frame, text="扳手设备: --", font=("微软雅黑", 10), fg="#2c3e50")
|
||||||
self.device_label.grid(row=1, column=2, sticky=tk.W, padx=5, pady=2)
|
self.device_label.grid(row=1, column=2, sticky=tk.W, padx=5, pady=2)
|
||||||
|
|
||||||
# 当前螺栓信息(上下布局,第二行)
|
# 当前作业信息(上下布局,第二行)
|
||||||
current_frame = tk.LabelFrame(right_container, text="当前螺栓", font=("微软雅黑", 12), padx=10, pady=10)
|
current_frame = tk.LabelFrame(right_container, text="当前作业", font=("微软雅黑", 12), padx=10, pady=10)
|
||||||
current_frame.grid(row=1, column=0, sticky="ew", padx=5, pady=5)
|
current_frame.grid(row=1, column=0, sticky="ew", padx=5, pady=5)
|
||||||
|
|
||||||
self.current_bolt_label = tk.Label(
|
self.current_bolt_label = tk.Label(
|
||||||
|
|
@ -414,11 +414,11 @@ class WrenchGUI:
|
||||||
self.progress_bar = ttk.Progressbar(progress_frame, mode='determinate', length=400)
|
self.progress_bar = ttk.Progressbar(progress_frame, mode='determinate', length=400)
|
||||||
self.progress_bar.pack(fill=tk.X, pady=5)
|
self.progress_bar.pack(fill=tk.X, pady=5)
|
||||||
|
|
||||||
# 螺栓列表(固定在"当前螺栓"下方、"操作控制"上方,可压缩但始终可见)
|
# 作业列表(固定在"当前作业"下方、"操作控制"上方,可压缩但始终可见)
|
||||||
# 创建螺栓列表框架
|
# 创建作业列表框架
|
||||||
list_frame = tk.LabelFrame(right_container, text="螺栓列表", font=("微软雅黑", 12), padx=10, pady=10)
|
list_frame = tk.LabelFrame(right_container, text="作业列表", font=("微软雅黑", 12), padx=10, pady=10)
|
||||||
list_frame.grid(row=2, column=0, sticky="nsew", padx=5, pady=5)
|
list_frame.grid(row=2, column=0, sticky="nsew", padx=5, pady=5)
|
||||||
# 螺栓列表通过right_container的row=2的weight=1来控制,可以压缩
|
# 作业列表通过right_container的row=2的weight=1来控制,可以压缩
|
||||||
# 设置最小高度,支持1920和1600分辨率
|
# 设置最小高度,支持1920和1600分辨率
|
||||||
self.root.update_idletasks()
|
self.root.update_idletasks()
|
||||||
screen_height = self.root.winfo_screenheight()
|
screen_height = self.root.winfo_screenheight()
|
||||||
|
|
@ -467,7 +467,7 @@ class WrenchGUI:
|
||||||
self.tree.bind("<B1-Motion>", self.on_drag_motion)
|
self.tree.bind("<B1-Motion>", self.on_drag_motion)
|
||||||
self.tree.bind("<ButtonRelease-1>", self.on_drag_release)
|
self.tree.bind("<ButtonRelease-1>", self.on_drag_release)
|
||||||
|
|
||||||
# 操作日志区域(移到右侧,放在螺栓列表下方)
|
# 操作日志区域(移到右侧,放在作业列表下方)
|
||||||
log_frame = tk.LabelFrame(right_container, text="操作日志", font=("微软雅黑", 9), padx=5, pady=3)
|
log_frame = tk.LabelFrame(right_container, text="操作日志", font=("微软雅黑", 9), padx=5, pady=3)
|
||||||
log_frame.grid(row=3, column=0, sticky="nsew", padx=5, pady=(0, 5))
|
log_frame.grid(row=3, column=0, sticky="nsew", padx=5, pady=(0, 5))
|
||||||
log_frame.grid_rowconfigure(0, weight=1)
|
log_frame.grid_rowconfigure(0, weight=1)
|
||||||
|
|
@ -689,7 +689,7 @@ class WrenchGUI:
|
||||||
time.sleep(self.poll_interval)
|
time.sleep(self.poll_interval)
|
||||||
|
|
||||||
def on_order_select(self, event):
|
def on_order_select(self, event):
|
||||||
"""工单选择事件处理 - 显示螺栓列表预览"""
|
"""工单选择事件处理 - 显示作业列表预览"""
|
||||||
selected = self.order_tree.selection()
|
selected = self.order_tree.selection()
|
||||||
if not selected:
|
if not selected:
|
||||||
return
|
return
|
||||||
|
|
@ -706,7 +706,7 @@ class WrenchGUI:
|
||||||
break
|
break
|
||||||
|
|
||||||
def preview_bolt_list(self, order_data):
|
def preview_bolt_list(self, order_data):
|
||||||
"""预览螺栓列表(认领前)"""
|
"""预览作业列表(认领前)"""
|
||||||
self.tree.delete(*self.tree.get_children())
|
self.tree.delete(*self.tree.get_children())
|
||||||
|
|
||||||
bolts = order_data.get('bolts', [])
|
bolts = order_data.get('bolts', [])
|
||||||
|
|
@ -743,7 +743,7 @@ class WrenchGUI:
|
||||||
self.drag_item = None
|
self.drag_item = None
|
||||||
|
|
||||||
def update_bolt_order(self):
|
def update_bolt_order(self):
|
||||||
"""更新螺栓顺序到work_order"""
|
"""更新作业顺序到work_order"""
|
||||||
if not self.work_order:
|
if not self.work_order:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -752,13 +752,13 @@ class WrenchGUI:
|
||||||
for item in self.tree.get_children():
|
for item in self.tree.get_children():
|
||||||
values = self.tree.item(item)['values']
|
values = self.tree.item(item)['values']
|
||||||
bolt_id = values[0]
|
bolt_id = values[0]
|
||||||
# 在原始螺栓列表中找到对应的螺栓
|
# 在原始作业列表中找到对应的作业
|
||||||
for bolt in self.work_order.get('bolts', []):
|
for bolt in self.work_order.get('bolts', []):
|
||||||
if bolt.get('bolt_id') == bolt_id:
|
if bolt.get('bolt_id') == bolt_id:
|
||||||
new_bolts.append(bolt)
|
new_bolts.append(bolt)
|
||||||
break
|
break
|
||||||
|
|
||||||
# 更新work_order中的螺栓顺序
|
# 更新work_order中的作业顺序
|
||||||
self.work_order['bolts'] = new_bolts
|
self.work_order['bolts'] = new_bolts
|
||||||
|
|
||||||
def claim_work_order(self):
|
def claim_work_order(self):
|
||||||
|
|
@ -799,7 +799,7 @@ class WrenchGUI:
|
||||||
if values[0] == trace_id and values[1] == process_id:
|
if values[0] == trace_id and values[1] == process_id:
|
||||||
self.order_tree.delete(item)
|
self.order_tree.delete(item)
|
||||||
break
|
break
|
||||||
self.log(f"✅ 成功认领工单: {trace_id} - {process_id}(可拖拽排序螺栓)", "SUCCESS")
|
self.log(f"✅ 成功认领工单: {trace_id} - {process_id}(可拖拽排序作业)", "SUCCESS")
|
||||||
else:
|
else:
|
||||||
messagebox.showerror("错误", result.get("message", "认领失败"))
|
messagebox.showerror("错误", result.get("message", "认领失败"))
|
||||||
self.log(f"认领失败: {result.get('message')}", "ERROR")
|
self.log(f"认领失败: {result.get('message')}", "ERROR")
|
||||||
|
|
@ -935,8 +935,8 @@ class WrenchGUI:
|
||||||
self.device_label.config(text="扳手设备: 未选择", foreground="#2c3e50")
|
self.device_label.config(text="扳手设备: 未选择", foreground="#2c3e50")
|
||||||
|
|
||||||
def update_bolt_list(self):
|
def update_bolt_list(self):
|
||||||
"""更新螺栓列表(始终显示,即使没有工单)"""
|
"""更新作业列表(始终显示,即使没有工单)"""
|
||||||
# 确保螺栓列表框架始终显示,无论连接状态如何
|
# 确保作业列表框架始终显示,无论连接状态如何
|
||||||
if hasattr(self, 'list_frame'):
|
if hasattr(self, 'list_frame'):
|
||||||
self.list_frame.grid() # 强制显示,防止被隐藏
|
self.list_frame.grid() # 强制显示,防止被隐藏
|
||||||
|
|
||||||
|
|
@ -947,7 +947,7 @@ class WrenchGUI:
|
||||||
# 没有工单时,显示空表格,但表格框架保持可见
|
# 没有工单时,显示空表格,但表格框架保持可见
|
||||||
return
|
return
|
||||||
|
|
||||||
# 有工单时,显示螺栓数据
|
# 有工单时,显示作业数据
|
||||||
bolts = self.work_order.get('bolts', [])
|
bolts = self.work_order.get('bolts', [])
|
||||||
for bolt in bolts:
|
for bolt in bolts:
|
||||||
self.tree.insert("", tk.END, values=(
|
self.tree.insert("", tk.END, values=(
|
||||||
|
|
@ -983,7 +983,7 @@ class WrenchGUI:
|
||||||
if self.is_running:
|
if self.is_running:
|
||||||
return
|
return
|
||||||
|
|
||||||
# 开始拧紧前,更新螺栓顺序(确保使用最新排序)
|
# 开始拧紧前,更新作业顺序(确保使用最新排序)
|
||||||
self.update_bolt_order()
|
self.update_bolt_order()
|
||||||
self.can_sort = False # 开始拧紧后禁用排序
|
self.can_sort = False # 开始拧紧后禁用排序
|
||||||
|
|
||||||
|
|
@ -1051,7 +1051,7 @@ class WrenchGUI:
|
||||||
time.sleep(init_delay)
|
time.sleep(init_delay)
|
||||||
self.log("扳手初始化完成,准备开始拧紧")
|
self.log("扳手初始化完成,准备开始拧紧")
|
||||||
|
|
||||||
# 遍历所有螺栓
|
# 遍历所有作业
|
||||||
bolts = self.work_order.get('bolts', [])
|
bolts = self.work_order.get('bolts', [])
|
||||||
bolt_results = []
|
bolt_results = []
|
||||||
|
|
||||||
|
|
@ -1066,9 +1066,9 @@ class WrenchGUI:
|
||||||
|
|
||||||
# 完成,提交数据
|
# 完成,提交数据
|
||||||
if self.is_running:
|
if self.is_running:
|
||||||
self.log("所有螺栓拧紧完成!", "SUCCESS")
|
self.log("所有作业拧紧完成!", "SUCCESS")
|
||||||
self.submit_results(bolt_results)
|
self.submit_results(bolt_results)
|
||||||
self.root.after(0, lambda: messagebox.showinfo("完成", "所有螺栓已成功拧紧!"))
|
self.root.after(0, lambda: messagebox.showinfo("完成", "所有作业已成功拧紧!"))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log(f"流程异常: {e}", "ERROR")
|
self.log(f"流程异常: {e}", "ERROR")
|
||||||
|
|
@ -1084,7 +1084,7 @@ class WrenchGUI:
|
||||||
self.root.after(0, self.stop_process)
|
self.root.after(0, self.stop_process)
|
||||||
|
|
||||||
def process_bolt(self, bolt, index):
|
def process_bolt(self, bolt, index):
|
||||||
"""处理单个螺栓"""
|
"""处理单个作业"""
|
||||||
bolt_id = bolt.get('bolt_id')
|
bolt_id = bolt.get('bolt_id')
|
||||||
bolt_name = bolt.get('name')
|
bolt_name = bolt.get('name')
|
||||||
target_torque = bolt.get('target_torque')
|
target_torque = bolt.get('target_torque')
|
||||||
|
|
@ -1111,7 +1111,7 @@ class WrenchGUI:
|
||||||
|
|
||||||
while self.is_running:
|
while self.is_running:
|
||||||
attempt += 1
|
attempt += 1
|
||||||
self.log(f"第 {attempt} 次尝试拧紧螺栓 {bolt_id}")
|
self.log(f"第 {attempt} 次尝试拧紧作业 {bolt_id}")
|
||||||
|
|
||||||
# 启动扳手
|
# 启动扳手
|
||||||
self.log("发送启动命令...")
|
self.log("发送启动命令...")
|
||||||
|
|
@ -1130,7 +1130,7 @@ class WrenchGUI:
|
||||||
actual_angle = result.get("actual_angle", 0)
|
actual_angle = result.get("actual_angle", 0)
|
||||||
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
self.log(f"✅ 螺栓 {bolt_id} 拧紧成功! 实际扭矩: {actual_torque} Nm", "SUCCESS")
|
self.log(f"✅ 作业 {bolt_id} 拧紧成功! 实际扭矩: {actual_torque} Nm", "SUCCESS")
|
||||||
|
|
||||||
# 更新界面
|
# 更新界面
|
||||||
self.root.after(0, lambda at=actual_torque, ts=timestamp: self.update_tree_item(
|
self.root.after(0, lambda at=actual_torque, ts=timestamp: self.update_tree_item(
|
||||||
|
|
@ -1154,9 +1154,9 @@ class WrenchGUI:
|
||||||
else:
|
else:
|
||||||
# 失败,继续尝试
|
# 失败,继续尝试
|
||||||
if result:
|
if result:
|
||||||
self.log(f"❌ 螺栓 {bolt_id} 拧紧失败: {result.get('status', '未知错误')}, 继续重试...", "WARN")
|
self.log(f"❌ 作业 {bolt_id} 拧紧失败: {result.get('status', '未知错误')}, 继续重试...", "WARN")
|
||||||
else:
|
else:
|
||||||
self.log(f"❌ 螺栓 {bolt_id} 无响应, 继续重试...", "WARN")
|
self.log(f"❌ 作业 {bolt_id} 无响应, 继续重试...", "WARN")
|
||||||
|
|
||||||
time.sleep(1) # 等待1秒后重试
|
time.sleep(1) # 等待1秒后重试
|
||||||
|
|
||||||
|
|
@ -1230,7 +1230,7 @@ class WrenchGUI:
|
||||||
self.log(f"❌ 数据提交失败: {e}", "ERROR")
|
self.log(f"❌ 数据提交失败: {e}", "ERROR")
|
||||||
|
|
||||||
def update_current_bolt(self, bolt, status):
|
def update_current_bolt(self, bolt, status):
|
||||||
"""更新当前螺栓显示"""
|
"""更新当前作业显示"""
|
||||||
self.current_bolt_label.config(text=f"[{bolt.get('bolt_id')}] {bolt.get('name')}")
|
self.current_bolt_label.config(text=f"[{bolt.get('bolt_id')}] {bolt.get('name')}")
|
||||||
self.current_torque_label.config(text=f"目标扭矩: {bolt.get('target_torque')} Nm")
|
self.current_torque_label.config(text=f"目标扭矩: {bolt.get('target_torque')} Nm")
|
||||||
self.current_status_label.config(text=f"状态: {status}")
|
self.current_status_label.config(text=f"状态: {status}")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue