server-xmlexporter.py
Go to the documentation of this file.
1 import sys
2 sys.path.insert(0, "..")
3 import time
4 from collections import OrderedDict
5 
6 from opcua import ua, Server, instantiate
7 from opcua.common.xmlexporter import XmlExporter
8 
9 
10 if __name__ == "__main__":
11 
12  # setup our server
13  server = Server()
14  server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/")
15 
16  # setup our own namespace, not really necessary but should as spec
17  uri = "http://examples.freeopcua.github.io"
18  idx = server.register_namespace(uri)
19 
20  # get Objects node, this is where we should put our nodes
21  objects = server.get_objects_node()
22 
23  # populating our address space
24  myobj = objects.add_object(idx, "MyObject")
25  myvar = myobj.add_variable(idx, "MyVariable", 6.7)
26  myvar.set_writable() # Set MyVariable to be writable by clients
27 
28  dev = server.nodes.base_object_type.add_object_type(0, "MyDevice")
29  dev.add_variable(0, "sensor1", 1.0)
30 
31  mydevice = instantiate(server.nodes.objects, dev, bname="2:Device0001")
32 
33  node_list = [dev, mydevice, myobj, myvar]
34 
35  # starting!
36  server.start()
37 
38  exporter = XmlExporter(server)
39  exporter.build_etree(node_list, ['http://myua.org/test/'])
40  exporter.write_xml('ua-export.xml')
41 
42  server.stop()
def instantiate(parent, node_type, nodeid=None, bname=None, idx=0)
Definition: instantiate.py:12


ros_opcua_impl_python_opcua
Author(s): Denis Štogl , Daniel Draper
autogenerated on Tue Jan 19 2021 03:12:44