Go to the documentation of this file.00001 from opcua import Client, ua
00002 from opcua.ua import ua_binary as uabin
00003 from opcua.common.methods import call_method
00004
00005
00006 class HelloClient:
00007 def __init__(self, endpoint):
00008 self.client = Client(endpoint)
00009
00010 def __enter__(self):
00011 self.client.connect()
00012 return self.client
00013
00014 def __exit__(self, exc_type, exc_val, exc_tb):
00015 self.client.disconnect()
00016
00017
00018 if __name__ == '__main__':
00019 with HelloClient("opc.tcp://localhost:40840/freeopcua/server/") as client:
00020 root = client.get_root_node()
00021 print("Root node is: ", root)
00022 objects = client.get_objects_node()
00023 print("Objects node is: ", objects)
00024
00025 hellower = objects.get_child("0:Hellower")
00026 print("Hellower is: ", hellower)
00027
00028 resulting_text = hellower.call_method("0:SayHello", False)
00029 print(resulting_text)
00030
00031 resulting_text = hellower.call_method("1:SayHello2", True)
00032 print(resulting_text)
00033
00034 resulting_array = hellower.call_method("1:SayHelloArray", False)
00035 print(resulting_array)