将tcp协议修改为opcua协议
This commit is contained in:
@ -37,9 +37,11 @@ class WeightDetailsDialog(QDialog):
|
||||
self.check_label = None # 状态图标标签
|
||||
|
||||
self.is_running = False # 定时器是否运行
|
||||
self.latest_json_data = {}
|
||||
self.statusWidgets = [] # 状态显示控件列表
|
||||
|
||||
# 存储当前重量值(用于处理空值/异常值)
|
||||
self.current_weight = 0.0
|
||||
|
||||
self._init_ui(title)
|
||||
|
||||
# -----------------------
|
||||
@ -189,12 +191,21 @@ class WeightDetailsDialog(QDialog):
|
||||
def update_weight(self, weight_data):
|
||||
"""根据TCP获取的数据更新重量显示"""
|
||||
# 更新6个数字标签(补零为6位,超过6位取后6位)
|
||||
try:
|
||||
weight_int = int(weight_data)
|
||||
weight_str = f"{weight_int:06d}"[-6:]
|
||||
except (ValueError, TypeError):
|
||||
# 处理空值/异常值(客户端传递的 "" 或 "error")
|
||||
if weight_data == "" or weight_data == "error" or weight_data is None:
|
||||
weight_str = "000000"
|
||||
self.current_weight = 0
|
||||
else:
|
||||
try:
|
||||
# 支持浮点数(如 648.06 → 保留2位小数后转为整数显示,避免丢失精度)
|
||||
weight_int = int(float(weight_data))
|
||||
self.current_weight = weight_int
|
||||
weight_str = f"{weight_int:06d}"[-6:] # 超过6位取后6位
|
||||
except (ValueError, TypeError):
|
||||
weight_str = "000000"
|
||||
self.current_weight = 0
|
||||
|
||||
# 更新6个数字标签
|
||||
for i in range(min(len(self.digit_labels), 6)):
|
||||
self.digit_labels[i].setText(weight_str[i] if i < len(weight_str) else "0")
|
||||
|
||||
@ -227,10 +238,15 @@ class WeightDetailsDialog(QDialog):
|
||||
# --------------------
|
||||
def _clear_ui_info(self):
|
||||
"""清空管片ID和网格信息"""
|
||||
if self.id_value_label:
|
||||
# 修复:避免访问未定义的 self.id_value_label
|
||||
if hasattr(self, 'id_value_label') and self.id_value_label:
|
||||
self.id_value_label.setText("")
|
||||
for widget in self.statusWidgets:
|
||||
widget['valueLabel'].setText("")
|
||||
if 'valueLabel' in widget and widget['valueLabel']:
|
||||
widget['valueLabel'].setText("")
|
||||
# 清空重量显示
|
||||
for label in self.digit_labels:
|
||||
label.setText("0")
|
||||
print("ℹ️ 界面信息已清空")
|
||||
|
||||
# 测试代码
|
||||
|
||||
Reference in New Issue
Block a user