适配小扳手,版本待测试
parent
77bb4e0281
commit
b33d83a287
|
|
@ -24,6 +24,10 @@
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"description": "测试模式:失败也算成功,用于无钉子测试"
|
"description": "测试模式:失败也算成功,用于无钉子测试"
|
||||||
},
|
},
|
||||||
|
"torque_display": {
|
||||||
|
"decimal_mode": true,
|
||||||
|
"description": "扭矩显示模式:decimal_mode=true时显示值除以10(如350显示为35.0),false时原样显示"
|
||||||
|
},
|
||||||
"bolt_default_config": {
|
"bolt_default_config": {
|
||||||
"mode": 1,
|
"mode": 1,
|
||||||
"torque_tolerance": 0.10,
|
"torque_tolerance": 0.10,
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,15 @@ class WrenchGUI:
|
||||||
# 开始轮询
|
# 开始轮询
|
||||||
self.start_polling()
|
self.start_polling()
|
||||||
|
|
||||||
|
def format_torque(self, torque_value):
|
||||||
|
"""格式化扭矩显示值"""
|
||||||
|
if torque_value is None or torque_value == "--":
|
||||||
|
return torque_value
|
||||||
|
decimal_mode = self.config.get('torque_display', {}).get('decimal_mode', False)
|
||||||
|
if decimal_mode:
|
||||||
|
return torque_value / 10
|
||||||
|
return torque_value
|
||||||
|
|
||||||
def _create_widgets(self):
|
def _create_widgets(self):
|
||||||
"""创建界面组件"""
|
"""创建界面组件"""
|
||||||
# 使用左右布局:左侧工单列表,右侧其他内容
|
# 使用左右布局:左侧工单列表,右侧其他内容
|
||||||
|
|
@ -714,7 +723,7 @@ class WrenchGUI:
|
||||||
self.tree.insert("", tk.END, values=(
|
self.tree.insert("", tk.END, values=(
|
||||||
bolt.get('bolt_id'),
|
bolt.get('bolt_id'),
|
||||||
bolt.get('name'),
|
bolt.get('name'),
|
||||||
bolt.get('target_torque'),
|
self.format_torque(bolt.get('target_torque')),
|
||||||
"待认领",
|
"待认领",
|
||||||
"--",
|
"--",
|
||||||
"--"
|
"--"
|
||||||
|
|
@ -953,7 +962,7 @@ class WrenchGUI:
|
||||||
self.tree.insert("", tk.END, values=(
|
self.tree.insert("", tk.END, values=(
|
||||||
bolt.get('bolt_id'),
|
bolt.get('bolt_id'),
|
||||||
bolt.get('name'),
|
bolt.get('name'),
|
||||||
bolt.get('target_torque'),
|
self.format_torque(bolt.get('target_torque')),
|
||||||
"待拧紧",
|
"待拧紧",
|
||||||
"--",
|
"--",
|
||||||
"--"
|
"--"
|
||||||
|
|
@ -1089,14 +1098,14 @@ class WrenchGUI:
|
||||||
bolt_name = bolt.get('name')
|
bolt_name = bolt.get('name')
|
||||||
target_torque = bolt.get('target_torque')
|
target_torque = bolt.get('target_torque')
|
||||||
|
|
||||||
self.log(f"开始拧紧: [{bolt_id}] {bolt_name}, 目标扭矩: {target_torque} Nm")
|
self.log(f"开始拧紧: [{bolt_id}] {bolt_name}, 目标扭矩: {self.format_torque(target_torque)} Nm")
|
||||||
|
|
||||||
# 更新界面
|
# 更新界面
|
||||||
self.root.after(0, lambda: self.update_current_bolt(bolt, "拧紧中..."))
|
self.root.after(0, lambda: self.update_current_bolt(bolt, "拧紧中..."))
|
||||||
self.root.after(0, lambda: self.update_tree_item(index, "拧紧中", "running"))
|
self.root.after(0, lambda: self.update_tree_item(index, "拧紧中", "running"))
|
||||||
|
|
||||||
# 设定参数
|
# 设定参数
|
||||||
self.log(f"设定参数: 扭矩={target_torque}Nm, 模式=M{bolt.get('mode', 1)}")
|
self.log(f"设定参数: 扭矩={self.format_torque(target_torque)}Nm, 模式=M{bolt.get('mode', 1)}")
|
||||||
self.wrench.set_torque_parameters(
|
self.wrench.set_torque_parameters(
|
||||||
target_torque=target_torque,
|
target_torque=target_torque,
|
||||||
mode=bolt.get('mode', 1),
|
mode=bolt.get('mode', 1),
|
||||||
|
|
@ -1130,7 +1139,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} 拧紧成功! 实际扭矩: {self.format_torque(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(
|
||||||
|
|
@ -1232,7 +1241,7 @@ class WrenchGUI:
|
||||||
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"目标扭矩: {self.format_torque(bolt.get('target_torque'))} Nm")
|
||||||
self.current_status_label.config(text=f"状态: {status}")
|
self.current_status_label.config(text=f"状态: {status}")
|
||||||
|
|
||||||
def update_tree_item(self, index, status, tag, actual_torque="--", timestamp="--"):
|
def update_tree_item(self, index, status, tag, actual_torque="--", timestamp="--"):
|
||||||
|
|
@ -1243,7 +1252,7 @@ class WrenchGUI:
|
||||||
values = list(self.tree.item(item)['values'])
|
values = list(self.tree.item(item)['values'])
|
||||||
values[3] = status
|
values[3] = status
|
||||||
if actual_torque != "--":
|
if actual_torque != "--":
|
||||||
values[4] = actual_torque
|
values[4] = self.format_torque(actual_torque)
|
||||||
if timestamp != "--":
|
if timestamp != "--":
|
||||||
values[5] = timestamp
|
values[5] = timestamp
|
||||||
self.tree.item(item, values=values, tags=(tag,))
|
self.tree.item(item, values=values, tags=(tag,))
|
||||||
|
|
|
||||||
|
|
@ -331,6 +331,13 @@ class WrenchController:
|
||||||
|
|
||||||
if response:
|
if response:
|
||||||
print(f"✅ 收到完整响应 ({len(response)}字节): {response.hex(' ').upper()}")
|
print(f"✅ 收到完整响应 ({len(response)}字节): {response.hex(' ').upper()}")
|
||||||
|
# 尝试解析实际扭矩(如果响应足够长)
|
||||||
|
if len(response) >= 31:
|
||||||
|
try:
|
||||||
|
actual_torque = struct.unpack('>H', response[29:31])[0]
|
||||||
|
print(f"⭐⭐⭐ 实际扭矩(位置29-30): {actual_torque} (原始值) ⭐⭐⭐")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
return response
|
return response
|
||||||
else:
|
else:
|
||||||
print("❌ 收到空响应(连接可能已关闭)")
|
print("❌ 收到空响应(连接可能已关闭)")
|
||||||
|
|
@ -531,8 +538,8 @@ class WrenchController:
|
||||||
:param response: 接收到的响应报文
|
:param response: 接收到的响应报文
|
||||||
:return: 解析后的结果字典
|
:return: 解析后的结果字典
|
||||||
"""
|
"""
|
||||||
if not response or len(response) < 44:
|
if not response or len(response) < 31:
|
||||||
return {"error": "响应数据不完整"}
|
return {"error": f"响应数据过短,仅{len(response) if response else 0}字节,至少需要31字节"}
|
||||||
|
|
||||||
# 验证报文头和功能码
|
# 验证报文头和功能码
|
||||||
if response[0:2] != b'\xC5\xC5':
|
if response[0:2] != b'\xC5\xC5':
|
||||||
|
|
@ -598,21 +605,22 @@ class WrenchController:
|
||||||
|
|
||||||
mode = "M1(扭矩模式)" if response[26] == 0x01 else "M2(角度模式)"
|
mode = "M1(扭矩模式)" if response[26] == 0x01 else "M2(角度模式)"
|
||||||
|
|
||||||
# 解析扭矩和角度值
|
# 解析扭矩和角度值(安全解析,检查长度)
|
||||||
target_torque = struct.unpack('>H', response[27:29])[0]
|
target_torque = struct.unpack('>H', response[27:29])[0] if len(response) >= 29 else 0
|
||||||
actual_torque = struct.unpack('>H', response[29:31])[0]
|
actual_torque = struct.unpack('>H', response[29:31])[0] if len(response) >= 31 else 0
|
||||||
target_angle = struct.unpack('>H', response[31:33])[0]
|
target_angle = struct.unpack('>H', response[31:33])[0] if len(response) >= 33 else 0
|
||||||
actual_angle = struct.unpack('>H', response[33:35])[0]
|
actual_angle = struct.unpack('>H', response[33:35])[0] if len(response) >= 35 else 0
|
||||||
torque_max = struct.unpack('>H', response[35:37])[0]
|
torque_max = struct.unpack('>H', response[35:37])[0] if len(response) >= 37 else 0
|
||||||
torque_min = struct.unpack('>H', response[37:39])[0]
|
torque_min = struct.unpack('>H', response[37:39])[0] if len(response) >= 39 else 0
|
||||||
angle_max = struct.unpack('>H', response[39:41])[0]
|
angle_max = struct.unpack('>H', response[39:41])[0] if len(response) >= 41 else 0
|
||||||
angle_min = struct.unpack('>H', response[41:43])[0]
|
angle_min = struct.unpack('>H', response[41:43])[0] if len(response) >= 43 else 0
|
||||||
|
|
||||||
# 详细打印扭矩和角度数据
|
# 详细打印扭矩和角度数据
|
||||||
print(f"\n{'='*70}")
|
print(f"\n{'='*70}")
|
||||||
print(f"🔧 扭矩和角度数据解析:")
|
print(f"🔧 扭矩和角度数据解析:")
|
||||||
print(f" [27-28] 目标扭矩: {target_torque} (原始值, HEX: {response[27:29].hex(' ').upper()})")
|
print(f" [27-28] 目标扭矩: {target_torque} (原始值, HEX: {response[27:29].hex(' ').upper()})")
|
||||||
print(f" [29-30] 实际扭矩: {actual_torque} (原始值, HEX: {response[29:31].hex(' ').upper()})")
|
print(f" [29-30] 实际扭矩: {actual_torque} (原始值, HEX: {response[29:31].hex(' ').upper()})")
|
||||||
|
print(f"\n⭐⭐⭐ 实际扭矩值: {actual_torque} ⭐⭐⭐")
|
||||||
print(f" [31-32] 目标角度: {target_angle}° (HEX: {response[31:33].hex(' ').upper()})")
|
print(f" [31-32] 目标角度: {target_angle}° (HEX: {response[31:33].hex(' ').upper()})")
|
||||||
print(f" [33-34] 实际角度: {actual_angle}° (HEX: {response[33:35].hex(' ').upper()})")
|
print(f" [33-34] 实际角度: {actual_angle}° (HEX: {response[33:35].hex(' ').upper()})")
|
||||||
print(f" [35-36] 扭矩上限: {torque_max} (HEX: {response[35:37].hex(' ').upper()})")
|
print(f" [35-36] 扭矩上限: {torque_max} (HEX: {response[35:37].hex(' ').upper()})")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue