File: IfchangeServer.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 (70 lines) | stat: -rw-r--r-- 1,926 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
59
60
61
62
63
64
65
66
67
68
69
70
import logging

import tango

from tango.server import Device
from tango.server import attribute, command


class IfchangeServer(Device):
    def init_device(self):
        Device.init_device(self)
        logging.basicConfig(level=logging.DEBUG)
        self._current = 0.0
        self.set_state(tango.DevState.ON)

    @attribute(label="Sequence Counter", dtype="int", description="Sequence counter")
    def seq_counter(self):
        return 456

    @attribute(label="Voltage", dtype="float", description="voltage")
    def volts(self):
        return 3.142

    def read_current(self):
        print("read current method ", self._current)
        return self._current

    def write_current(self, curr):
        self._current = curr
        print("set current to ", self._current)

    def start(self, argin):
        print("start method")
        return 3142

    @command(dtype_in=str, doc_in="name of dynamic attribute to add")
    def add_dyn_attr(self, name):
        attr = attribute(
            name=name, dtype="float", fget=self.read_current, fset=self.write_current
        )
        self.add_attribute(attr)

    @command(dtype_in=str, doc_in="name of dynamic attribute to delete")
    def delete_dyn_attr(self, name):
        self._remove_attribute(name)

    @command
    def add_dyn_cmd(self):
        device_level = True
        cmd = command(
            f=self.start,
            dtype_in=str,
            dtype_out=int,
            doc_in="description of input",
            doc_out="description of output",
            display_level=tango.DispLevel.EXPERT,
            polling_period=5100,
        )
        self.add_command(cmd, device_level)

    @command(dtype_in=str, doc_in="name of dynamic command to delete")
    def delete_dyn_cmd(self, name):
        self._remove_command(name, False, True)


# ----------
# Run server
# ----------
if __name__ == "__main__":
    IfchangeServer.run_server()