Go to the documentation of this file.00001
00002 import sys
00003 import time
00004 sys.path.append(".")
00005
00006 from IPython import embed
00007 import opcua
00008
00009 class SubClient(opcua.SubscriptionHandler):
00010 def __init_(self, *args):
00011 self.val = MessageSecurityMode.None
00012 #self.c = Condition()
00013 def data_change(self, handle, node, val, attr):
00014 print("Python: New data change event", handle, node, val, attr)
00015 self.val = val
00016
00017
00018 if __name__ == "__main__":
00019 client = opcua.Client(True)
00020 client.connect("opc.tcp:
00021 #s.connect("opc.tcp:
00022 try:
00023 root = client.get_root_node()
00024 print("I got root: ", root)
00025 print("Childs are: ", root.get_children())
00026
00027 #getting node by id since nodejs seems not to support browsepath
00028 myvar = client.get_node(opcua.NodeId("ns=1;i=1001"))
00029 #myvar = root.get_child(["0:MyDevice"])
00030 #print("yvar is: ", myvar,get_children())
00031 #myvar = root.get_child(["0:MyDevice", "0:MyVariable1"])
00032 print("myvar is: ", myvar)
00033
00034 sclt = SubClient()
00035 sub = client.create_subscription(100, sclt)
00036 handle = sub.subscribe_data_change(myvar)
00037 print("Subscribe handle is: ", handle)
00038
00039
00040 embed()
00041 finally:
00042 client.disconnect()