File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments