File: low-level-api.py

package info (click to toggle)
pytango 10.1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,304 kB
  • sloc: python: 27,795; cpp: 16,150; sql: 252; sh: 152; makefile: 43
file content (58 lines) | stat: -rwxr-xr-x 1,451 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
# SPDX-FileCopyrightText: All Contributors to the PyTango project
# SPDX-License-Identifier: LGPL-3.0-or-later

"""Trivial example of a low-level API device server."""

import sys
import tango


class Motor(tango.Device_6Impl):
    def __init__(self, cl, name):
        tango.Device_6Impl.__init__(self, cl, name)
        Motor.init_device(self)

    def delete_device(self):
        pass

    def init_device(self):
        self.get_device_properties(self.get_device_class())
        self.attr_position_read = 1.0

    def always_executed_hook(self):
        pass

    def read_position(self, attr):
        attr.set_value(self.attr_position_read)

    def read_attr_hardware(self, data):
        pass


class MotorClass(tango.DeviceClass):
    class_property_list = {}
    device_property_list = {}
    cmd_list = {}
    attr_list = {"position": [[tango.DevDouble, tango.SCALAR, tango.READ]]}

    def __init__(self, name):
        tango.DeviceClass.__init__(self, name)
        self.set_type(name)


def main():
    try:
        util = tango.Util(sys.argv)
        util.add_class(MotorClass, Motor, "Motor")
        U = tango.Util.instance()
        U.server_init()
        U.server_run()
    except tango.DevFailed as exc:
        print(f"-------> Received a DevFailed exception: {exc}")
    except Exception as exc:
        print(f"-------> An unforeseen exception occurred: {exc}")


if __name__ == "__main__":
    main()