tests/ide_tests/opcua_browse.sikuli/opcua_service.bash
author Edouard Tisserant <edouard.tisserant@gmail.com>
Sun, 18 Jun 2023 16:28:42 +0200
changeset 3820 46f3ca3f0157
parent 3718 7841b651d601
permissions -rw-r--r--
OPC-UA client : python3 + AsyncUA fixes
3543
6210c08c1c41 tests: CLI: add simple test running python example
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     1
#!/bin/bash
6210c08c1c41 tests: CLI: add simple test running python example
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     2
3672
230c8b90f3dc Tests: Add OPC-UA server browsing and veriable picking UI test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3549
diff changeset
     3
echo "Instant OPC-UA server for test"
3543
6210c08c1c41 tests: CLI: add simple test running python example
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     4
3549
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
     5
# Run server
3672
230c8b90f3dc Tests: Add OPC-UA server browsing and veriable picking UI test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3549
diff changeset
     6
exec $BEREMIZPYTHONPATH - << EOF
3543
6210c08c1c41 tests: CLI: add simple test running python example
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     7
3549
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
     8
import sys
3718
7841b651d601 Tests: OPCUA tests can now use OPCUA_DEFAULT_HOST environment variable to force host to something else than "127.0.0.1" or "localhost"
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3672
diff changeset
     9
import os
3549
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    10
import time
3820
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    11
import asyncio
3549
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    12
3820
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    13
from asyncua import Server
3549
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    14
3820
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    15
async def main():
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    16
    server = Server()
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    17
    host = os.environ.get("OPCUA_DEFAULT_HOST", "127.0.0.1")
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    18
    endpoint = "opc.tcp://"+host+":4840/freeopcua/server/"
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    19
    await server.init()
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    20
    server.set_endpoint(endpoint)
3549
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    21
3820
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    22
    uri = "http://beremiz.github.io"
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    23
    idx = await server.register_namespace(uri)
3549
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    24
3820
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    25
    objects = server.get_objects_node()
3549
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    26
3820
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    27
    testobj = await objects.add_object(idx, "TestObject")
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    28
    testvarout = await testobj.add_variable(idx, "TestOut", 1.2)
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    29
    testvar = await testobj.add_variable(idx, "TestIn", 5.6)
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    30
    await testvar.set_writable()
3549
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    31
3820
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    32
    await server.start()
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    33
    try:
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    34
        while True:
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    35
            await asyncio.sleep(1)
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    36
            inval = await testvar.get_value()
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    37
            print(inval)
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    38
            await testvarout.set_value(inval*2)
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    39
            sys.stdout.flush()
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    40
    finally:
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    41
        await server.stop()
3549
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    42
3820
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    43
asyncio.run(main())
46f3ca3f0157 OPC-UA client : python3 + AsyncUA fixes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3718
diff changeset
    44
3549
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    45
EOF