Commit 31045f10 authored by Philipp's avatar Philipp

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

parent 20b9b9fa
...@@ -24,8 +24,8 @@ xml = args.xml ...@@ -24,8 +24,8 @@ xml = args.xml
# Server information # Server information
if bool(int(ipv6_enabled)): if bool(int(ipv6_enabled)):
url = "opc.tcp://[{ipv6}]:{port}/PwDC" url = f"opc.tcp://[{ipv6}]:{port}/PwDC"
#url = "opc.tcp://0.0.0.0:4880/PwDC" #url = "opc.tcp://[0.0.0.0]:4840/PwDC"
async def main(): async def main():
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
...@@ -34,22 +34,33 @@ async def main(): ...@@ -34,22 +34,33 @@ async def main():
while True: while True:
await asyncio.sleep(1) await asyncio.sleep(1)
# Get the root node # Get the root node
#namespace_uri = "http://examples.freeopcua.github.io" root = client.get_root_node()
#nsidx = await client.get_namespace_index(namespace_uri)
nsidx = 1 # Get the objects node
objects = await root.get_child("0:Objects")
# Get the Powerfuse object # Get the Powerfuse object
s="Powerfuse_Maschinenstatus_Status_Rot" powerfuse_obj = await objects.get_child("1:Powerfuse")
var = await client.nodes.root.get_child(f"0:Objects/{nsidx}:Powerfuse/{nsidx}:{s}")
value = await var.read_value() # Get the variables
name = await var.read_browse_name() machine_status_rot = await powerfuse_obj.get_child("1:Powerfuse_Maschinenstatus_Status_Rot")
_logger.info(f"Value of {s} ({var}): {value}") machine_status_gelb = await powerfuse_obj.get_child("1:Powerfuse_Maschinenstatus_Status_Gelb")
s="Powerfuse_Maschinenstatus_Status_Gelb" # Read values
var = await client.nodes.root.get_child(f"0:Objects/{nsidx}:Powerfuse/{nsidx}:{s}") value_rot = await machine_status_rot.read_value()
value = await var.read_value() value_gelb = await machine_status_gelb.read_value()
name = await var.read_browse_name() _logger.info(f"Initial values: Rot={value_rot}, Gelb={value_gelb}")
_logger.info(f"Value of {s} ({var}): {value}")
# 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__": if __name__ == "__main__":
logging.basicConfig(level=logging.INFO) 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