diff --git a/eco/acquisition/daq_client.py b/eco/acquisition/daq_client.py index f16c486..e3fa915 100644 --- a/eco/acquisition/daq_client.py +++ b/eco/acquisition/daq_client.py @@ -41,10 +41,11 @@ class Daq: self.name = name self._default_file_path = None - def acquire(self, file_name=None, Npulses=100, acq_pars = {}): + def acquire(self, file_name=None, Npulses=100, acq_pars={}): print(file_name, Npulses) acquisition = Acquisition( - acquire=None, acquisition_kwargs={"Npulses": Npulses}, + acquire=None, + acquisition_kwargs={"Npulses": Npulses}, ) def acquire(): @@ -68,7 +69,7 @@ class Daq: def acquire_pulses(self, Npulses, label=None, wait=True, **kwargs): ix = self.start(label=label, **kwargs) return self.stop( - stop_id=self.running[ix]["start_id"] + Npulses -1, acq_ix=ix, wait=wait + stop_id=self.running[ix]["start_id"] + Npulses - 1, acq_ix=ix, wait=wait ) def start(self, label=None, **kwargs): @@ -117,6 +118,7 @@ class Daq: filename_format="run_{:06d}", **kwargs, ): + print("This is tha additional input:", kwargs) if not pgroup: pgroup = self.pgroup if not pgroup: diff --git a/eco/bernina/config.py b/eco/bernina/config.py index 78906b8..492cbd1 100755 --- a/eco/bernina/config.py +++ b/eco/bernina/config.py @@ -360,13 +360,13 @@ components = [ "kwargs": {}, }, # { - # "name": "spatial_tt", - # "args": [], - # "kwargs": {"reduction_client_address": "http://sf-daqsync-02:12003/"}, - # "z_und": 141, - # "desc": "spatial encoding timing diagnostics before sample.", - # "type": "eco.xdiagnostics.timetools:SpatialEncoder", - # "lazy": True, + # "name": "spatial_tt", + # "args": [], + # "kwargs": {"reduction_client_address": "http://sf-daqsync-02:12003/"}, + # "z_und": 141, + # "desc": "spatial encoding timing diagnostics before sample.", + # "type": "eco.xdiagnostics.timetools:SpatialEncoder", + # "lazy": True, # }, # { # "name": "slit_kb", @@ -384,20 +384,33 @@ components = [ "desc": "General purpose station", "type": "eco.endstations.bernina_diffractometers:GPS", "kwargs": { - "Id": "SARES22-GPS", + "pvname": "SARES22-GPS", "configuration": config["gps_config"], "fina_hex_angle_offset": "~/eco/reference_values/hex_pi_angle_offset.json", }, "lazy": True, }, - { - "args": [], - "name": "xrd_old", - "z_und": 142, - "desc": "Xray diffractometer", - "type": "eco.endstations.bernina_diffractometers:XRD_old", - "kwargs": {"Id": "SARES21-XRD", "configuration": config["xrd_config"]}, - }, + # { + # "args": [], + # "name": "gps_old", + # "z_und": 142, + # "desc": "General purpose station", + # "type": "eco.endstations.bernina_diffractometers:GPS_old", + # "kwargs": { + # "Id": "SARES22-GPS", + # "configuration": config["gps_config"], + # "fina_hex_angle_offset": "~/eco/reference_values/hex_pi_angle_offset.json", + # }, + # "lazy": True, + # }, + # { + # "args": [], + # "name": "xrd_old", + # "z_und": 142, + # "desc": "Xray diffractometer", + # "type": "eco.endstations.bernina_diffractometers:XRD_old", + # "kwargs": {"Id": "SARES21-XRD", "configuration": config["xrd_config"]}, + # }, { "args": [], "name": "xrd", @@ -801,11 +814,11 @@ components = [ }, { "args": [], - "name": "bsen", - "z_und": 142, - "desc": "bsen targets", + "name": "tt_usd", + "z_und": 141, + "desc": "timetool in upstream diagnostics", "type": "eco.xdiagnostics.bsen_usd:Bsen", - "kwargs": {"Id": "SARES23"}, + "kwargs": {}, }, { "args": [], diff --git a/eco/devices_general/adjustable.py b/eco/devices_general/adjustable.py index c045189..bd9c08c 100644 --- a/eco/devices_general/adjustable.py +++ b/eco/devices_general/adjustable.py @@ -269,6 +269,7 @@ class AdjustableFS: if not self.file_path.parent.exists(): self.file_path.parent.mkdir() self._write_value(default_value) + self.alias = Alias(name) self.name = name def get_current_value(self): diff --git a/eco/devices_general/motors.py b/eco/devices_general/motors.py index 37c1a05..7aa67fa 100755 --- a/eco/devices_general/motors.py +++ b/eco/devices_general/motors.py @@ -462,11 +462,11 @@ class MotorRecord(Assembly): """ Adjustable convention""" cmd = ["caqtdm", "-macro"] - cmd.append('"P=%s:,M=%s"' % tuple(self.Id.split(":"))) + cmd.append('"P=%s:,M=%s"' % tuple(self.pvname.split(":"))) # cmd.append('/sf/common/config/qt/motorx_more.ui') cmd.append("motorx_more.ui") # os.system(' '.join(cmd)) - return subprocess.Popen(" ".join(cmd), shell=True) + return subprocess.Popen(" ".join(cmd), shell=True, stdout=subprocess.DEVNULL) # return string with motor value as variable representation def __str__(self): diff --git a/eco/endstations/bernina_diffractometers.py b/eco/endstations/bernina_diffractometers.py index f7915b7..0b9f461 100644 --- a/eco/endstations/bernina_diffractometers.py +++ b/eco/endstations/bernina_diffractometers.py @@ -21,7 +21,95 @@ def addMotorRecordToSelf(self, name=None, Id=None): print(f"Warning! Could not find motor {name} (Id:{Id})") -class GPS: +class GPS(Assembly): + def __init__( + self, + name=None, + pvname=None, + configuration=["base"], + alias_namespace=None, + fina_hex_angle_offset=None, + ): + super().__init__() + self.pvname = pvname + self.name = name + self.configuration = configuration + + if "base" in self.configuration: + ### motors base platform ### + self._append(MotorRecord, pvname + ":MOT_TX", name="xbase", is_setting=True) + self._append(MotorRecord, pvname + ":MOT_TY", name="ybase", is_setting=True) + self._append( + MotorRecord, pvname + ":MOT_RX", name="rxbase", is_setting=True + ) + self._append( + MotorRecord, pvname + ":MOT_MY_RYTH", name="alpha", is_setting=True + ) + + ### motors XRD detector arm ### + self._append( + MotorRecord, pvname + ":MOT_NY_RY2TH", name="gamma", is_setting=True + ) + + if "phi_table" in self.configuration: + ### motors phi table ### + self._append( + MotorRecord, pvname + ":MOT_HEX_RX", name="phi", is_setting=True + ) + self._append( + MotorRecord, pvname + ":MOT_HEX_TX", name="tphi", is_setting=True + ) + + if "phi_hex" in self.configuration: + + ### motors PI hexapod ### + if fina_hex_angle_offset: + fina_hex_angle_offset = Path(fina_hex_angle_offset).expanduser() + + self._append( + HexapodPI, + "SARES20-HEX_PI", + name="hex", + fina_angle_offset=fina_hex_angle_offset, + is_setting=False, + ) + + if "hlxz" in self.configuration: + ### motors heavy load goniometer ### + self._append( + MotorRecord, pvname + ":MOT_TBL_TX", name="xhl", is_setting=True + ) + self._append( + MotorRecord, pvname + ":MOT_TBL_TZ", name="zhl", is_setting=True + ) + + if "hly" in self.configuration: + self._append( + MotorRecord, pvname + ":MOT_TBL_TY", name="yhl", is_setting=True + ) + + if "hlrxrz" in self.configuration: + self._append( + MotorRecord, pvname + ":MOT_TBL_RX", name="rxhl", is_setting=True + ) + self._append( + MotorRecord, pvname + ":MOT_TBL_RZ", name="rzhl", is_setting=True + ) + + # def get_adjustable_positions_str(self): + # ostr = "*****GPS motor positions******\n" + + # for tkey, item in self.__dict__.items(): + # if hasattr(item, "get_current_value"): + # pos = item.get_current_value() + # ostr += " " + tkey.ljust(17) + " : % 14g\n" % pos + # return ostr + + # def __repr__(self): + # return self.get_adjustable_positions_str() + + +class GPS_old: def __init__( self, name=None, diff --git a/eco/endstations/bernina_sample_environments.py b/eco/endstations/bernina_sample_environments.py index a023285..f4d4f42 100644 --- a/eco/endstations/bernina_sample_environments.py +++ b/eco/endstations/bernina_sample_environments.py @@ -392,16 +392,16 @@ class Electro_optic_sampling: "home_direction": "back", }, "rx": { - "id": "-LIC11", - "pv_descr": "Motor6:2 EOS prism rx ", + "id": "-ESB5", + "pv_descr": "Motor4:1 EOS prism rx ", "type": 1, "sensor": 0, "speed": 250, "home_direction": "back", }, "x": { - "id": "-LIC10", - "pv_descr": "Motor6:1 EOS prism x ", + "id": "-ESB4", + "pv_descr": "Motor4:2 EOS prism x ", "type": 1, "sensor": 0, "speed": 250, diff --git a/eco/endstations/hexapod.py b/eco/endstations/hexapod.py index c4937de..72e6372 100644 --- a/eco/endstations/hexapod.py +++ b/eco/endstations/hexapod.py @@ -9,6 +9,7 @@ from time import sleep from ..aliases import append_object_to_object, Alias from scipy.spatial.transform import Rotation import datetime +from ..elements.assembly import Assembly class Hexapod_PI: @@ -28,7 +29,180 @@ class Hexapod_PI: ] -class HexapodPI: +class HexapodPI(Assembly): + def __init__(self, pvname, name=None, fina_angle_offset=None): + super().__init__(name=name) + self.pvname = pvname + self._append( + PvRecord, + self.pvname + ":SET-POSI-X", + pvreadbackname=self.pvname + ":POSI-X", + accuracy=0.001, + name="x_raw", + is_setting=True, + ) + self._append( + PvRecord, + self.pvname + ":SET-POSI-Y", + pvreadbackname=self.pvname + ":POSI-Y", + accuracy=0.001, + name="y_raw", + is_setting=True, + ) + self._append( + PvRecord, + self.pvname + ":SET-POSI-Z", + pvreadbackname=self.pvname + ":POSI-Z", + accuracy=0.001, + name="z_raw", + is_setting=True, + ) + self._append( + PvRecord, + self.pvname + ":SET-POSI-U", + pvreadbackname=self.pvname + ":POSI-U", + accuracy=0.001, + name="rx_raw", + is_setting=True, + ) + self._append( + PvRecord, + self.pvname + ":SET-POSI-V", + pvreadbackname=self.pvname + ":POSI-V", + accuracy=0.001, + name="ry_raw", + is_setting=True, + ) + self._append( + PvRecord, + self.pvname + ":SET-POSI-W", + pvreadbackname=self.pvname + ":POSI-W", + accuracy=0.001, + name="rz_raw", + is_setting=True, + ) + self._append( + PvRecord, + self.pvname + ":SET-PIVOT-R", + pvreadbackname=self.pvname + ":PIVOT-R", + accuracy=0.001, + name="pivot_x", + is_setting=True, + ) + self._append( + PvRecord, + self.pvname + ":SET-PIVOT-S", + pvreadbackname=self.pvname + ":PIVOT-S", + accuracy=0.001, + name="pivot_y", + is_setting=True, + ) + self._append( + PvRecord, + self.pvname + ":SET-PIVOT-T", + pvreadbackname=self.pvname + ":PIVOT-T", + accuracy=0.001, + name="pivot_z", + is_setting=True, + ) + if fina_angle_offset: + self._append( + AdjustableFS, fina_angle_offset, name="ref_frame_angle", is_setting=True + ) + self._append( + AdjustableVirtual, + [self.x_raw, self.y_raw, self.z_raw], + lambda xraw, yraw, zraw: self._calc_xyz(xraw, yraw, zraw)[0], + lambda x: self._calc_xyzraw( + x, self.y.get_current_value(), self.z.get_current_value() + ), + reset_current_value_to=False, + append_aliases=False, + change_simultaneously=False, + name="x", + is_setting=True, + ) + self._append( + AdjustableVirtual, + [self.x_raw, self.y_raw, self.z_raw], + lambda xraw, yraw, zraw: self._calc_xyz(xraw, yraw, zraw)[1], + lambda y: self._calc_xyzraw( + self.x.get_current_value(), y, self.z.get_current_value() + ), + reset_current_value_to=False, + change_simultaneously=False, + append_aliases=False, + name="y", + is_setting=True, + ) + self._append( + AdjustableVirtual, + [self.x_raw, self.y_raw, self.z_raw], + lambda xraw, yraw, zraw: self._calc_xyz(xraw, yraw, zraw)[2], + lambda z: self._calc_xyzraw( + self.x.get_current_value(), self.y.get_current_value(), z + ), + reset_current_value_to=False, + append_aliases=False, + change_simultaneously=False, + name="z", + is_setting=True, + ) + + @property + def rotation(self): + angs = self.ref_frame_angle.get_current_value() + angs = [angs["rx"], angs["ry"], angs["rz"]] + return Rotation.from_euler("xyz", angs, degrees=True) + + def _calc_xyz(self, xraw, yraw, zraw): + return self.rotation.apply([xraw, yraw, zraw]) + + def _calc_xyzraw(self, x, y, z): + print(self.rotation.inv().apply([x, y, z])) + return self.rotation.inv().apply([x, y, z]) + + # # def get_status(self): + # # s = f'Hexapod {self.alias.get_full_name()} status ({datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S")})\n' + # # if hasattr(self, "ref_frame_angle"): + # # for var in ["x", "y", "z"]: + # # s += ( + # # " " * 4 + # # + var.ljust(16) + # # + f"{self.__dict__[var].get_current_value():g}\n" + # # ) + # # s += ( + # # " " * 4 + # # + "ref_frame_angle".ljust(16) + # # + str(self.ref_frame_angle.get_current_value()) + # # + "\n" + # # ) + # # for var in [ + # # "x_raw", + # # "y_raw", + # # "z_raw", + # # "rx_raw", + # # "ry_raw", + # # "rz_raw", + # # "pivot_x", + # # "pivot_y", + # # "pivot_z", + # # ]: + # # s += ( + # # " " * 4 + # # + var.ljust(16) + # # + f"{self.__dict__[var].get_current_value():g}\n" + # # ) + # # return s + + # def __str__(self): + # return self.get_status() + + # def __repr__(self): + # return self.__str__() + + +class HexapodPI_old: def __init__(self, pvname, name=None, fina_angle_offset=None): self.name = name self.alias = Alias(name) diff --git a/eco/timing/event_timing_new_new.py b/eco/timing/event_timing_new_new.py index 6e16335..f35ff4a 100644 --- a/eco/timing/event_timing_new_new.py +++ b/eco/timing/event_timing_new_new.py @@ -220,15 +220,14 @@ class MasterEventSystem(Assembly): class EvrPulser(Assembly): - def __init__(self, pv_base, outputs=None, name=None): + def __init__(self, pv_base, name=None): super().__init__(name=name) self.pv_base = pv_base - self.name = name self._append( PvEnum, f"{self.pv_base}-Polarity-Sel", name="polarity", is_setting=True ) self._append( - self, PvEnum, f"{self.pv_base}-Ena-Sel", name="enable", is_setting=True + PvEnum, f"{self.pv_base}-Ena-Sel", name="enable", is_setting=True ) self._append( PvRecord, f"{self.pv_base}-Evt-Trig0-SP", name="eventcode", is_setting=True @@ -252,7 +251,7 @@ class EvrPulser(Assembly): ) self._append( PvRecord, - f"{self.pv_base}-Delay-SP", + f"{self.pv_base}-Width-SP", pvreadbackname=f"{self.pv_base}-Width-RB", name="width", is_setting=True, @@ -260,27 +259,24 @@ class EvrPulser(Assembly): self.description = EpicsString(pv_base + "-Name-I") -class EvrOutput: - def __init__(self, pv_base, name=None): +class EvrOutput(Assembly): + def __init__(self, pv_base, pulsers=None, name=None): + super().__init__(name=name) self.pv_base = pv_base - self.name = name - self.alias = Alias(name) - self._pulsers = None + self._pulsers = pulsers # self._update_connected_pulsers() - append_object_to_object(self, PvEnum, f"{self.pv_base}-Ena-SP", name="enable") - self.pulsers_numbers = ( - PvEnum(f"{self.pv_base}-Src-Pulse-SP", name="pulserA"), - PvEnum(f"{self.pv_base}-Src2-Pulse-SP", name="pulserB"), - ) + self._append(PvEnum, f"{self.pv_base}-Ena-SP", name="enable",is_setting=True) + self._append(PvEnum, f"{self.pv_base}-Src-Pulse-SP", name="pulser_number_A", is_setting=True) + self._append(PvEnum, f"{self.pv_base}-Src2-Pulse-SP", name="pulser_number_B", is_setting=True) self.description = EpicsString(pv_base + "-Name-I") def _get_pulserA(self): - return self._pulsers[self.pulsers_numbers[0].get_current_value()] + return self._pulsers[self.pulser_number_A.get_current_value()] pulserA = property(_get_pulserA) def _get_pulserB(self): - return self._pulsers[self.pulsers_numbers[1].get_current_value()] + return self._pulsers[self.pulser_number_B.get_current_value()] pulserB = property(_get_pulserB) @@ -294,40 +290,30 @@ class EvrOutput: # self.pulsers = () - def get_status(self): - pass -class EventReceiver: +class EventReceiver(Assembly): def __init__( self, pvname, n_pulsers=24, n_output_front=8, n_output_rear=16, name=None ): - self.name = name - self.alias = Alias(name) + super().__init__(name=name) self.pvname = pvname pulsers = [] for n in range(n_pulsers): - append_object_to_object( - self, EvrPulser, f"{self.pvname}:Pul{n}", name=f"pulser{n}" - ) + self._append(EvrPulser, f"{self.pvname}:Pul{n}", name=f"pulser{n}", is_setting=True) pulsers.append(self.__dict__[f"pulser{n}"]) self.pulsers = tuple(pulsers) outputs = [] for n in range(n_output_front): - append_object_to_object( - self, - EvrOutput, - f"{self.pvname}:FrontUnivOut{n}", - name=f"output_front{n}", - ) + self._append(EvrOutput, + f"{self.pvname}:FrontUnivOut{n}", pulsers=pulsers, + name=f"output_front{n}", is_setting=True) outputs.append(self.__dict__[f"output_front{n}"]) for n in range(n_output_rear): - append_object_to_object( - self, EvrOutput, f"{self.pvname}:RearUniv{n}", name=f"output_rear{n}" - ) + self._append(EvrOutput, f"{self.pvname}:RearUniv{n}", pulsers=pulsers, name=f"output_rear{n}", is_setting=True) outputs.append(self.__dict__[f"output_rear{n}"]) - for to in outputs: - to._pulsers = self.pulsers + # for to in outputs: + # to._pulsers = self.pulsers self.outputs = outputs diff --git a/eco/utilities/elog.py b/eco/utilities/elog.py index bfe2eb9..307a7f3 100755 --- a/eco/utilities/elog.py +++ b/eco/utilities/elog.py @@ -29,12 +29,11 @@ class Elog: self._screenshot = Screenshot(screenshot_directory) self.read = self._log.read - def post(self, *args, **kwargs): - """ - """ - if not ("Author" in kwargs): - kwargs["Author"] = self.user - return self._log.post(*args, **kwargs) + def post(self, *args, Title=None, Author=None, **kwargs): + """""" + if not Author: + Author = self.user + return self._log.post(*args, Title=Title, Author=Author, **kwargs) def screenshot(self, message="", window=False, desktop=False, delay=3, **kwargs): filepath = self._screenshot.shoot()[0] diff --git a/eco/utilities/runtable.py b/eco/utilities/runtable.py index 27df246..fdf7473 100644 --- a/eco/utilities/runtable.py +++ b/eco/utilities/runtable.py @@ -284,19 +284,19 @@ class Run_Table(): else: name = device.name self.adjustables[name] = {key: value for key, value in device.__dict__.items() if hasattr(value, 'get_current_value')} - self.adjustables[name].update({key+'_offset': PvRecord(pvsetname = value.Id+'.OFF') for key, value in device.__dict__.items() if hasattr(value, '_motor')}) - self.units[name] = {key: caget(value.Id+'.EGU') for key, value in device.__dict__.items() if hasattr(value, '_motor')} + self.adjustables[name].update({key+'_offset': PvRecord(pvsetname = value.pvname+'.OFF') for key, value in device.__dict__.items() if hasattr(value, '_motor')}) + self.units[name] = {key: caget(value.pvname+'.EGU') for key, value in device.__dict__.items() if hasattr(value, '_motor')} if hasattr(device, 'get_current_value'): self.adjustables[name]['_'.join([name, 'self'])]=device def _parse_child_instances(self, parent_class, pp_name=None): - try: - self._get_all_adjustables(parent_class, pp_name) - except: - print(f'Getting adjustables from {parent_class.name} failed') - pass + #try: + self._get_all_adjustables(parent_class, pp_name) + #except: + # print(f'Getting adjustables from {parent_class.name} failed') + # pass if pp_name is not None: pp_name = '_'.join([pp_name, parent_class.name]) else: diff --git a/eco/xdiagnostics/bsen_usd.py b/eco/xdiagnostics/bsen_usd.py index 416fed3..215df6c 100644 --- a/eco/xdiagnostics/bsen_usd.py +++ b/eco/xdiagnostics/bsen_usd.py @@ -1,9 +1,10 @@ import sys sys.path.append("..") -from ..devices_general.motors import MotorRecord +from ..devices_general.motors import MotorRecord, SmaractStreamdevice from ..devices_general.smaract import SmarActRecord from ..devices_general.adjustable import PvRecord +from ..devices_general.cameras_swissfel import CameraBasler from epics import PV from ..aliases import Alias, append_object_to_object @@ -20,6 +21,7 @@ from collections import deque from matplotlib.animation import FuncAnimation from threading import Thread from time import sleep +from ..elements.assembly import Assembly def addPvRecordToSelf( @@ -27,7 +29,10 @@ def addPvRecordToSelf( ): try: self.__dict__[name] = PvRecord( - pvsetname, pvreadbackname=pvreadbackname, accuracy=accuracy, name=name, + pvsetname, + pvreadbackname=pvreadbackname, + accuracy=accuracy, + name=name, ) self.alias.append(self.__dict__[name].alias) except: @@ -49,68 +54,37 @@ def addSmarActRecordToSelf(self, Id=None, name=None): self.alias.append(self.__dict__[name].alias) -class Bsen: +class Bsen(Assembly): def __init__( self, name=None, - Id=None, processing_pipeline="SARES20-CAMS142-M5_psen_db", processing_instance="SARES20-CAMS142-M5_psen_db1", spectrometer_camera_channel="SARES20-CAMS142-M5:FPICTURE", ): - self.Id = Id - self.name = name - self.alias = Alias(name) + super().__init__(name=name) self.proc_client = PipelineClient() self.proc_pipeline = processing_pipeline self.proc_instance = processing_instance self.spectrometer_camera_channel = spectrometer_camera_channel - - self.motor_configuration = { - "transl": { - "id": "-ESB17", - "pv_descr": "Motor8:2 BSEN_transl", - "type": 2, - "sensor": 1, - "speed": 400, - "home_direction": "back", - }, - } - ## white light beam pointing mirrors - - addPvRecordToSelf( - self, - pvsetname="SLAAR21-LMNP-ESBIR11:DRIVE", - pvreadbackname="SLAAR21-LMNP-ESBIR11:MOTRBV", - accuracy=10, - name="mirr1_ry", + self._append( + SmaractStreamdevice, + "SARES23-LIC5", + name="x_mirror_microscope", + is_setting=True, ) - addPvRecordToSelf( - self, - pvsetname="SLAAR21-LMNP-ESBIR12:DRIVE", - pvreadbackname="SLAAR21-LMNP-ESBIR12:MOTRBV", - accuracy=10, - name="mirr1_rx", + self._append(MotorRecord, "SARES20-MF2:MOT_1", name="x_target", is_setting=True) + self._append(MotorRecord, "SARES20-MF2:MOT_2", name="y_target", is_setting=True) + self._append(MotorRecord, "SARES20-MF2:MOT_3", name="z_target", is_setting=True) + self._append( + MotorRecord, "SARES20-MF2:MOT_4", name="zoom_microscope", is_setting=True ) - - addPvRecordToSelf( - self, - pvsetname="SLAAR21-LMNP-ESBIR13:DRIVE", - pvreadbackname="SLAAR21-LMNP-ESBIR13:MOTRBV", - accuracy=10, - name="mirr2_rx", + self._append( + CameraBasler, + "SARES20-PROF141-M1", + name="camera_microscope", + is_setting=True, ) - addPvRecordToSelf( - self, - pvsetname="SLAAR21-LMNP-ESBIR14:DRIVE", - pvreadbackname="SLAAR21-LMNP-ESBIR14:MOTRBV", - accuracy=10, - name="mirr2_ry", - ) - - ### BSEN target position ### - for name, config in self.motor_configuration.items(): - addSmarActRecordToSelf(self, Id=Id + config["id"], name=name) def get_proc_config(self): return self.proc_client.get_pipeline_config(self.proc_pipeline) @@ -137,63 +111,6 @@ class Bsen: ax = fig.add_subplot(111) ax.imshow(im) - def set_stage_config(self): - for name, config in self.motor_configuration.items(): - mot = self.__dict__[name]._device - mot.put("NAME", config["pv_descr"]) - mot.put("STAGE_TYPE", config["type"]) - mot.put("SET_SENSOR_TYPE", config["sensor"]) - mot.put("CL_MAX_FREQ", config["speed"]) - sleep(0.5) - mot.put("CALIBRATE.PROC", 1) - - def home_smaract_stages(self, stages=None): - if stages == None: - stages = self.motor_configuration.keys() - print("#### Positions before homing ####") - print(self.__repr__()) - for name in stages: - config = self.motor_configuration[name] - mot = self.__dict__[name]._device - print( - "#### Homing {} in {} direction ####".format( - name, config["home_direction"] - ) - ) - sleep(1) - if config["home_direction"] == "back": - mot.put("FRM_BACK.PROC", 1) - while mot.get("STATUS") == 7: - sleep(1) - if mot.get("GET_HOMED") == 0: - print( - "Homing failed, try homing {} in forward direction".format(name) - ) - mot.put("FRM_FORW.PROC", 1) - elif config["home_direction"] == "forward": - mot.put("FRM_FORW.PROC", 1) - while mot.get("STATUS") == 7: - sleep(1) - if mot.get("GET_HOMED") == 0: - print( - "Homing failed, try homing {} in backward direction".format( - name - ) - ) - mot.put("FRM_BACK.PROC", 1) - - def get_adjustable_positions_str(self): - ostr = "*****BSEN target position******\n" - - for tkey, item in self.__dict__.items(): - if hasattr(item, "get_current_value"): - pos = item.get_current_value() - ostr += " " + tkey.ljust(17) + " : % 14g\n" % pos - return ostr - - def __repr__(self): - return self.get_adjustable_positions_str() - class TtProcessor: def __init__(self, Nbg=10): @@ -256,4 +173,3 @@ class TtProcessor: self.fig, self.update_plot, init_func=self.setup_plot ) plt.show() - diff --git a/eco/xoptics/dcm_new.py b/eco/xoptics/dcm_new.py index b496f02..19c0142 100644 --- a/eco/xoptics/dcm_new.py +++ b/eco/xoptics/dcm_new.py @@ -9,12 +9,14 @@ from ..devices_general.adjustable import ( PvEnum, spec_convenience, default_representation, + update_changes, ) from ..devices_general.utilities import Changer from ..elements.assembly import Assembly @spec_convenience +@update_changes class DoubleCrystalMono(Assembly): def __init__( self, @@ -78,6 +80,18 @@ class DoubleCrystalMono(Assembly): def get_current_value(self, *args, **kwargs): return self.energy.get_current_value(*args, **kwargs) + def __str__(self): + return f"{self.name} @ {self.get_current_value()} eV" + + def add_value_callback(self, callback, index=None): + return self.energy._pvreadback.add_callback(callback=callback, index=index) + + def clear_value_callback(self, index=None): + if index: + self.energy._pvreadback.remove_callback(index) + else: + self.energy._pvreadback.clear_callbacks() + @spec_convenience @default_representation