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): 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 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