#Parameters """ E1 = 800 E2 = 820 TIME = 1 #min DELAY = 0.1 #s MODE = 'LINEAR' OFFSET = 0.0 FOLDER = 'XAS/2020/11/SL-IN/' FILE = 'test' ALPHA=0.0 TAG=None """ print "\nStart energy scan..." #print E1,E2,TIME,DELAY,str(MODE) ,str(OFFSET) ,str(FOLDER) ,str(FILE) ,str(ALPHA) if MODE == "LINEAR": print E1,"eV ->",E2,"eV,",TIME,"min duration,",DELAY,"sec delay,",str(MODE),str(ALPHA),"deg" else: print E1,"eV ->",E2,"eV,",TIME,"min duration,",DELAY,"sec delay,",str(MODE) folder = os.path.expanduser("~/Data1/") + FOLDER + "/"; if TAG is not None: TAG = ("%03d" % (get_exec_pars().index,)) + "_" + TAG #set_exec_pars(name= FILE) #Pre-actions #if NO_BEAM_CHECK == False: # print "Wait beam" # wait_beam() if MODE is not None: print "Set polarization" pol_mode.write(MODE) if MODE == 'LINEAR': if ALPHA is not None: pol_angle.write(ALPHA) time.sleep(0.5) wait_pol_done(1.0) # new script to wait for polarization. Wait_device does not work for this channel. CP. Apr/22 print "Set offset" if OFFSET is not None: pol_offset.write(OFFSET) #wait_device(pol_done, "DONE") print "Set energy" energy.write(float(E1)) sleep(0.1) wait_channel(ALL_DONE, 1, type = 'i') caput('E1', E1) caput('E2', E2) caput('TIME', TIME) caput('FOLDER', FOLDER) caput('FILE', FILE) time.sleep(DELAY) caput('START', '1') #Pseudo-devices class Time(Readable): def __init__(self): self.start = time.time() def read(self): return time.time()-self.start class NORMtey(Readable): def read(self): return float(CADC2.take())/float(CADC1.take()) class NORMdiode(Readable): def read(self): return float(CADC3.take())/float(CADC1.take()) pol = pol_angle if (pol_mode.readback.read() == "LINEAR") else pol_mode #take pol angle or mode to save in the file. CP. Apr/22 scan_completed = False try: caput('START', '1') #sensors = [Ecrbk, CADC1, CADC2, CADC3, NORMtey(), NORMdiode()] sensors = [Ecrbk, CADC1, CADC2, CADC3, field, pol, NORMtey(), NORMdiode()] # add polarization and mag. field in file. CP. Apr/22 def monitoring_task(): global scan_completed time.sleep(1.0) try: plot_titles = [ "I0", "TEYraw", "TFYraw", "TEY", "TFY"] for index, title in enumerate(plot_titles, start=0): get_plots()[index].title = title except: pass wait_channel('START', 'STOP', type = 's') scan_completed = True get_exec_pars().currentScan.abort() ret = fork(monitoring_task) print "Scanning...", try: mscan(Ecrbk, sensors, -1, None, range="auto", domain_axis="Ecrbk", enabled_plots = ["NORMtey", "NORMdiode", CADC1,CADC3, CADC2], tag=TAG) finally: ret[0].cancel(True) print "Finished Energy scan." except: if not scan_completed: print sys.exc_info() print("Aborting...") while caget('START') == 'START': caput('START', '0') time.sleep(0.1) raise after_sample() #To call check_id_error()