server-instantiate-object.py
Go to the documentation of this file.
1 import sys
2 sys.path.insert(0, "..")
3 import time
4 from IPython import embed
5 
6 
7 from opcua import ua, Server, instantiate
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  # create our custom object type
21  dev = server.nodes.base_object_type.add_object_type(0, "MyDevice")
22  dev.add_variable(0, "sensor1", 1.0)
23  dev.add_property(0, "device_id", "0340")
24  ctrl = dev.add_object(0, "controller")
25  ctrl.add_property(0, "state", "Idle")
26 
27  # instantiate our new object type
28  mydevice = instantiate(server.nodes.objects, dev, bname="2:Device0001")
29  #mydevice = server.nodes.objects.add_object(2, "Device0001", objecttype=dev) # specificying objecttype to add_object also instanciate a node type
30  mydevice_var = mydevice.get_child(["0:controller", "0:state"]) # get proxy to our device state variable
31 
32  # starting!
33  server.start()
34 
35  try:
36  mydevice_var.set_value("Running")
37  embed()
38  finally:
39  # close connection, remove subcsriptions, etc
40  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