Commit 31045f10 authored by Philipp's avatar Philipp

Update opcua-client-fhi/minimal-client.py

parent 20b9b9fa
......@@ -24,8 +24,8 @@ xml = args.xml
# Server information
if bool(int(ipv6_enabled)):
url = "opc.tcp://[{ipv6}]:{port}/PwDC"
#url = "opc.tcp://0.0.0.0:4880/PwDC"
url = f"opc.tcp://[{ipv6}]:{port}/PwDC"
#url = "opc.tcp://[0.0.0.0]:4840/PwDC"
async def main():
_logger = logging.getLogger(__name__)
......@@ -34,22 +34,33 @@ async def main():
while True:
await asyncio.sleep(1)
# Get the root node
#namespace_uri = "http://examples.freeopcua.github.io"
#nsidx = await client.get_namespace_index(namespace_uri)
nsidx = 1
root = client.get_root_node()
# Get the objects node
objects = await root.get_child("0:Objects")
# Get the Powerfuse object
s="Powerfuse_Maschinenstatus_Status_Rot"
var = await client.nodes.root.get_child(f"0:Objects/{nsidx}:Powerfuse/{nsidx}:{s}")
value = await var.read_value()
name = await var.read_browse_name()
_logger.info(f"Value of {s} ({var}): {value}")
s="Powerfuse_Maschinenstatus_Status_Gelb"
var = await client.nodes.root.get_child(f"0:Objects/{nsidx}:Powerfuse/{nsidx}:{s}")
value = await var.read_value()
name = await var.read_browse_name()
_logger.info(f"Value of {s} ({var}): {value}")
powerfuse_obj = await objects.get_child("1:Powerfuse")
# Get the variables
machine_status_rot = await powerfuse_obj.get_child("1:Powerfuse_Maschinenstatus_Status_Rot")
machine_status_gelb = await powerfuse_obj.get_child("1:Powerfuse_Maschinenstatus_Status_Gelb")
# Read values
value_rot = await machine_status_rot.read_value()
value_gelb = await machine_status_gelb.read_value()
_logger.info(f"Initial values: Rot={value_rot}, Gelb={value_gelb}")
# Write values
await machine_status_rot.write_value(True)
await machine_status_gelb.write_value(False)
### write the values to the opcua-to-http-gw-service opc.tcp://[2001:67c:1254:108:404e::9]:4840/freeopcua/server/
# Currently there is just one
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
asyncio.run(main())
asyncio.run(main(), debug=False)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment