tests/ide_tests/opcua_browse.sikuli/opcua_service.bash
author etisserant <edouard.tisserant@gmail.com>
Tue, 13 Dec 2022 22:04:16 +0100
changeset 3699 ddadbdf20e70
parent 3672 230c8b90f3dc
child 3718 7841b651d601
permissions -rw-r--r--
GH CI: try reverting to previous version of ubuntu
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
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
     9
import time
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
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
    11
from opcua import ua, Server
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
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
    13
server = Server()
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
server.set_endpoint("opc.tcp://127.0.0.1:4840/freeopcua/server/")
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
    15
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
    16
uri = "http://beremiz.github.io"
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
    17
idx = server.register_namespace(uri)
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
    18
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
    19
objects = server.get_objects_node()
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
    20
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
testobj = objects.add_object(idx, "TestObject")
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
    22
testvarout = testobj.add_variable(idx, "TestOut", 1.2)
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
    23
testvar = testobj.add_variable(idx, "TestIn", 5.6)
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
testvar.set_writable()
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
    25
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
server.start()
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
    27
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
    28
try:
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
    29
    while True:
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
    30
        time.sleep(1)
3672
230c8b90f3dc Tests: Add OPC-UA server browsing and veriable picking UI test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3549
diff changeset
    31
        inval=testvar.get_value()
230c8b90f3dc Tests: Add OPC-UA server browsing and veriable picking UI test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3549
diff changeset
    32
        print inval
230c8b90f3dc Tests: Add OPC-UA server browsing and veriable picking UI test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3549
diff changeset
    33
        testvarout.set_value(inval*2)
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
    34
        sys.stdout.flush()
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
    35
finally:
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
    36
    server.stop()
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
    37
EOF