File: asyncio_simple_example.py

package info (click to toggle)
pytango 10.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,216 kB
  • sloc: python: 28,206; cpp: 16,380; sql: 255; sh: 82; makefile: 43
file content (27 lines) | stat: -rw-r--r-- 776 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# SPDX-FileCopyrightText: All Contributors to the PyTango project
# SPDX-License-Identifier: LGPL-3.0-or-later
import asyncio
from tango.asyncio import DeviceProxy


async def asyncio_example():
    dev = await DeviceProxy("sys/tg_test/1")
    print(dev.get_green_mode())

    print(await dev.state())

    # in case of high-level API read has to be awaited
    print(await dev.long_scalar)
    print(await dev["long_scalar"])
    print(await getattr(dev, "long_scalar"))

    # while write executed sync
    dev.long_scalar = 1

    # for low-level API both read_attribute and write_attribute have to be awaited
    print(await dev.read_attribute("long_scalar"))
    await dev.write_attribute("long_scalar", 1)


if __name__ == "__main__":
    asyncio.run(asyncio_example())