将上料斗、下料斗重量改成opc_tcp根节点的子节点

This commit is contained in:
2025-11-18 14:47:09 +08:00
parent 20bdd61d55
commit f7f887dea2
4 changed files with 10 additions and 7 deletions

BIN
img.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

BIN
img_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

View File

@ -12,9 +12,7 @@ from datetime import datetime
# -----------
# 参数配置
# -----------
OPC_SERVER_URL = "opc.tcp://localhost:4840/zjsh_feed/server/"
UPPER_WEIGHT_NODE_ID = "ns=2;s=upper_weight"
LOWER_WEIGHT_NODE_ID = "ns=2;s=lower_weight"
OPC_SERVER_URL = "opc.tcp://localhost:4841/zjsh_feed/server/"
RECONNECT_INTERVAL = 2000 # 重连间隔(毫秒)
DATA_READ_INTERVAL = 2000 # 数据读取间隔(毫秒,与服务端更新频率一致)
@ -98,8 +96,11 @@ class OpcuaClient(QObject):
print(f"OPC UA 连接成功:{self.opc_server_url}")
# 2. 获取重量节点对象(仅连接成功时获取一次)
self.upper_weight_node = self.opc_client.get_node(UPPER_WEIGHT_NODE_ID)
self.lower_weight_node = self.opc_client.get_node(LOWER_WEIGHT_NODE_ID)
objects = self.opc_client.get_objects_node() # 根节点
self.upper_weight_node = objects.get_child(["2:upper", "2:upper_weight"])
objects = self.opc_client.get_objects_node() # 根节点
self.lower_weight_node = objects.get_child(["2:lower", "2:lower_weight"])
# 3. 验证节点是否有效
self._verify_nodes()

View File

@ -1,6 +1,8 @@
# 功能
使用opc_tcp通讯读取服务端的上料斗和下料斗重量的数值并且显示在界面上。当服务端断开状态图标会切换重量值清零会一直重连服务端。
当服务端那边连接不上重量那边的客户端,上料斗或下料斗的值会变为"error",我这边客户端接收到"error"值时,状态图标会切换,重量值清零,直到接收到正常值
当服务端那边连接不上重量那边的客户端,上料斗或下料斗的值会变为"error",我这边客户端接收到"error"值时,状态图标会切换,重量值清零,直到接收到正常值
# 使用教程
使用前需要修改的参数opcua_client.py文件中需要修改的地方有
![img.png](参数修改.png)
![img.png](img.png)
![img_1.png](img_1.png)