Ejemplo n.º 1
0
    def _HW_rawCommand(self, cmd, par=0):
        if cmd not in self._HW_CMDS:
            raise ValueError('Command code %r not supported, check code and '
                             'docu!' % cmd)
        cmd = int(self._HW_CMDS.get(cmd, cmd))

        pswd = 16082008 + ((int(cmd) + int(par)) % 228)
        self.log.debug('Initiate command %d with par %d and pswd %d',
                       cmd, par, pswd)
        self._writeU32(16, int(par))
        self._writeU32(12, int(pswd))
        self._writeU32(14, int(cmd))

        self.log.debug('checking reaction')
        session.delay(0.1)
        for _ in range(10):
            ack = bool(self._HW_readACK())
            nack = bool(self._HW_readNACK())
            self.log.debug('%s %s', ack, nack)
            if ack and not nack:
                self.log.debug('Command accepted')
                return
            elif nack and not ack:
                raise NicosError('Command rejected by Beckhoff')
        raise NicosTimeoutError('Command not recognized by Beckhoff within 1s!')
Ejemplo n.º 2
0
 def _wait_for(self, sig, name):
     i = 0
     while self._attached_status_in.read(0) != sig:
         session.delay(0.1)
         i += 1
         if i == 100:
             raise NicosTimeoutError(
                 self, 'timeout waiting for %s '
                 'signal from spectrometer' % name)
Ejemplo n.º 3
0
 def _wait_for_shutdown(self):
     timeout = time.time() + self.offtimeout
     while time.time() < timeout:
         time.sleep(1)
         for dev in self._attached_ephvs:
             if dev.read(0) > self.offlimit:
                 break
         else:
             return
     raise NicosTimeoutError(self, 'timeout waiting for HV to ramp down')
Ejemplo n.º 4
0
 def _HW_wait_while_HOT(self):
     sd = 6.5
     anz = int(round(self.waittime * 60 / sd))
     # Pech bei 2.session
     for a in range(anz):
         temp = max(self.motortemp)
         if temp < self.maxtemp:  # wait if temp>33 until temp<26
             if a:
                 self.log.info('%d Celsius continue', temp)
             else:
                 self.log.debug('%d Celsius continue', temp)
             return True
         self.log.info('%d Celsius Timeout in: %.1f min', temp,
                       (anz - a) * sd / 60)
         session.delay(sd)
     raise NicosTimeoutError('HW still HOT after {0:d} min'.format(
         self.waittime))
Ejemplo n.º 5
0
 def _HW_wait_while_BUSY(self, timeout=100):
     # XXX timeout?
     # XXX rework !
     delay = 0.1
     while timeout > 0:
         session.delay(delay)
         statval = self._readStatusWord()
         # self.log.info('statval = 0x%04X', statval)
         # if motor moving==0 and target ready==1 -> Ok
         if (statval & 0b10100000 == 0) and \
            (statval & 0b100000000) and \
            (statval & 0b1):
             return
         # limit switch triggered or stop issued
         if statval & (7 << 10):
             session.delay(0.5)
             return
         timeout -= delay
     raise NicosTimeoutError('HW still BUSY after %d s' % timeout)
Ejemplo n.º 6
0
def waitfor(dev, condition, timeout=86400):
    """Wait for a device until a condition is fulfilled.

    Convenience function to avoid writing code like this:

    >>> while not motor.read() < 10:
    ...     sleep(0.3)

    which now can be written as:

    >>> waitfor(motor, '< 10')

    The supported conditions are [#]_:

    - '<', '<=', '==', '!=', '>=', '>' with a value
    - 'is False', 'is True', 'is None'
    - 'in list', where list could be a Python list or tuple

    An optional timeout value can be added, which denominates the maximum time
    the command will wait (in seconds).  If the timeout value is reached, an
    error will be raised.  The default timeout value is 86400 seconds (1 day).
    Example:

    >>> waitfor(T, '< 10', timeout=3600)

    Will wait a maximum of 1 hour for T to get below 10.

    .. note::

       In contrast to the `wait()` command this command will not only wait
       until the target is reached.  You may define also conditions which
       represent intermediate states of a movement or you may wait on
       external trigger signals and so on.

    .. [#] The device value, determined by ``dev.read()``, will be added in
       front of the condition, so the resulting conditions is:

        >>> dev.read() < 10

       The condition parameter will be given as a simple comparison to
       the value of the device.
    """
    dev = session.getDevice(dev, Readable)
    full_condition = '_v %s' % condition

    try:
        ast.parse(full_condition)
    except Exception:
        raise UsageError('Could not parse condition %r' % condition)

    if session.mode == SIMULATION:
        return

    def check(tmr):
        session.breakpoint(2)  # allow break and continue here
        waitfor.cond_fulfilled = eval(full_condition, {}, {'_v': dev.read(0)})
        if waitfor.cond_fulfilled:
            session.log.info('Waiting for \'%s %s\' finished.', dev, condition)
            tmr.stop()

    waitfor.cond_fulfilled = False
    try:
        session.beginActionScope('Waiting until %s %s' % (dev, condition))
        tmr = Timer(timeout if timeout else 86400)  # max wait time 1 day
        tmr.wait(dev._base_loop_delay * 3, check)
    finally:
        if not waitfor.cond_fulfilled:
            raise NicosTimeoutError(
                dev, 'Waiting for \'%s %s\' timed out.' % (dev, condition))
        session.endActionScope()