server-minimal.py
Go to the documentation of this file.
1 import sys
2 sys.path.insert(0, "..")
3 import time
4 
5 
6 from opcua import ua, Server
7 
8 
9 if __name__ == "__main__":
10 
11  # setup our server
12  server = Server()
13  server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/")
14 
15  # setup our own namespace, not really necessary but should as spec
16  uri = "http://examples.freeopcua.github.io"
17  idx = server.register_namespace(uri)
18 
19  # get Objects node, this is where we should put our nodes
20  objects = server.get_objects_node()
21 
22  # populating our address space
23  myobj = objects.add_object(idx, "MyObject")
24  myvar = myobj.add_variable(idx, "MyVariable", 6.7)
25  myvar.set_writable() # Set MyVariable to be writable by clients
26 
27  # starting!
28  server.start()
29 
30  try:
31  count = 0
32  while True:
33  time.sleep(1)
34  count += 0.1
35  myvar.set_value(count)
36  finally:
37  #close connection, remove subcsriptions, etc
38  server.stop()


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