| Total Complexity | 2 |
| Total Lines | 27 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import asyncio |
||
| 2 | from asyncua import ua |
||
| 3 | from asyncua.client import Client |
||
| 4 | from asyncua.client.ua_file import UaFile |
||
| 5 | |||
| 6 | async def read_file(): |
||
| 7 | """ read file example """ |
||
| 8 | |||
| 9 | url = "opc.tcp://10.0.0.199:4840" |
||
| 10 | async with Client(url=url) as client: |
||
| 11 | file_node = client.get_node("ns=2;s=NameOfNode") |
||
| 12 | ua_file_client = UaFile(file_node) |
||
| 13 | |||
| 14 | # open(), read(), close() all in one operation |
||
| 15 | contents = await ua_file_client.read_once() |
||
| 16 | print(contents) |
||
| 17 | |||
| 18 | # handling all methods by the user |
||
| 19 | handle = await ua_file_client.open(ua.OpenFileMode.Read.value) |
||
| 20 | size = await ua_file_client.get_size() |
||
| 21 | contents = await ua_file_client.read(handle, size) |
||
| 22 | await ua_file_client.close(handle) |
||
| 23 | print(contents) |
||
| 24 | |||
| 25 | |||
| 26 | asyncio.run(read_file()) |
||
| 27 |