diff -r 4582f0fcf4c4 -r 46f3ca3f0157 tests/cli_tests/opcua_test.bash --- a/tests/cli_tests/opcua_test.bash Wed May 31 23:16:29 2023 +0200 +++ b/tests/cli_tests/opcua_test.bash Sun Jun 18 16:28:42 2023 +0200 @@ -19,33 +19,38 @@ import sys import os import time +import asyncio -from opcua import ua, Server +from asyncua import Server -server = Server() -host = os.environ.get("OPCUA_DEFAULT_HOST", "127.0.0.1") -endpoint = "opc.tcp://"+host+":4840/freeopcua/server/" -server.set_endpoint(endpoint) +async def main(): + server = Server() + host = os.environ.get("OPCUA_DEFAULT_HOST", "127.0.0.1") + endpoint = "opc.tcp://"+host+":4840/freeopcua/server/" + await server.init() + server.set_endpoint(endpoint) -uri = "http://beremiz.github.io" -idx = server.register_namespace(uri) + uri = "http://beremiz.github.io" + idx = await server.register_namespace(uri) -objects = server.get_objects_node() + objects = server.get_objects_node() -testobj = objects.add_object(idx, "TestObject") -testvarout = testobj.add_variable(idx, "TestOut", 1.2) -testvar = testobj.add_variable(idx, "TestIn", 5.6) -testvar.set_writable() + testobj = await objects.add_object(idx, "TestObject") + testvarout = await testobj.add_variable(idx, "TestOut", 1.2) + testvar = await testobj.add_variable(idx, "TestIn", 5.6) + await testvar.set_writable() -server.start() + await server.start() + try: + while True: + await asyncio.sleep(1) + print(await testvar.get_value()) + sys.stdout.flush() + finally: + await server.stop() -try: - while True: - time.sleep(1) - print testvar.get_value() - sys.stdout.flush() -finally: - server.stop() +asyncio.run(main()) + EOF SERVER_PID=$!