141 lines
3.9 KiB
Python
141 lines
3.9 KiB
Python
###################################################################################################
|
|
# Deployment specific global definitions - executed after startup.py
|
|
###################################################################################################
|
|
|
|
import ch.psi.fda.ProcessorFDA as ProcessorFDA
|
|
import ntpath
|
|
|
|
NO_BEAM_CHECK = False
|
|
ABORT_ON_ID_ERROR = False
|
|
|
|
|
|
#Layout
|
|
get_context().dataManager.provider.embeddedAtributes=False
|
|
|
|
|
|
#Device initialization
|
|
energy_ma.setBlockingWrite(True)
|
|
pol_mode.setpoint.setBlockingWrite(True)
|
|
pol_offset.setBlockingWrite(True)
|
|
pol_angle.setBlockingWrite(True)
|
|
|
|
|
|
#Utilities
|
|
def run_fda(file_name, arguments={}):
|
|
"""
|
|
Run FDA loop
|
|
"""
|
|
ProcessorFDA().execute(file_name,arguments)
|
|
|
|
|
|
def otf(start, end, time, delay=0.0, mode = None, offset = None, alpha = None, name = None):
|
|
"""
|
|
"""
|
|
if name is None:
|
|
name = get_exec_pars().name
|
|
|
|
if len(name)> 38:
|
|
name = name[:38]
|
|
print('WARNING: Sample name too long. Name has been truncated.')
|
|
|
|
run("EnergyScan_ma", {"E1":start, "E2":end, "TIME":time, "DELAY":float(delay), "MODE":mode, "OFFSET":(offset), "NAME":name, "ALPHA":float(alpha) if alpha is not None else None})
|
|
|
|
|
|
|
|
|
|
def has_beam():
|
|
"""
|
|
"""
|
|
return beam_status.readback.read() !="Machine Down"
|
|
|
|
def wait_beam():
|
|
"""
|
|
"""
|
|
if not has_beam():
|
|
print "Waiting for beam... "
|
|
if NO_BEAM_CHECK:
|
|
print "Maintenence mode: disregarding beam state"
|
|
return
|
|
while not has_beam():
|
|
sleep(0.1)
|
|
print "Beam OK."
|
|
|
|
def wait_pol_done(delay=1.0):
|
|
"""
|
|
"""
|
|
print "Waiting for pol done"
|
|
time.sleep(delay) #Make sure value changed
|
|
while True:
|
|
try:
|
|
if caget("X07MA-ID:DONE") == "DONE":
|
|
break
|
|
except:
|
|
print "Error reading pol done"
|
|
time.sleep(0.5)
|
|
print "Done"
|
|
|
|
def wait_channel(name, value, timeout=None, type='s'):
|
|
print "Waiting " + str(name) + " = " + str(value),"... "
|
|
cawait(name, value, timeout = timeout, type=type)
|
|
|
|
def is_id_error():
|
|
return (id_error.read()==0)
|
|
|
|
def check_id_error():
|
|
if is_id_error():
|
|
raise Exception ("ID error: check ID status")
|
|
|
|
def wait_id_ok():
|
|
"""
|
|
"""
|
|
if is_id_error():
|
|
print "ID error: waiting..."
|
|
while True:
|
|
time.sleep(1.0) #Make sure value changed
|
|
try:
|
|
if not is_id_error():
|
|
break
|
|
except:
|
|
print "Error reading id error"
|
|
print "Done"
|
|
|
|
def set_pol(mode=None, alpha=None, offset=None):
|
|
if mode is not None:
|
|
print "Set pol mode: ", mode
|
|
pol_mode.write(mode)
|
|
if MODE == 'LINEAR':
|
|
if alpha is not None:
|
|
print "Set pol alpha: ", alpha
|
|
pol_angle.write(alpha)
|
|
wait_pol_done(1.0)
|
|
|
|
if offset is not None:
|
|
print "Set pol offset: ", offset
|
|
pol_offset.write(offset)
|
|
|
|
def set_energy_ma(value):
|
|
print "Setting energy ma to: ", value
|
|
energy_ma.write(float(E1)) # no need to add wait command. This commands sets and waits.
|
|
print "Done"
|
|
|
|
###################################################################################################
|
|
#Default scan callbacks
|
|
###################################################################################################
|
|
|
|
def before_sample(position, scan):
|
|
pass
|
|
|
|
def after_sample(record=None, scan=None):
|
|
if ABORT_ON_ID_ERROR:
|
|
check_id_error()
|
|
return True
|
|
if is_id_error():
|
|
if (record is not None):
|
|
record.invalidate()
|
|
print "ID error, waiting..."
|
|
while is_id_error():
|
|
time.sleep(1.0)
|
|
print "ID OK"
|
|
return False
|
|
return True
|