nodeopcuaclient.py
Go to the documentation of this file.
1 
2 import sys
3 import time
4 sys.path.append(".")
5 
6 from IPython import embed
7 import opcua
8 
9 class SubClient(opcua.SubscriptionHandler):
10  def __init_(self, *args):
11  self.val = MessageSecurityMode.None
12  #self.c = Condition()
13  def data_change(self, handle, node, val, attr):
14  print("Python: New data change event", handle, node, val, attr)
15  self.val = val
16 
17 
18 if __name__ == "__main__":
19  client = opcua.Client(True)
20  client.connect("opc.tcp://utgaard:4841")
21  #s.connect("opc.tcp://192.168.56.101:48030")
22  try:
23  root = client.get_root_node()
24  print("I got root: ", root)
25  print("Childs are: ", root.get_children())
26 
27  #getting node by id since nodejs seems not to support browsepath
28  myvar = client.get_node(opcua.NodeId("ns=1;i=1001"))
29  #myvar = root.get_child(["0:MyDevice"])
30  #print("yvar is: ", myvar,get_children())
31  #myvar = root.get_child(["0:MyDevice", "0:MyVariable1"])
32  print("myvar is: ", myvar)
33 
34  sclt = SubClient()
35  sub = client.create_subscription(100, sclt)
36  handle = sub.subscribe_data_change(myvar)
37  print("Subscribe handle is: ", handle)
38 
39 
40  embed()
41  finally:
42  client.disconnect()
FMT_API void print(std::FILE *f, CStringRef format_str, ArgList args)
Definition: format.cc:873
def data_change(self, handle, node, val, attr)


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:12:07