Startup
This commit is contained in:
+69
-38
@@ -3,22 +3,26 @@
|
||||
###################################################################################################
|
||||
import os
|
||||
import os.path
|
||||
from shutil import copyfile
|
||||
import json
|
||||
|
||||
|
||||
###################################################################################################
|
||||
# Interlocks
|
||||
###################################################################################################
|
||||
|
||||
class MyInterlock1 (Interlock):
|
||||
def __init__(self):
|
||||
Interlock.__init__(self, (alpha, gamma))
|
||||
class InterlockFourcv (Interlock):
|
||||
def __init__(self):
|
||||
Interlock.__init__(self, (fourcv, alpha, delta, gamma, omegaV))
|
||||
|
||||
def check(self, (a, g)):
|
||||
if a>=g:
|
||||
def check(self, (p, a, d, g, o)):
|
||||
if fourcv.isStartingSimultaneousMove():
|
||||
a, d, g, o = p
|
||||
if a>g:
|
||||
return False
|
||||
return True
|
||||
|
||||
#interlock1 = MyInterlock1()
|
||||
|
||||
#interlock1 = InterlockFourcv()
|
||||
|
||||
###################################################################################################
|
||||
# Hardware
|
||||
@@ -99,37 +103,6 @@ def set_count_time(value):
|
||||
"""
|
||||
set_setting(COUNT_TIME_PREFERENCE, value )
|
||||
|
||||
|
||||
|
||||
def get_geometry():
|
||||
"""
|
||||
"""
|
||||
setting = get_setting(GEOMETRY_PREFERENCE)
|
||||
if setting is None or (len(setting.strip()) == 0):
|
||||
return None
|
||||
return setting
|
||||
|
||||
def set_geometry(value, apply = None):
|
||||
"""
|
||||
"""
|
||||
if value is None or (len(value.strip()) == 0):
|
||||
set_setting(GEOMETRY_PREFERENCE, "" )
|
||||
for name in "wavelength", "hkl_group", "h", "k", "l":
|
||||
dev = get_device(name)
|
||||
if dev is not None:
|
||||
remove_device(dev)
|
||||
return
|
||||
filename = get_context().setup.expandPath("{script}/geometry/"+ str(value)+".py")
|
||||
if not os.path.isfile(filename):
|
||||
raise Exception("Invalid geometry file: " + value)
|
||||
former = get_geometry()
|
||||
if ((apply is None) and former != value) or (apply==True) :
|
||||
set_setting(GEOMETRY_PREFERENCE, value )
|
||||
run(filename)
|
||||
|
||||
def is_geometry_set():
|
||||
return get_device("wavelength") is not None
|
||||
|
||||
def get_roi():
|
||||
"""
|
||||
"""
|
||||
@@ -162,6 +135,41 @@ def set_bg_roi(x1, y1, x2, y2):
|
||||
set_setting(BG_ROI_PREFERENCE, str(int(x1)) + " " + str(int(y1)) + " " + str(int(x2)) + " " + str(int(y2)) )
|
||||
|
||||
|
||||
###################################################################################################
|
||||
# Context
|
||||
###################################################################################################
|
||||
|
||||
|
||||
def get_geometry():
|
||||
"""
|
||||
"""
|
||||
setting = get_setting(GEOMETRY_PREFERENCE)
|
||||
if setting is None or (len(setting.strip()) == 0):
|
||||
return None
|
||||
return setting
|
||||
|
||||
def set_geometry(value, apply = None):
|
||||
"""
|
||||
"""
|
||||
if value is None or (len(value.strip()) == 0):
|
||||
set_setting(GEOMETRY_PREFERENCE, "" )
|
||||
for name in "wavelength", "hkl_group", "h", "k", "l":
|
||||
dev = get_device(name)
|
||||
if dev is not None:
|
||||
remove_device(dev)
|
||||
return
|
||||
filename = get_context().setup.expandPath("{script}/geometry/"+ str(value)+".py")
|
||||
if not os.path.isfile(filename):
|
||||
raise Exception("Invalid geometry file: " + value)
|
||||
former = get_geometry()
|
||||
if ((apply is None) and former != value) or (apply==True) :
|
||||
set_setting(GEOMETRY_PREFERENCE, value )
|
||||
run(filename)
|
||||
|
||||
def is_geometry_set():
|
||||
return get_device("wavelength") is not None
|
||||
|
||||
|
||||
###################################################################################################
|
||||
# Scan callbacks
|
||||
###################################################################################################
|
||||
@@ -377,12 +385,34 @@ def wait_for_file_size(filepath, size, timeout = None):
|
||||
|
||||
|
||||
def set_data_path(path):
|
||||
"""Changes data root path.
|
||||
"""
|
||||
get_context().setDataPath(path)
|
||||
|
||||
|
||||
def set_script_path(path):
|
||||
"""Changes script root path.
|
||||
"""
|
||||
get_context().setScriptPath(path)
|
||||
|
||||
def backup_ub(name=None, destination = "{data}"):
|
||||
"""Copies ub matrix (default= current) to user space.
|
||||
"""
|
||||
if not name:
|
||||
name = ub.ubcalc._state.name
|
||||
name = name + ".json"
|
||||
f = settings.persistence_path + "/" + name
|
||||
if not os.path.isfile(f):
|
||||
raise Exception("Invalid UB name: " + str(name))
|
||||
copyfile(f, get_context().setup.expandPath(destination + "/" +name))
|
||||
|
||||
def restore_ub(name, origin = "{data}"):
|
||||
"""Restores ub matrix from user space and loads it.
|
||||
"""
|
||||
f = settings.persistence_path + "/" + name + ".json"
|
||||
copyfile(get_context().setup.expandPath(origin + "/" +name + ".json"), f)
|
||||
loadub(name)
|
||||
|
||||
###################################################################################################
|
||||
# HKL commands
|
||||
###################################################################################################
|
||||
@@ -496,6 +526,7 @@ def hkllinscan(hstart, hfinish, kstart, kfinish, lstart, lfinish, number_of_step
|
||||
###################################################################################################
|
||||
|
||||
set_geometry(get_geometry(),True)
|
||||
load_exp_context()
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user