''' #Parameters E1 = 630 E2 = 685 TIME = 1 #min DELAY = 0.0 #s MODE = 'LINEAR' #'CIRC +' OFFSET = None FOLDER = '2021_03/20210330' FILE = 'Test' ALPHA=0 #None ''' set_exec_pars (reset=True) print "wait 0.5 seconds..." time.sleep(0.5) # delay to avoid immediate commands to ID after completion of last scan #print "\nCheck temperature" #wait_temp() #print "\nTemperature ok" 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 + "/"; 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) wait_pol_done(1.0) # new script to wait for polarization. Wait_device does not work for this channel print "Set Energy" if OFFSET is not None: pol_offset.write(OFFSET) #TODO: CAPUT #time.sleep(0.5) #wait_device(pol_done, "DONE") energy.write(float(E1)) # no need to add wait command. This commands sets and waits. print "Energy setting done" caput('X07MA-PGM:CERBK.N',10) # set energy readback averaging to 10 pts caput('E1', E1) caput('E2', E2) caput('TIME', TIME) #caput('FOLDER', FOLDER) caput('FOLDER', "OTF/" + FOLDER) caput('FILE', FILE) time.sleep(0.1) #open_valve() #open_valve(0.0) #TODO: WHY WRITING AGAIN??? time.sleep(DELAY) #if WAIT_STABLE_TEMPERATURE == True: # wait_temp() topup_thresh=402.0 print('wait for topup') while(caget('ARIDI-PCT:CURRENT') < topup_thresh): sleep(0.3) pass; print('topup done') scan_completed = False try: while True: # if ABORT_ON_ID_ERROR == False, waits reading with no ID error caput('START', '1') write_logs() waiting = True 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(CADC1.take())/float(CADC2.take()) class NORMdiode(Readable): def read(self): return float(CADC3.take())/float(CADC2.take()) pol = pol_angle if (pol_mode.readback.read() == "LINEAR") else pol_mode #Fixed, should be an attribute, not a column sensors = [Ecrbk, CADC1, CADC2, CADC3,CADC4,CADC5,current,Time(),FieldX,FieldZ,pol, Temperature, NORMtey(), NORMdiode()] def monitoring_task(): global scan_completed time.sleep(1.0) try: plot_titles = ["TEY raw", "I0", "diode_raw", "TEY_norm", "diode_norm"] 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) current.alias="MCurr" pol.alias="Pol" print "Scanning...", try: mscan(Ecrbk, sensors, -1, None, range="auto", domain_axis="Ecrbk", enabled_plots = ["NORMtey", "NORMdiode", CADC1,CADC3, CADC2], ) finally: ret[0].cancel(True) current.alias=None pol.alias=None #time.sleep(2.0) print "Finished Energy scan." if after_sample(): #Repeat if id error break except: if not scan_completed: print sys.exc_info() print("Aborting...") while caget('START') == 'START': caput('START', '0') time.sleep(0.1) #if get_exec_pars().source != CommandSource.plugin: # show_message(str(ex)) raise