Advertisement
DeaD_EyE

Access via OPCUA Tags on a sImulated MTP700

May 19th, 2025
543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. import typing
  2.  
  3. import opcua
  4.  
  5.  
  6. def get_value(hmi_opcua: opcua.Client, tag: str) -> typing.Any:
  7.     root = hmi_opcua.get_root_node()
  8.  
  9.     for child in root.get_child(["0:Objects", "1:HmiRuntime", "1:HMI_RT_4", "1:Tags"]).get_children():
  10.         name = child.get_browse_name().Name.split("::")[1]
  11.         if name == tag:
  12.             return child.get_value()
  13.  
  14.     raise ValueError(f"Could not find {tag}")
  15.  
  16.  
  17.  
  18. # simulated MTP700 with activated OPCUA
  19. client = opcua.Client("opc.tcp://127.0.0.1:4949")
  20. client.session_timeout = 600000
  21. client.connect()
  22.  
  23.  
  24. print("Tag in position:", get_value(client, "Tag_in_pos"))
  25. client.disconnect()
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement