From 0b9bc44f149132671481d5dd6a414678ae0a60cf Mon Sep 17 00:00:00 2001 From: Didier Voulot Date: Sat, 17 Sep 2022 07:37:26 +0200 Subject: [PATCH] add magnets.py and sfop.py --- magnets.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ sfop.py | 5 +++++ 2 files changed, 63 insertions(+) create mode 100644 magnets.py create mode 100644 sfop.py diff --git a/magnets.py b/magnets.py new file mode 100644 index 0000000..9aae526 --- /dev/null +++ b/magnets.py @@ -0,0 +1,58 @@ +from slic.core.adjustable import Adjustable, PVAdjustable +from slic.core.device import SimpleDevice + + + + +class MagnetsScaler(Adjustable): + + def __init__(self, ID="MAGNETS-SCALER", factor=1): + super().__init__(ID) + self.factor = factor + mag1 = Magnet("SINEG01-MSOL010") +# mag2 = Magnet("SINEG01-MSOL010") + self.magnets = SimpleDevice( + ID, + m1=mag1, +# m2=mag2 + ) + self._magnets = [ + mag1, +# mag2 + ] + + + def get_current_value(self): + return self.factor + + def set_target_value(self, factor): + old_factor = self.factor + self.factor = factor + print(old_factor, factor) + tasks = [] # we collect tasks to run in parallel, ... + for m in self._magnets: + current = m.get() + print(current, current / old_factor * factor) + t = m.set(current / old_factor * factor) + for t in tasks: # ... then we need to wait for all tasks to finish + t.wait() + + def is_moving(self): + return any(m.is_moving() for m in self.magnets) + + + + +class Magnet(PVAdjustable): + + def __init__(self, ID): + pvn_set = ID + ":I-SET" + pvn_read = ID + ":I-READ" +# pvn_comp = ID + ":I_COMP" +# super().__init__(pvn_set, pvn_read, pvname_moving=pvn_comp) # COMP updates only once per second, so we cannot use it. + super().__init__(pvn_set, pvn_read, accuracy=0.01) + + + + + diff --git a/sfop.py b/sfop.py new file mode 100644 index 0000000..689d95c --- /dev/null +++ b/sfop.py @@ -0,0 +1,5 @@ +from magnets import MagnetsScaler + +mags = MagnetsScaler() + +