fshutter.py 2.69 KB
Newer Older
Emmanuel Papillon's avatar
Emmanuel Papillon committed
1
from bliss.config.settings import HashObjSetting
2
3

# from bliss.common.shutter import BaseShutter, BaseShutterState
Emmanuel Papillon's avatar
Emmanuel Papillon committed
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
from bliss import current_session


class FastShutter:
    def __init__(self, name, config):
        super().__init__()
        self.__name = name
        self.__config = config
        self.__shutter_mux = config["shutter_mux"]
        self.__session_mux = config["session_mux"]
        self.__settings = HashObjSetting(f"fastshutter:{name}")
        self.__time = None

    @property
    def name(self):
        return self.__name

    @property
    def config(self):
        return self.__config

    def __info__(self):
        info = f"FastShutter [{self.name}]:\n"
        info += f"Controlled by session = {self.session}\n"
        info += f"Shutter polarity      = {self.polarity}\n"
        info += f"Shutter mode          = {self.mode}\n"
        info += f"Shutter time          = {self.shutter_time:.3f} sec\n"
        return info

    @property
    def session(self):
        return self.__session_mux.getOutputStat("SHUTTER_SESSION")

    @session.setter
    def session(self, value):
        self.__session_mux.switch("SHUTTER_SESSION", value.upper())

    def __check_session(self):
        current = current_session.name.upper()
        if current != self.session:
            print("!!! FastShutter WARNING !!!")
            print(f"Session [{self.session}] is now controlling shutter")
            print("Current session has NO control !!!\n")

    @property
    def polarity(self):
        return self.__shutter_mux.getOutputStat("SHUTTER_POLARITY")

    @polarity.setter
    def polarity(self, value):
        self.__shutter_mux.switch("SHUTTER_POLARITY", value.upper())

    @property
    def shutter_time(self):
        if self.__time is None:
            self.__time = self.__settings.get("time", 0.)
        return self.__time

    @shutter_time.setter
    def shutter_time(self, value):
        self.__settings["time"] = value
        self.__time = None

67
68
69
70
    @property
    def multiplexer(self):
        return self.__shutter_mux
    
Emmanuel Papillon's avatar
Emmanuel Papillon committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
    def open(self, wait=False):
        self.__check_session()
        self.__shutter_mux.switch("SHUTTER", "OPEN")
        if wait:
            gevent.sleep(self.shutter_time)

    def close(self, wait=False):
        self.__check_session()
        self.__shutter_mux.switch("SHUTTER", "CLOSE")
        if wait:
            gevent.sleep(self.shutter_time)

    @property
    def state(self):
        return self.__shutter_mux.getOutputStat("SHUTTER")
86

Emmanuel Papillon's avatar
Emmanuel Papillon committed
87
88
89
90
91
92
    @property
    def mode(self):
        return self.__shutter_mux.getOutputStat("SHUTTER")

    @mode.setter
    def mode(self, value):
93
        self.__check_session()
Emmanuel Papillon's avatar
Emmanuel Papillon committed
94
        self.__shutter_mux.switch("SHUTTER", value.upper())