Ejemplo n.º 1
0
def is_numerical(obj):
    if is_number(obj):
        return True
    if is_non_str_seq(obj) or isinstance(obj, numpy.ndarray):
        if is_number(obj[0]):
            return True
        elif is_non_str_seq(obj[0]) or isinstance(obj, numpy.ndarray):
            if is_number(obj[0][0]):
                return True
    return False
Ejemplo n.º 2
0
 def _from_ctrl_state_info(self, state_info):
     state_info, _ = state_info
     if len(state_info) > 2:
         state, status, ls = state_info[:3]
     else:
         state, other = state_info[:2]
         if is_number(other):
             ls, status = other, None
         else:
             ls, status = 0, other
     state, ls = int(state), tuple(map(bool, (ls & 1, ls & 2, ls & 4)))
     return state, status, ls
Ejemplo n.º 3
0
    def _from_ctrl_state_info(self, state_info):
        state_info, _ = state_info

        try:
            state_str = State.whatis(state_info)
            return int(state_info), "{0} is in {1}".format(self.name, state_str), 0
        except KeyError:
            pass

        if len(state_info) > 2:
            state, status, ls = state_info[:3]
        else:
            state, other = state_info[:2]
            if is_number(other):
                ls, status = other, ''
            else:
                ls, status = 0, other
        state, ls = int(state), tuple(map(bool, (ls & 1, ls & 2, ls & 4)))
        return state, status, ls
Ejemplo n.º 4
0
    def calc_position(self, dial=None):
        """Returns the computed position from last the dial position from the
        given parameter or (if None), the last dial position obtained from
        hardware read.

        :param dial: the new dial position [default: None, meaning use the
                     current dial position.
        :return: the computed user position
        :rtype: obj

        :raises:
            :exc:`Exception` if dial_position is None and no read value has
            been set yet"""
        obj = self.obj
        if dial is None:
            dial_attr = obj.dial_position
            if dial_attr.in_error():
                raise dial_attr.exc_info[1]
            dial = dial_attr.value
        if not is_number(dial):
            raise Exception("Controller returns not a number %s" % dial)
        sign, offset = obj.sign.value, obj.offset.value
        return sign * dial + offset
Ejemplo n.º 5
0
    def init(self, door_name=None):
        if door_name is None:
            door_name = getattr(sardanacustomsettings, 'UNITTEST_DOOR_NAME')

        # TODO: As a workaround: check with PyTango that the door is running
        # in case of exception raise a RuntimeError. Ideally it should be done
        # just using taurus
        try:
            import PyTango
            d = PyTango.DeviceProxy(door_name)
            # when building docs, in RTD environment, PyTango is a mock
            assert is_number(d.ping())
        except:
            raise RuntimeError("Door %s is not running" % door_name)

        registerExtensions()

        self.door = Device(door_name)
        self.ms = self.door.macro_server

        self.controllers = None
        self.cts = None
        self.motors = None
        self.pseudos = None
        self.zerods = None
        self.oneds = None
        self.twods = None

        try:
            self.env = self.ms.getEnvironment()['_SAR_DEMO']['elements'] + \
                list(self.ms.getEnvironment()['_SAR_DEMO']['controllers'])
        except KeyError:
            err = 'sar_demo has not been executed (or door %s not ready)' % \
                  door_name
            raise RuntimeError(err)
        self.ready = True
Ejemplo n.º 6
0
    def init(self, door_name=None):
        if door_name is None:
            door_name = getattr(sardanacustomsettings, 'UNITTEST_DOOR_NAME')

        # TODO: As a workaround: check with PyTango that the door is running
        # in case of exception raise a RuntimeError. Ideally it should be done
        # just using taurus
        try:
            import PyTango
            d = PyTango.DeviceProxy(door_name)
            # when building docs, in RTD environment, PyTango is a mock
            assert is_number(d.ping())
        except:
            raise RuntimeError("Door %s is not running" % door_name)

        registerExtensions()

        self.door = Device(door_name)
        self.ms = self.door.macro_server

        self.controllers = None
        self.cts = None
        self.motors = None
        self.pseudos = None
        self.zerods = None
        self.oneds = None
        self.twods = None

        try:
            self.env = self.ms.getEnvironment()['_SAR_DEMO']['elements'] + \
                list(self.ms.getEnvironment()['_SAR_DEMO']['controllers'])
        except KeyError:
            err = 'sar_demo has not been executed (or door %s not ready)' % \
                  door_name
            raise RuntimeError(err)
        self.ready = True