Passed
Pull Request — master (#372)
by
unknown
02:30
created

client-file   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A read_file() 0 18 2
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