This commit is contained in:
2025-11-21 14:55:52 +08:00
parent e3ecd0550f
commit 26ed8df502
36 changed files with 908 additions and 433 deletions

View File

@ -52,36 +52,30 @@ class OPCUAClientTest:
objects = self.client.get_objects_node()
print(f"对象节点: {objects}")
# 浏览 IndustrialDevice 节点
upper_device = objects.get_child("2:upper")
print(f"\n工业设备节点: {upper_device}")
print(f"\n上料斗对象: {upper_device}")
# 获取传感器节点
lower_device = objects.get_child("2:lower")
print(f"传感器节点: {lower_device}")
print(f"下料斗对象: {lower_device}")
print(f"温度传感器: {upper_device}")
print(f"压力传感器: {lower_device}")
# 获取变量值
print("\n=== 当前传感器数据 ===")
self.read_sensor_values(upper_device, lower_device)
print("\n=== 当前对象属性===")
self.read_object_properties(upper_device, lower_device)
except Exception as e:
print(f"浏览节点时出错: {e}")
def read_sensor_values(self, upper_device, lower_device):
"""读取传感器数值"""
def read_object_properties(self, upper_device, lower_device):
"""读取重量数值"""
try:
# 读取温度
temp_value = upper_device.get_child("2:upper_weight").get_value()
temp_unit = upper_device.get_child("2:lower_weight").get_value()
print(f"温度: {temp_value} {temp_unit}")
# 读取重量
upper_weight = upper_device.get_child("2:upper_weight").get_value()
lower_weight = lower_device.get_child("2:lower_weight").get_value()
print(f"上料斗重量: {upper_weight}")
print(f"下料斗重量: {lower_weight}")
except Exception as e:
print(f"读取传感器数据时出错: {e}")
print(f"读取数据时出错: {e}")
def monitor_data(self, duration=30):
"""监控数据变化"""