diff --git a/config/devices.properties b/config/devices.properties index 5bc738e..7b3a341 100644 --- a/config/devices.properties +++ b/config/devices.properties @@ -1,3 +1,9 @@ +pol_mode=ch.psi.pshell.epics.DiscretePositioner|X11MA-ID2:MODE|||true +pol_angle=ch.psi.pshell.epics.ChannelDouble|X11MA-ID2:ALPHA|||true +pol_offset=ch.psi.pshell.epics.ChannelDouble|X11MA-ID2:ENERGY-OFFS|||true +pol_done=ch.psi.pshell.epics.ChannelString|X11MA-ID2:DONE|Read||true +energy=ch.psi.pshell.epics.ChannelDouble|X11MA-PHS:E_SP||| +id_error=ch.psi.pshell.epics.ChannelInteger|X11MA-ID2-PLC:ERROR|||true beam_status=ch.psi.pshell.epics.DiscretePositioner|ACOAU-ACCU:OP-MODE|Read||true edata=ch.psi.pshell.epics.ChannelDoubleArray|EDATA 3|Read|| count=ch.psi.pshell.epics.ChannelInteger|COUNT|Read||true @@ -29,7 +35,7 @@ MCPArray1=ch.psi.pshell.epics.ChannelIntegerArray|X11MA-ES4:PHC-CTRWF1|Read||tru SamplingTime=ch.psi.pshell.epics.ChannelDouble|X11MA-ES4:SAMPLE-TIME|Read||true MCPArray2=ch.psi.pshell.epics.ChannelIntegerArray|X11MA-ES4:PHC-CTRWF2|Read||true NrCounters=ch.psi.pshell.epics.ChannelInteger|X11MA-ES4:NCTR|Read||true -energy=ch.psi.pshell.epics.ChannelDouble|X11MA-PGM:rbkenergy|Read||true +energy_rbk=ch.psi.pshell.epics.ChannelDouble|X11MA-PGM:rbkenergy|Read||true energy_done=ch.psi.pshell.epics.ChannelDouble|X11MA-PHS:ALL-DONE|Read||true keithley_1a=ch.psi.pshell.epics.ChannelDouble|X11MA-ES1:CADC1|Read||true keithley_2a=ch.psi.pshell.epics.ChannelDouble|X11MA-ES1:CADC2|Read||true diff --git a/script/local.py b/script/local.py index c087567..8e0cf52 100644 --- a/script/local.py +++ b/script/local.py @@ -122,4 +122,21 @@ def wait_beam(): sleep(0.1) print "Beam OK." +def is_id_error(): + return (id_error.read()==0) + +def check_id_error(): + if is_id_error(): + raise Exception ("ID error: check ID status") + +################################################################################################### +#Default scan callbacks +################################################################################################### + +def before_sample(): + pass + +def after_sample(): + check_id_error() + diff --git a/script/local.py~ b/script/local.py~ index 56bb292..c087567 100644 --- a/script/local.py~ +++ b/script/local.py~ @@ -1,7 +1,8 @@ ################################################################################################### # Deployment specific global definitions - executed after startup.py ################################################################################################### - + +NO_BEAM_CHECK = False # setting this to true disables the waiting for the beam before starting energy or hyst scan OTF_START = "X11MA-OTF:GO" OTF_E1 = "X11MA-OTF:E1" diff --git a/script/templates/EnergyScan.py b/script/templates/EnergyScan.py index 6bb11ca..943067b 100644 --- a/script/templates/EnergyScan.py +++ b/script/templates/EnergyScan.py @@ -68,8 +68,6 @@ def getNewestFile(): global folder import glob try: -# print glob.glob(folder+'/*.txt') -# print max(glob.glob(folder+'/*.txt'), key=os.path.getctime) return max(glob.glob(folder+'/*.txt'), key=os.path.getctime) except: return None @@ -83,81 +81,40 @@ if NO_BEAM_CHECK == False: if MODE is not None: - pol_mode.write(MODE) #caput('X07MA-ID:MODE', MODE) #TODO: CAPUT -# time.sleep(0.5) #TODO: Needed? + pol_mode.write(MODE) if MODE == 'LINEAR': if ALPHA is not None: - pol_angle.write(ALPHA) #TODO: CAPUT -# time.sleep(0.5) - #wait_device(pol_done, "DONE") #TODO: NEEDED? + pol_angle.write(ALPHA) + if OFFSET is not None: - pol_offset.write(OFFSET) #TODO: CAPUT -# time.sleep(0.5) - #wait_device(pol_done, "DONE") + pol_offset.write(OFFSET) -wait_device(pol_done, "DONE") # added 10/02/2017 to try avoid taper error. CP +wait_device(pol_done, "DONE") ################# -""" -print "Moving down energy in steps." +energy.write(float(E1)) +wait_channel(ALL_DONE, 1, type = 'i') -while True: - en = caget("X07MA-PGM:CERBK") - if en > 350.0: - estep = 20.0 - else: - estep = 5.0 - - if abs(en - E1) < estep: - estep = abs(en - E1) - - if en > float(E1): - set_energy( en - estep ) - else: - break - -print "It is done." -############ -""" -energy.write(float(E1)) # added 10/02/2017 to try avoid taper error. CP - -#wait_device(energy_done, 1) # added 10/02/2017 to try avoid taper error. CP. Removed in 17/03 because often script was hanging at this point caput('E1', E1) -#print "caput E1" #add for debug caput('E2', E2) -#print "caput E2" #add for debug caput('TIME', TIME) -#print "caput TIME" #add for debug caput('FOLDER', FOLDER) -#print "caput FOLDER" #add for debug -#set_energy (E1) caput('FILE', FILE) -#print "caput FILE" #add for debug time.sleep(0.1) -#open_valve() -#open_valve(0.0) #TODO: WHY WRITING AGAIN??? -#print "before delay" #add for debug time.sleep(DELAY) -#print "after delay" #add for debug - -#print 'ldfkj;fjk' -#if WAIT_STABLE_TEMPERATURE == True: -# wait_temp() caput('START', '1') -#print "caput START" #add for debug try: - write_logs() + #write_logs() waiting = True def plot_task(): global waiting pos=count.take() start_plot() - #print "start_plot" # added for debug while waiting: if count.take() != pos: update_plot() @@ -175,19 +132,13 @@ try: finally: waiting = False join(ret) - #print "Joined " - #File convertion - #newName = folder + time.strftime("%Y%m%d_%H%M%S_", start) + FILE + "_0000.txt"; + + #File convertion newName = folder + time.strftime("%Y%m%d_%H%M_", start) + FILE + "_0000.txt"; name = getNewestFile() - #print "newest file:" - #print name - #print "newest variable" - #print newest - - if name == newest:#TODO: WHY WRITING AGAIN??? + if name == newest: print "Risk of overwriting. " + name + " same as " + newest raise Exception("Data file not created.") @@ -195,16 +146,14 @@ try: raise Exception("Data file not found: " + name) convert_file(name, newName) - log("Created data file: " + newName) + #log("Created data file: " + newName) #plot_file(newName) - #print("Success") - #"PlotDomain", "Ecrbk" + print("Success") + except: 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