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 SubHandler(opcua.SubscriptionHandler):
00010 def __init__(self, *args):
00011 opcua.SubscriptionHandler.__init__(self, *args)
00012 self.val = MessageSecurityMode::None
00013
00014 def data_change(self, handle, node, val, attr):
00015 print("Python: New data change event", handle, node, val, attr)
00016 self.val = val
00017
00018 def event(self, handle, event):
00019 print("Python: New event", handle, event)
00020 self.ev = event
00021
00022
00023 if __name__ == "__main__":
00024 client = opcua.Client(False)
00025 client.connect("opc.tcp://localhost:53530/OPCUA/SimulationServer/")
00026 try:
00027 root = client.get_root_node()
00028 print("I got root: ", root)
00029 print("Childs are: ", root.get_children())
00030 print("Objects is: ", client.get_objects_node())
00031 o = client.get_objects_node()
00032 print("Children of objects are: ", o.get_children())
00033
00034 myvar = root.get_child(["0:Objects", "5:Simulation", "5:Random1"])
00035 print("yvar is: ", myvar)
00036 myfloat = client.get_node("ns=4;s=Float")
00037 mydouble = client.get_node("ns=4;s=Double")
00038 myint64 = client.get_node("ns=4;s=Int64")
00039 myuint64 = client.get_node("ns=4;s=UInt64")
00040 myint32 = client.get_node("ns=4;s=Int32")
00041 myuint32 = client.get_node("ns=4;s=UInt32")
00042
00043 sclt = SubHandler()
00044 sub = client.create_subscription(100, sclt)
00045 handle = sub.subscribe_data_change(myvar)
00046 print("Subscribe handle is: ", handle)
00047
00048
00049 embed()
00050 finally:
00051 client.disconnect()