edouard@3543: #!/bin/bash edouard@3543: edouard@3672: echo "Instant OPC-UA server for test" edouard@3543: edouard@3549: # Run server edouard@3672: exec $BEREMIZPYTHONPATH - << EOF edouard@3543: edouard@3549: import sys edouard@3549: import time edouard@3549: edouard@3549: from opcua import ua, Server edouard@3549: edouard@3549: server = Server() edouard@3549: server.set_endpoint("opc.tcp://127.0.0.1:4840/freeopcua/server/") edouard@3549: edouard@3549: uri = "http://beremiz.github.io" edouard@3549: idx = server.register_namespace(uri) edouard@3549: edouard@3549: objects = server.get_objects_node() edouard@3549: edouard@3549: testobj = objects.add_object(idx, "TestObject") edouard@3549: testvarout = testobj.add_variable(idx, "TestOut", 1.2) edouard@3549: testvar = testobj.add_variable(idx, "TestIn", 5.6) edouard@3549: testvar.set_writable() edouard@3549: edouard@3549: server.start() edouard@3549: edouard@3549: try: edouard@3549: while True: edouard@3549: time.sleep(1) edouard@3672: inval=testvar.get_value() edouard@3672: print inval edouard@3672: testvarout.set_value(inval*2) edouard@3549: sys.stdout.flush() edouard@3549: finally: edouard@3549: server.stop() edouard@3549: EOF