Commit 31045f10 authored by Philipp's avatar Philipp

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

parent 20b9b9fa
...@@ -24,32 +24,43 @@ xml = args.xml ...@@ -24,32 +24,43 @@ 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__)
_logger.info("Connecting to %s ...", url) _logger.info("Connecting to %s ...", url)
async with Client(url=url, timeout=2) as client: async with Client(url=url, timeout=2) as client:
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
# Get the Powerfuse object objects = await root.get_child("0:Objects")
s="Powerfuse_Maschinenstatus_Status_Rot"
var = await client.nodes.root.get_child(f"0:Objects/{nsidx}:Powerfuse/{nsidx}:{s}") # Get the Powerfuse object
value = await var.read_value() powerfuse_obj = await objects.get_child("1:Powerfuse")
name = await var.read_browse_name()
_logger.info(f"Value of {s} ({var}): {value}") # Get the variables
machine_status_rot = await powerfuse_obj.get_child("1:Powerfuse_Maschinenstatus_Status_Rot")
s="Powerfuse_Maschinenstatus_Status_Gelb" machine_status_gelb = await powerfuse_obj.get_child("1:Powerfuse_Maschinenstatus_Status_Gelb")
var = await client.nodes.root.get_child(f"0:Objects/{nsidx}:Powerfuse/{nsidx}:{s}")
value = await var.read_value() # Read values
name = await var.read_browse_name() value_rot = await machine_status_rot.read_value()
_logger.info(f"Value of {s} ({var}): {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__": 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