aboutsummaryrefslogtreecommitdiff
path: root/acquisition/hardware.py
blob: 2d062e2ab057e11f9b0ec38716650ebe59392e3c (plain)
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
class Hardware(pc.Hardware):

    def __init__(self, *args, **kwargs):
        pc.Hardware.__init__(self, *args, **kwargs)
        self.exposed = self.driver.exposed
        for obj in self.exposed:
            obj.updated.connect(self.update)
        self.recorded = self.driver.recorded
        self.offset = self.driver.offset
        self.position = self.exposed[0]
        self.native_units = self.driver.native_units
        self.destination = pc.Number(units=self.native_units, display=True)
        self.destination.write(self.position.read(self.native_units),
                               self.native_units)
        self.limits = self.driver.limits
        self.driver.initialized_signal.connect(self.on_address_initialized)
        hardwares.append(self)

    def set_offset(self, offset, input_units=None):
        if input_units is None:
            pass
        else:
            offset = wt.units.converter(offset, input_units,
                                        self.native_units)
        # do nothing if new offset is same as current offset
        if offset == self.offset.read(self.native_units):
            return
        self.q.push('set_offset', offset)

    def set_position(self, destination, input_units=None, force_send=False):
        if input_units is None:
            pass
        else:
            destination = wt.units.converter(destination, input_units,
                                             self.native_units)
        # do nothing if new destination is same as current destination
        if destination == self.destination.read(self.native_units):
            if not force_send:
                return
        self.destination.write(destination, self.native_units)
        self.q.push('set_position', destination)