Example #1
0
    def __init__(self, attr=None, pytango_dev_attr=None, config=None):
        # config parameter is kept for backwards compatibility only
        TaurusAttrValue.__init__(self)
        if config is not None:
            from taurus.core.util.log import deprecated
            deprecated(dep='"config" kwarg', alt='"attr"', rel='4.0')
            attr = config
        if attr is None:
            self._attrRef = None
        else:
            self._attrRef = weakref.proxy(attr)
        self.config = self._attrRef  # bck-compat

        self._pytango_dev_attr = p = pytango_dev_attr
        if p is None:
            self._pytango_dev_attr = p = PyTango.DeviceAttribute()
            return

        if self._attrRef is None:
            return

        numerical = (PyTango.is_numerical_type(self._attrRef._tango_data_type,
                                               inc_array=True)
                     or p.type == PyTango.CmdArgType.DevUChar)

        if p.has_failed:
            self.error = PyTango.DevFailed(*p.get_err_stack())
        else:
            # spectra and images can be empty without failing
            if p.is_empty and self._attrRef.data_format != DataFormat._0D:
                dtype = FROM_TANGO_TO_NUMPY_TYPE.get(
                    self._attrRef._tango_data_type)
                if self._attrRef.data_format == DataFormat._1D:
                    shape = (0, )
                elif self._attrRef.data_format == DataFormat._2D:
                    shape = (0, 0)
                p.value = numpy.empty(shape, dtype=dtype)
                if not (numerical or self._attrRef.type == DataType.Boolean):
                    # generate a nested empty list of given shape
                    p.value = []
                    for _ in xrange(len(shape) - 1):
                        p.value = [p.value]

        rvalue = p.value
        wvalue = p.w_value
        if numerical:
            units = self._attrRef._units
            if rvalue is not None:
                rvalue = Quantity(rvalue, units=units)
            if wvalue is not None:
                wvalue = Quantity(wvalue, units=units)
        elif isinstance(rvalue, PyTango._PyTango.DevState):
            rvalue = DevState[str(rvalue)]

        self.rvalue = rvalue
        self.wvalue = wvalue
        self.time = p.time  # TODO: decode this into a TaurusTimeVal
        self.quality = quality_from_tango(p.quality)
Example #2
0
 def __init__(self, attr=None, config=None):
     # config parameter is kept for backwards compatibility only
     TaurusAttrValue.__init__(self)
     if config is not None:
         from taurus.core.util.log import deprecated
         deprecated(dep='"config" kwarg', alt='"attr"', rel='4.0')
         attr = config
     if attr is None:
         self._attrRef = None
     else:
         self._attrRef = weakref.proxy(attr)
     self.config = self._attrRef
Example #3
0
 def __init__(self, attr=None, config=None):
     # config parameter is kept for backwards compatibility only
     TaurusAttrValue.__init__(self)
     if config is not None:
         from taurus.core.util.log import deprecated
         deprecated(dep='"config" kwarg', alt='"attr"', rel='4.0')
         attr = config
     if attr is None:
         self._attrRef = None
     else:
         self._attrRef = weakref.proxy(attr)
     self.config = self._attrRef
Example #4
0
    def __init__(self, attr=None, pytango_dev_attr=None, config=None):
        # config parameter is kept for backwards compatibility only
        TaurusAttrValue.__init__(self)
        if config is not None:
            from taurus.core.util.log import deprecated

            deprecated(dep='"config" kwarg', alt='"attr"', rel="4.0")
            attr = config
        if attr is None:
            self._attrRef = None
        else:
            self._attrRef = weakref.proxy(attr)
        self.config = self._attrRef  # bck-compat

        self._pytango_dev_attr = p = pytango_dev_attr
        if p is None:
            self._pytango_dev_attr = p = PyTango.DeviceAttribute()
            return

        if self._attrRef is None:
            return

        numerical = PyTango.is_numerical_type(self._attrRef._tango_data_type, inc_array=True)
        if p.has_failed:
            self.error = PyTango.DevFailed(*p.get_err_stack())
        else:
            if p.is_empty:  # spectra and images can be empty without failing
                dtype = FROM_TANGO_TO_NUMPY_TYPE.get(self._attrRef._tango_data_type)
                if self._attrRef.data_format == DataFormat._1D:
                    shape = (0,)
                elif self._attrRef.data_format == DataFormat._2D:
                    shape = (0, 0)
                p.value = numpy.empty(shape, dtype=dtype)
                if not (numerical or self._attrRef.type == DataType.Boolean):
                    # generate a nested empty list of given shape
                    p.value = []
                    for _ in xrange(len(shape) - 1):
                        p.value = [p.value]

        rvalue = p.value
        wvalue = p.w_value
        if numerical:
            units = self._attrRef._units
            if rvalue is not None:
                rvalue = Quantity(rvalue, units=units)
            if wvalue is not None:
                wvalue = Quantity(wvalue, units=units)
        elif isinstance(rvalue, PyTango._PyTango.DevState):
            rvalue = DevState[str(rvalue)]
        elif p.type == PyTango.CmdArgType.DevUChar:
            if self._attrRef.data_format == DataFormat._0D:
                rvalue = chr(rvalue)
                wvalue = chr(wvalue)
            else:
                rvalue = rvalue.view("S1")
                wvalue = wvalue.view("S1")

        self.rvalue = rvalue
        self.wvalue = wvalue
        self.time = p.time  # TODO: decode this into a TaurusTimeVal
        self.quality = quality_from_tango(p.quality)