From 52e126c1af8ac9693543c691f4e52c321ad0ec85 Mon Sep 17 00:00:00 2001 From: reiche Date: Wed, 5 Feb 2025 17:36:28 +0100 Subject: [PATCH] Adding an adjustable instance which combines a set of normal pvadjustables to a new adjustable class PVCombiAdjustable --- ext/__init__.py | 1 + ext/pvcombiadjustable.py | 52 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 ext/pvcombiadjustable.py diff --git a/ext/__init__.py b/ext/__init__.py index 976402d..c94733c 100644 --- a/ext/__init__.py +++ b/ext/__init__.py @@ -2,3 +2,4 @@ from .magnet import Magnet from .camacquisition import CamAcquisition from .counteradjustable import CounterAdjustable from .bscacquisition import BSCAcquisition +from .pvcombiadjustable import PVCombiAdjustable diff --git a/ext/pvcombiadjustable.py b/ext/pvcombiadjustable.py new file mode 100644 index 0000000..ddb4261 --- /dev/null +++ b/ext/pvcombiadjustable.py @@ -0,0 +1,52 @@ +from slic.core.adjustable import Adjustable + +class PVCombiAdjustable(Adjustable): + def __init__(self, adjustables,values): + self.adjustables = adjustables + self.values = values # array or indiviual array values + self.process_time = np.max(np.array([adj.process_time for adj in self.adjustables])) + + def set_target_value(self, value): + intval = int(value) + if intval < 0 or intval >= len(self.values[0]): + tname = typename(self) + raise AdjustableError(f"Outside of array bounds for {tname} \"{self.name}\" to set target values") + + for adj in self.adjustables: + adj._wait_for_ready() + + for i,adj in enumerate(self.adjustables): + val=self.values[i,intval] + ret = adj.pvs.setvalue.put(val, wait=True, use_complete=True) # use_complete=True enables status in PV.put_complete + error = handle_put_return_value(ret) + if error is not None: + tname = typename(adj) + raise AdjustableError(f"changing {tname} \"{adj.name}\" to {val} {adj.units} failed due to {error}") + + sleep(self.process_time) + + for adj in self.adjustables: + adj._wait_for_done() + + @property + def units(self): + [adj.units() for adj in self.adjustables] + + + def get_current_value(self, readback=True): + return [adj.get_current_value(readback) for adj in self.adjustables] + + def stop(self): + for adj in self.adjustbale: + adj.stop() + + def is_moving(self): + return any([adj.is_moving() for adj in self.adjustables]) + + + + + + + +