Commit 33c81201 authored by Emmanuel Papillon's avatar Emmanuel Papillon
Browse files

added user_script_list in user_script

update txrd count preset
parent ec79f666
...@@ -38,7 +38,6 @@ class AirpadWagoPulseHook(MotionHook): ...@@ -38,7 +38,6 @@ class AirpadWagoPulseHook(MotionHook):
if phase == "premove": if phase == "premove":
self.__air_on = True self.__air_on = True
def pre_move(self, motion_list): def pre_move(self, motion_list):
if not self.__air_on: if not self.__air_on:
self.set("pre_move") self.set("pre_move")
...@@ -65,6 +64,6 @@ class AirpadWagoPulseHook(MotionHook): ...@@ -65,6 +64,6 @@ class AirpadWagoPulseHook(MotionHook):
start_time = time.time() start_time = time.time()
gevent.sleep(timeout * 60.0) gevent.sleep(timeout * 60.0)
while True: while True:
elapsed = int((time.time() - start_time)/60.0) elapsed = int((time.time() - start_time) / 60.0)
print(f"\n!!! WARNING : {self.name} is ON since {elapsed} min. !!!") print(f"\n!!! WARNING : {self.name} is ON since {elapsed} min. !!!")
gevent.sleep(60.0) gevent.sleep(60.0)
from bliss.config.settings import HashObjSetting from bliss.config.settings import HashObjSetting
#from bliss.common.shutter import BaseShutter, BaseShutterState
# from bliss.common.shutter import BaseShutter, BaseShutterState
from bliss import current_session from bliss import current_session
...@@ -78,12 +79,12 @@ class FastShutter: ...@@ -78,12 +79,12 @@ class FastShutter:
@property @property
def state(self): def state(self):
return self.__shutter_mux.getOutputStat("SHUTTER") return self.__shutter_mux.getOutputStat("SHUTTER")
@property @property
def mode(self): def mode(self):
return self.__shutter_mux.getOutputStat("SHUTTER") return self.__shutter_mux.getOutputStat("SHUTTER")
@mode.setter @mode.setter
def mode(self, value): def mode(self, value):
self.__check_session()
self.__shutter_mux.switch("SHUTTER", value.upper()) self.__shutter_mux.switch("SHUTTER", value.upper())
...@@ -3,7 +3,13 @@ from bliss.controllers.motors.icepap import Icepap ...@@ -3,7 +3,13 @@ from bliss.controllers.motors.icepap import Icepap
from bliss.common.cleanup import error_cleanup from bliss.common.cleanup import error_cleanup
from bliss.shell.standard import wm from bliss.shell.standard import wm
__all__ = ["mot_findref", "mot_showref", "mot_findrange", "mot_findhome", "mot_findlimit"] __all__ = [
"mot_findref",
"mot_showref",
"mot_findrange",
"mot_findhome",
"mot_findlimit",
]
def mot_findrange(axis, direction=+1): def mot_findrange(axis, direction=+1):
...@@ -15,7 +21,11 @@ def mot_findrange(axis, direction=+1): ...@@ -15,7 +21,11 @@ def mot_findrange(axis, direction=+1):
lim_dir = +1 lim_dir = +1
# --- first limit # --- first limit
print("Searching {0} hardware limit {1}".format(axis.name, lim_dir>0 and "positive" or "negative")) print(
"Searching {0} hardware limit {1}".format(
axis.name, lim_dir > 0 and "positive" or "negative"
)
)
mot_findlimit(axis, lim_dir) mot_findlimit(axis, lim_dir)
lim_dial1 = axis.limit_found_dial() lim_dial1 = axis.limit_found_dial()
lim_user1 = axis.dial2user(lim_dial1) lim_user1 = axis.dial2user(lim_dial1)
...@@ -24,7 +34,11 @@ def mot_findrange(axis, direction=+1): ...@@ -24,7 +34,11 @@ def mot_findrange(axis, direction=+1):
# --- second limit # --- second limit
lim_dir *= -1 lim_dir *= -1
print("Searching {0} hardware limit {1}".format(axis.name, lim_dir>0 and "positive" or "negative")) print(
"Searching {0} hardware limit {1}".format(
axis.name, lim_dir > 0 and "positive" or "negative"
)
)
mot_findlimit(axis, lim_dir) mot_findlimit(axis, lim_dir)
lim_dial2 = axis.limit_found_dial() lim_dial2 = axis.limit_found_dial()
lim_user2 = axis.dial2user(lim_dial2) lim_user2 = axis.dial2user(lim_dial2)
...@@ -36,7 +50,7 @@ def mot_findrange(axis, direction=+1): ...@@ -36,7 +50,7 @@ def mot_findrange(axis, direction=+1):
print(f"Motor travel range = {travel:g}") print(f"Motor travel range = {travel:g}")
print() print()
def mot_findref(axis): def mot_findref(axis):
if not isinstance(axis.controller, Icepap): if not isinstance(axis.controller, Icepap):
raise RuntimeError("findmotref only implemented for icepap motors") raise RuntimeError("findmotref only implemented for icepap motors")
...@@ -78,7 +92,10 @@ def mot_findref(axis): ...@@ -78,7 +92,10 @@ def mot_findref(axis):
# --- resets dial at reference # --- resets dial at reference
print() print()
ans = _yes_no("Do you want to set reference dial position to {0:g}".format(refcfg["dial"]), False) ans = _yes_no(
"Do you want to set reference dial position to {0:g}".format(refcfg["dial"]),
False,
)
if ans is True: if ans is True:
print("==> set dial position to {0:g}".format(refcfg["dial"])) print("==> set dial position to {0:g}".format(refcfg["dial"]))
axis.dial = refcfg["dial"] + offset axis.dial = refcfg["dial"] + offset
...@@ -97,9 +114,11 @@ def mot_findref(axis): ...@@ -97,9 +114,11 @@ def mot_findref(axis):
False, False,
) )
if ans is True: if ans is True:
print("==> set limits to ({0:g}, {1:g})".format( print(
refcfg["low_limit"], refcfg["high_limit"] "==> set limits to ({0:g}, {1:g})".format(
)) refcfg["low_limit"], refcfg["high_limit"]
)
)
low_user = axis.dial2user(refcfg["low_limit"]) low_user = axis.dial2user(refcfg["low_limit"])
high_user = axis.dial2user(refcfg["high_limit"]) high_user = axis.dial2user(refcfg["high_limit"])
axis.limits = (low_user, high_user) axis.limits = (low_user, high_user)
...@@ -137,22 +156,32 @@ def mot_showref(axis): ...@@ -137,22 +156,32 @@ def mot_showref(axis):
print("* user position at reference : {user}".format(**refcfg)) print("* user position at reference : {user}".format(**refcfg))
print() print()
def mot_findhome(axis, direction=1): def mot_findhome(axis, direction=1):
axis.home(direction, wait=False) axis.home(direction, wait=False)
mot_move_poll(axis) mot_move_poll(axis)
def mot_move_poll(axis): def mot_move_poll(axis):
with error_cleanup(axis.stop): with error_cleanup(axis.stop):
while axis.is_moving: while axis.is_moving:
print(f"\r{axis.name}: dial={axis.dial:g} user={axis.position:g}", end="", flush=True) print(
f"\r{axis.name}: dial={axis.dial:g} user={axis.position:g}",
end="",
flush=True,
)
sleep(0.1) sleep(0.1)
print(f"\r{axis.name}: dial={axis.dial:g} user={axis.position:g}", end="", flush=True) print(
f"\r{axis.name}: dial={axis.dial:g} user={axis.position:g}", end="", flush=True
)
print("") print("")
def mot_findlimit(axis, direction=1): def mot_findlimit(axis, direction=1):
axis.hw_limit(direction, wait=False) axis.hw_limit(direction, wait=False)
mot_move_poll(axis) mot_move_poll(axis)
def _yes_no(msg, flag): def _yes_no(msg, flag):
defans = flag is True and "YES" or "NO" defans = flag is True and "YES" or "NO"
ask = msg + f" [{defans}] ? " ask = msg + f" [{defans}] ? "
......
...@@ -2,16 +2,19 @@ from bliss.config.static import get_config ...@@ -2,16 +2,19 @@ from bliss.config.static import get_config
from bliss.common.scans import DEFAULT_CHAIN from bliss.common.scans import DEFAULT_CHAIN
from bliss.scanning.chain import ChainPreset from bliss.scanning.chain import ChainPreset
def set_frelon_trigger(): def set_frelon_trigger():
config = get_config() config = get_config()
chaincfg = config.get("chain_3dxrd_trig") chaincfg = config.get("chain_3dxrd_trig")
DEFAULT_CHAIN.set_settings(chaincfg["chain_config"]) DEFAULT_CHAIN.set_settings(chaincfg["chain_config"])
def set_frelon_gate(): def set_frelon_gate():
config = get_config() config = get_config()
chaincfg = config.get("chain_3dxrd_gate") chaincfg = config.get("chain_3dxrd_gate")
DEFAULT_CHAIN.set_settings(chaincfg["chain_config"]) DEFAULT_CHAIN.set_settings(chaincfg["chain_config"])
def set_frelon_soft(): def set_frelon_soft():
DEFAULT_CHAIN.set_settings({}) DEFAULT_CHAIN.set_settings({})
...@@ -23,17 +26,16 @@ class CountMuxPreset(ChainPreset): ...@@ -23,17 +26,16 @@ class CountMuxPreset(ChainPreset):
def prepare(self, chain): def prepare(self, chain):
# --- shutter # --- shutter
frelonnodes = [ node for node in chain.nodes_list if node.name.startswith("frelon") ] frelonnodes = [
frelon2shutter = { node for node in chain.nodes_list if node.name.startswith("frelon")
"frelon1": "CAM1", ]
"frelon2": "CAM2", frelon2shutter = {"frelon1": "CAM1", "frelon2": "CAM2", "frelon3": "CAM3"}
"frelon3": "CAM3",
}
shutter_mode = "COUNTER" shutter_mode = "COUNTER"
for node in frelonnodes: for node in frelonnodes:
dev = node.device dev = node.device
if dev.name in frelon2shutter: if dev.name in frelon2shutter:
shutter_mode = frelon2shutter[dev.name] shutter_mode = frelon2shutter[dev.name]
dev.shutter.mode = "AUTO_FRAME"
dev.shutter.close_time = self.fsh.shutter_time dev.shutter.close_time = self.fsh.shutter_time
break break
self.fsh.mode = shutter_mode self.fsh.mode = shutter_mode
......
import math import math
from bliss.setup_globals import * from bliss.setup_globals import *
def tfenergy(nal=None, nbe=None): def tfenergy(nal=None, nbe=None):
values = tfoh1.getlenses() values = tfoh1.getlenses()
if nal is None: if nal is None:
nal = values["Al"] nal = values["Al"]
if nbe is None: if nbe is None:
nbe = values["Be"] nbe = values["Be"]
neff = 1.5682766 * nal + nbe neff = 1.5682766 * nal + nbe
print("Energy for EH3 (96 m) : {0:.3f} keV".format(math.sqrt(neff/0.013981957))) print("Energy for EH3 (96 m) : {0:.3f} keV".format(math.sqrt(neff / 0.013981957)))
print("Energy for EH1 (46 m) : {0:.3f} keV".format(math.sqrt(neff/0.037651802))) print("Energy for EH1 (46 m) : {0:.3f} keV".format(math.sqrt(neff / 0.037651802)))
def tfguess(energy, hutch="EH3"): def tfguess(energy, hutch="EH3"):
if hutch.upper() not in ["EH1", "EH3"]: if hutch.upper() not in ["EH1", "EH3"]:
...@@ -44,4 +46,3 @@ def tfguess(energy, hutch="EH3"): ...@@ -44,4 +46,3 @@ def tfguess(energy, hutch="EH3"):
print("{0:d} Al + {1:d} Be".format(nal, int(nbe))) print("{0:d} Al + {1:d} Be".format(nal, int(nbe)))
elif energy > 125: elif energy > 125:
print("Sorry, only focuses up to 125 keV !!") print("Sorry, only focuses up to 125 keV !!")
import importlib import importlib
import os.path import os
import sys import sys
from bliss import current_session from bliss import current_session
...@@ -10,7 +10,12 @@ USER_SCRIPT_HOME = SimpleSetting( ...@@ -10,7 +10,12 @@ USER_SCRIPT_HOME = SimpleSetting(
default_value="%s/bliss_scripts" % os.getenv("HOME"), default_value="%s/bliss_scripts" % os.getenv("HOME"),
) )
__all__ = ["user_script_directory", "user_script_run", "user_script_load"] __all__ = [
"user_script_directory",
"user_script_run",
"user_script_load",
"user_script_list",
]
def user_script_directory(new_dir=None): def user_script_directory(new_dir=None):
...@@ -22,12 +27,26 @@ def user_script_directory(new_dir=None): ...@@ -22,12 +27,26 @@ def user_script_directory(new_dir=None):
return USER_SCRIPT_HOME.get() return USER_SCRIPT_HOME.get()
def user_script_list():
rootdir = USER_SCRIPT_HOME.get()
print(f"Scripts found in [{rootdir}]:")
for (dirpath, dirnames, filenames) in os.walk(rootdir):
dirname = dirpath.replace(rootdir, "")
dirname = dirname.lstrip("/")
if len(dirname):
dirname += "/"
for filename in filenames:
print(f" - {dirname}{filename}")
def user_script_load(scriptname): def user_script_load(scriptname):
_user_script_exec(scriptname, export=True) _user_script_exec(scriptname, export=True)
def user_script_run(scriptname): def user_script_run(scriptname):
_user_script_exec(scriptname, export=False) _user_script_exec(scriptname, export=False)
def _user_script_exec(scriptname, export=False): def _user_script_exec(scriptname, export=False):
script_dir = os.path.abspath(USER_SCRIPT_HOME.get()) script_dir = os.path.abspath(USER_SCRIPT_HOME.get())
(filename, fileext) = os.path.splitext(scriptname) (filename, fileext) = os.path.splitext(scriptname)
......
from bliss.config.static import get_config from bliss.config.static import get_config
def desc(*objs): def desc(*objs):
for obj in objs: for obj in objs:
try: try:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment