SAMPLES = 20 TOLERANCE = 0.01 TIMEOUT = 10.0 intensity = ChannelDouble("intensity", "SARFE10-PBPG050:PHOTON-ENERGY-PER-PULSE-US") intensity.initialize() gap = Channel(GAP + ":GAP_SP", alias = "gap") readout = Channel(GAP + ":GAP") av = create_averager(intensity, SAMPLES, interval = -1, name = None) def before(position, scan): caput(GAP + ":GO", 1) start = time.time() while abs(readout.read() - gap.read()) > TOLERANCE: time.sleep(0.1) if time.time() - start > TIMEOUT: raise Exception ("Timeout waiting gap change") ret = lscan (gap, av, 17.5, 19.5, 40, latency=10.0, before_read=before)