async def task(loop): url = "opc.tcp://192.168.2.64:4840" # url = "opc.tcp://localhost:4840/freeopcua/server/" try: client = Client(url=url) client.set_user('test') client.set_password('test') # client.set_security_string() await client.connect() # Client has a few methods to get proxy to UA nodes that should always be in address space such as Root or Objects root = client.get_root_node() _logger.info("Objects node is: %r", root) # Node objects have methods to read and write node attributes as well as browse or populate address space _logger.info("Children of root are: %r", await root.get_children()) tree = await browse_nodes(client.get_objects_node()) _logger.info('Node tree: %r', tree) except Exception: _logger.exception('error') finally: await client.disconnect()
import sys sys.path.insert(0, "..") import time import logging from IPython import embed from asyncua import Client from asyncua import ua if __name__ == "__main__": logging.basicConfig(level=logging.WARN) client = Client("opc.tcp://asyncua.demo-this.com:51210/UA/SampleServer") try: client.connect() root = client.get_root_node() objects = client.get_objects_node() struct = client.get_node("ns=2;i=10239") struct_array = client.get_node("ns=2;i=10323") before = struct.read_value() before_array = struct_array.read_value() client.load_type_definitions( ) # scan server for custom structures and import them after = struct.read_value() after_array = struct_array.read_value() embed() finally: client.disconnect()