Example #1
0
def move_dev(dev, pos, sleeptime=0, maxtries=3):
    session.log.info('Moving %s to %f', dev, pos)
    d = session.getDevice(dev)
    for _ in range(maxtries):
        d.maw(pos)
        if sleeptime:
            sleep(sleeptime)
        if abs(d.read() - pos) < d.precision:
            return
    raise PositionError(dev, 'Could not move %d to %f' % (dev, pos))
Example #2
0
def wait(*devlist):
    """Wait until motion/action of one or more devices is complete.

    This command can wait until a device, a list of devices or all devices have
    finished their movement or action, i.e. the status of the devices is no
    longer "busy".

    The "busy" status is device specific, but in general a moveable device,
    started by the `move()` command, is going to the target, while a detector
    device, e.g. started by the `count()` command, is counting.

    The following example waits for all devices, which can be used to ensure
    that no device is moving or counting before the next step starts.

    >>> wait()

    The next example waits for the T (typically the sample temperature) and B
    (typically the magnetic field):

    >>> wait(T, B)    # wait for T and B devices

    Sometimes the user wants to wait an additional time after all given devices
    left the "busy" state. This can be given by a number (the unit is seconds).
    The next example waits until T leaves the "busy" state and thereafter 60
    seconds before the next command is executed.

    >>> wait(T, 60)   # wait for the T device, then another 60 seconds

    The same can be done with the following sequence:

    >>> wait(T)
    >>> sleep(60)

    .. note::
        The difference is that this version can be interrupted between the
        `wait()` and `sleep()` commands.
    """
    if not devlist:
        devlist = [
            session.devices[devname] for devname in session.explicit_devices
            if isinstance(session.devices[devname], Waitable)
        ]
    for dev in devlist:
        if isinstance(dev, number_types):
            sleep(dev)
            continue
        dev = session.getDevice(dev, Waitable)
        dev.log.info('waiting for device')
        try:
            value = dev.wait()
        except Exception:
            dev.log.exception('error waiting for device')
            continue
        if value is not None:
            dev.log.info('at %20s %s', dev.format(value), dev.unit)
Example #3
0
    def waitForAcq(self, retries):
        if not self.acqIsCounting():
            return True

        while retries:
            sleep(0.5)
            retries -= 1
            if not self.acqIsCounting():
                return True
        self.log.warning('Doppler speed can not be changed while '
                         'SIS is counting.')
        return False
Example #4
0
def pole_figure(numrows, speed, timedelta, sampleinfo):
    """Run a typical pole figure measurement.

    The command runs 'numrows' continuous scans over the 'phis' device, which
    makes a full turn (360 deg) during the measurement.

    The changed parameter device is 'chis'. It divides the angle of 90 deg into
    'numrows' steps, starting at the half of the stepsize. A 'numrows' of 6
    will generate the 'chis' positions of 172.5, 157.5, 142.5, 127.5, 112.5,
    and 97.5 deg.

    Examples::

        # create a pole figure measurement with 6 steps taking every 10 s a
        # picture
        >>> pole_figure(6, 0.25, 10, 'Alpha_Ti')

    """
    chis = session.getDevice('chis')
    phis = session.getDevice('phis')
    dchi = round(90.0 / numrows, 2) / 2.0
    # creating a list beginnig from 180 + dchi downsteps to 90 + dchi
    positions = numpy.arange(90 + dchi, 180, 2 * dchi)[::-1]
    maw(phis, 0)
    for i, chipos in enumerate(positions):
        move_dev(chis, round(chipos, 2), maxtries=2)
        sleep(5)
        start, end = (360., 0.) if i % 2 else (0., 360.)
        contscan(phis, start, end, speed, timedelta,
                 '%s_Chis_%s' % (sampleinfo, str(chis.read())))
    sleep(5)
    maw(phis, 0)
    sleep(5)
    maw(chis, 180)
    sleep(5)
Example #5
0
def test_special_behavior(session):
    oldtime = session.clock.time
    sleep(1000)  # should take no time in simulation mode, but advance clock
    newtime = session.clock.time
    assert newtime - oldtime == 1000
Example #6
0
 def test_sleep_command(self, session, log):
     tosleep = 0.1
     with log.assert_msg_matches(r'sleeping for %.1f seconds\.\.\.' %
                                 tosleep):
         used = timeit.timeit(lambda: sleep(tosleep), number=1)
     assert tosleep < used < 1.3 * tosleep