# ***************************************************************************** # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 2 of the License, or (at your option) any later # version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Module authors: # Markus Zolliker # # ***************************************************************************** """helper devices for lab experiments""" import time from nicos.core import Override, Param, Measurable from nicos.core.params import Value class Timestamp(Measurable): """to be used as a 'detector' in lab experiments just waiting the preset time """ parameter_overrides = { 'unit': Override(default='sec', mandatory=False), } parameters = { 'show': Param('show timestamp in data file', type=bool, settable=True, default=True, mandatory=False), } _preset = 0 _time_used = 0 _start = 0 def _getCache(self): """no cache needed""" self._cache = None def doRead(self, maxage=0): return time.time() def doStatus(self, maxage=0): return 100, '' def doSetPreset(self, t=0, **preset): self._start = 0 self._preset = t self._value = 0 def doStart(self): self._start = time.time() def doPause(self): self._time_used = time.time() - self._start return True def doResume(self): self._start = time.time() - self._time_used def doFinish(self): pass def doStop(self): pass def doIsCompleted(self): return time.time() > self._start + self._preset def valueInfo(self): if self.show: return Measurable.valueInfo(self) return () class Det(Measurable): """wrap a Readable into a Detector just for placing the result in a scan file in the detector part """ temporary = True def __init__(self, dev): self._dev = dev Measurable.__init__(self, str(dev), unit=dev.unit, fmtstr=dev.fmtstr) def _getCache(self): """no cache needed""" self._cache = None def doRead(self, maxage=0): return self._dev.doRead(maxage) def doStatus(self, maxage=0): return self._dev.doStatus(maxage) def doSetPreset(self, t=5, **preset): self._start = 0 self._preset = t def doStart(self): self._start = time.time() def doFinish(self): pass def doStop(self): self._start = 0 def doIsCompleted(self): return time.time() > self._start + self._preset def valueInfo(self): return Value(self.name, unit=self.unit, fmtstr=self.fmtstr),