server-instantiate-object.py
Go to the documentation of this file.
00001 import sys
00002 sys.path.insert(0, "..")
00003 import time
00004 from IPython import embed
00005 
00006 
00007 from opcua import ua, Server, instantiate
00008 
00009 
00010 if __name__ == "__main__":
00011 
00012     # setup our server
00013     server = Server()
00014     server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/")
00015 
00016     # setup our own namespace, not really necessary but should as spec
00017     uri = "http://examples.freeopcua.github.io"
00018     idx = server.register_namespace(uri)
00019 
00020     # create our custom object type
00021     dev = server.nodes.base_object_type.add_object_type(0, "MyDevice")
00022     dev.add_variable(0, "sensor1", 1.0)
00023     dev.add_property(0, "device_id", "0340")
00024     ctrl = dev.add_object(0, "controller")
00025     ctrl.add_property(0, "state", "Idle")
00026 
00027     # instantiate our new object type
00028     mydevice = instantiate(server.nodes.objects, dev, bname="2:Device0001")
00029     #mydevice = server.nodes.objects.add_object(2, "Device0001", objecttype=dev)  # specificying objecttype to add_object also instanciate a node type
00030     mydevice_var = mydevice.get_child(["0:controller", "0:state"])  # get proxy to our device state variable 
00031 
00032     # starting!
00033     server.start()
00034 
00035     try:
00036         mydevice_var.set_value("Running")
00037         embed()
00038     finally:
00039         # close connection, remove subcsriptions, etc
00040         server.stop()


ros_opcua_impl_python_opcua
Author(s): Denis Štogl , Daniel Draper
autogenerated on Sat Jun 8 2019 18:26:23