97 lines
2.9 KiB
Python
97 lines
2.9 KiB
Python
#Debugging
|
|
if get_exec_pars().args is None:
|
|
E1 = 974
|
|
E2 = 978
|
|
TIME = 1 #min
|
|
DELAY = 0.0 #s
|
|
MODE = None #'LINEAR' #'CIRC +'
|
|
OFFSET = None
|
|
NAME = 'Test'
|
|
ALPHA= None #0
|
|
|
|
print "\nStart energy scan..."
|
|
print E1,"eV ->",E2,"eV,",TIME,"min duration,",DELAY,"sec delay,",str(MODE),(str(ALPHA)+"deg") if (MODE=="LINEAR") else ""
|
|
|
|
|
|
set_exec_pars(reset=True, name= NAME)
|
|
|
|
#Pre-actions
|
|
wait_beam()
|
|
wait_id_ok()
|
|
|
|
set_pol(MODE, ALPHA, OFFSET)
|
|
set_energy_ma(float(E1))
|
|
caput(energy_ma_rbv.channelName+".N", 10) # set energy readback averaging to 10 pts
|
|
|
|
print "Setup OTF"
|
|
caput('E1', E1)
|
|
caput('E2', E2)
|
|
caput('TIME', TIME)
|
|
caput('FOLDER', "OTF/" + get_context().setup.expandPath("OTF/{year}_{month}/{date}"))
|
|
caput('FILE', NAME)
|
|
|
|
time.sleep(max(DELAY, 0.1))
|
|
|
|
#Scan
|
|
print "Start OTF"
|
|
scan_completed = False
|
|
try:
|
|
while True:
|
|
caput('START', '1')
|
|
waiting = True
|
|
|
|
class Time(Readable):
|
|
def __init__(self):
|
|
self.start = time.time()
|
|
def read(self):
|
|
return time.time()-self.start
|
|
tm = Time()
|
|
|
|
class norm_tey(Readable):
|
|
def read(self):
|
|
return float(cadc1.take())/float(cadc2.take())
|
|
|
|
class norm_diode(Readable):
|
|
def read(self):
|
|
return float(cadc3.take())/float(cadc2.take())
|
|
|
|
snaps = (pol_mode, pol_angle,pol_offset)
|
|
diags = (current.cache) #Must use cache because mscan evensts are called from monitor callback tread (or else async=False). Sensors are automatically handled.
|
|
sensors = [energy_ma_rbv, cadc1, cadc2, cadc3, cadc4, cadc5, norm_tey(), norm_diode(), tm]
|
|
|
|
tm.setAlias("time")
|
|
cadc1.setAlias("tey_raw")
|
|
cadc2.setAlias("i0")
|
|
cadc3.setAlias("diode_raw")
|
|
|
|
def monitoring_task():
|
|
global scan_completed
|
|
time.sleep(1.0)
|
|
wait_channel('START', 'STOP', type = 's')
|
|
scan_completed = True
|
|
get_exec_pars().currentScan.abort()
|
|
|
|
monitoring_future = fork(monitoring_task)[0]
|
|
|
|
print "Scanning...",
|
|
try:
|
|
mscan( energy_ma_rbv, sensors, -1, None, \
|
|
range="auto",domain_axis=energy_ma_rbv.name, \
|
|
enabled_plots=["norm_tey", "norm_diode", cadc1, cadc3, cadc2], \
|
|
snaps=snaps, diags=diags)
|
|
finally:
|
|
monitoring_future.cancel(True)
|
|
|
|
print "Finished Energy scan."
|
|
if after_sample(): #Repeat if id error and not ABORT_ON_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)
|
|
raise
|