Skip to content

Commit 3990a96

Browse files
committed
add robot nodeset example
1 parent 3291bea commit 3990a96

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
server.import_xml("../schemas/UA-Nodeset/DI/Opc.Ua.Di.NodeSet2.xml")
16+
server.import_xml("../schemas/UA-Nodeset/Robotics/Opc.Ua.Robotics.NodeSet2.xml")
17+
18+
# setup our own namespace, not really necessary but should as spec
19+
uri = "http://examples.freeopcua.github.io"
20+
idx = server.register_namespace(uri)
21+
22+
# get Objects node, this is where we should put our nodes
23+
objects = server.get_objects_node()
24+
25+
# populating our address space
26+
myobj = objects.add_object(idx, "MyObject")
27+
myvar = myobj.add_variable(idx, "MyVariable", 6.7)
28+
myvar.set_writable() # Set MyVariable to be writable by clients
29+
30+
# starting!
31+
server.start()
32+
33+
try:
34+
count = 0
35+
while True:
36+
time.sleep(1)
37+
count += 0.1
38+
myvar.set_value(count)
39+
finally:
40+
#close connection, remove subcsriptions, etc
41+
server.stop()

0 commit comments

Comments
 (0)