Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- import pprint
- from asyncua import Client
- from asyncua.ua import DataValue
- def make_node_path(namespace, path):
- parts = ".".join(f'"{part}"' for part in path.split("."))
- return f"ns={namespace};s={parts}"
- async def main(paths):
- values = {}
- async with Client("opc.tcp://192.168.10.10:4840/") as client:
- ns = await client.get_namespace_index("http://www.siemens.com/simatic-s7-opcua")
- for path in paths:
- node_path = make_node_path(ns, path)
- node = client.get_node(node_path)
- values[node_path] = await node.get_value()
- return values
- if __name__ == "__main__":
- nodes = ["DataExchange.operator_panel.S1", "I0", "I1", "I2"]
- coro = main(nodes)
- result = asyncio.run(coro)
- pprint.pprint(result, sort_dicts=False, compact=True, indent=4)
Add Comment
Please, Sign In to add comment