def __init__(self, name, parent, **kwargs): self.__enable_polling = False self.call__init__(TaurusAttribute, name, parent) self.parent = parent self._validator = TangoArchivingAttributeNameValidator() groups = self._validator.getUriGroups(name) self._start_date = None self._end_date = None self._return_timestamps = False arch_label = "(archiving)" self._query = groups.get('query', None) if self._query is not None: for query_elem in self._query.split(';'): if 't0=' in query_elem: self._start_date = query_elem[3:] if 't1=' in query_elem: self._end_date = query_elem[3:] if self._end_date == 'now': self._end_date = time.time() if 'ts' in query_elem: self._return_timestamps = True arch_label = "(archiving ts)" self._arch_values = TaurusAttrValue() self._arch_timestamps = TaurusAttrValue() # set the label self._tg_attr_name = groups.get('attrname') self._label = "{} {}".format(self._tg_attr_name, arch_label)
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)
def decode(self, event_value): if isinstance(event_value, int): # TaurusSWDevState new_sw_state = event_value else: self.info("Unexpected value to decode: %s" % str(event_value)) new_sw_state = TaurusDevState.NotReady value = TaurusAttrValue() value.rvalue = new_sw_state return value
def decode(self, event_value): # TODO: Is this method ever called? (or maybe just garbage from 3.x?) if isinstance(event_value, int): # TaurusSWDevState new_sw_state = event_value else: self.info("Unexpected value to decode: %s" % str(event_value)) new_sw_state = TaurusDevState.NotReady value = TaurusAttrValue() value.rvalue = new_sw_state return value
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
def read(self, cache=True): if cache and self._last_value is not None: return self._last_value dev = self.getParentObj() # each time we need to open and close the file, otherwise the # file content is not updated with h5py.File(dev.filename) as h5file: data = h5file.get(self._attr_name) if data is None: msg = "Object %s does not exist" % self._attr_name raise TaurusException(msg) # we need to decode and copy the data while the file is still opened rvalue = self.decode(data) value = TaurusAttrValue() value.rvalue = rvalue value.time = TaurusTimeVal.now() self._last_value = value return value
def decode(self, pv): """Decodes an epics PV object into a TaurusValue, and also updates other properties of the Attribute object """ attr_value = TaurusAttrValue() if not pv.connected: attr_value.error = ChannelAccessException('PV "%s" not connected' % pv.pvname) return attr_value v = pv.value # type try: self.type = Dbr2TaurusType[pv.ftype] except KeyError: raise ValueError('Unsupported epics type "%s"' % pv.type) # writable self.writable = pv.write_access # data_format if numpy.isscalar(v): self.data_format = DataFormat._0D else: self.data_format = DataFormat(len(numpy.shape(v))) # units and limits support if self.type in (DataType.Integer, DataType.Float): v = Quantity(v, pv.units) self._range = self.__decode_limit(pv.lower_ctrl_limit, pv.upper_ctrl_limit) self._alarm = self.__decode_limit(pv.lower_alarm_limit, pv.upper_alarm_limit) self._warning = self.__decode_limit(pv.lower_warning_limit, pv.upper_warning_limit) # rvalue attr_value.rvalue = v # wvalue if pv.write_access: attr_value.wvalue = v # time if pv.timestamp is None: attr_value.time = TaurusTimeVal.now() else: attr_value.time = TaurusTimeVal.fromtimestamp(pv.timestamp) # quality if pv.severity > 0: attr_value.quality = AttrQuality.ATTR_ALARM else: attr_value.quality = AttrQuality.ATTR_VALID return attr_value
def read(self, cache=True): """Returns the value of the attribute. :param cache: (bool) If True (default), the last calculated value will be returned. If False, the referenced values will be re- read. :return: TaurusAttrValue """ if cache and self._last_value is not None: return self._last_value dev = self.getParentObj() self.handler.setFilename(dev.filename) data_frame = self.handler.parseAttrName(self._attr_name) value = TaurusAttrValue() value.rvalue = self.decode(data_frame) value.time = TaurusTimeVal.now() self._last_value = value return value
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)