tests/ide_tests/opcua_browse.sikuli/opcua_service.bash
author GP Orcullo <kinsamanka@gmail.com>
Fri, 28 Oct 2022 12:39:15 +0800
branchpython3
changeset 3750 f62625418bff
parent 3718 7841b651d601
child 3820 46f3ca3f0157
permissions -rw-r--r--
automated conversion using 2to3-3.9 tool

cmd used: 2to3-3.9 -w <file>
#!/bin/bash

echo "Instant OPC-UA server for test"

# Run server
exec $BEREMIZPYTHONPATH - << EOF

import sys
import os
import time

from opcua import ua, 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)

uri = "http://beremiz.github.io"
idx = server.register_namespace(uri)

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()

server.start()

try:
    while True:
        time.sleep(1)
        inval=testvar.get_value()
        print inval
        testvarout.set_value(inval*2)
        sys.stdout.flush()
finally:
    server.stop()
EOF