From a95d8f664a53ae03ca99ab006ca0b0c625b1adb8 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Thu, 10 Sep 2020 12:16:25 +0200 Subject: [PATCH] added slowadc to python --- python/CMakeLists.txt | 1 + python/scripts/cmd_python.py | 1 + python/slsdet/detector.py | 5 +++++ python/slsdet/slowadcproxy.py | 25 +++++++++++++++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 python/slsdet/slowadcproxy.py diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 49199bfcc..2af935c94 100755 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -36,6 +36,7 @@ set( PYTHON_FILES gotthard2.py moench.py jsonproxy.py + slowadcproxy.py ctb.py jungfrau.py mythen3.py diff --git a/python/scripts/cmd_python.py b/python/scripts/cmd_python.py index eaa282845..c0817184b 100644 --- a/python/scripts/cmd_python.py +++ b/python/scripts/cmd_python.py @@ -70,6 +70,7 @@ dacs = [ ] intentionally_missing = [ + 'activate', #use getActive and getRxPadDeactivatedMode syntax is not a good fit for python 'temp_10ge', #temperatures already available from enum or specialized class 'temp_adc', 'temp_dcdc', diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index 2fd78f6a6..de1266fa7 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -12,6 +12,7 @@ from .utils import element_if_equal, all_equal, get_set_bits, list_to_bitmask from .utils import Geometry, to_geo, element, reduce_time, is_iterable from . import utils as ut from .jsonproxy import JsonProxy +from .slowadcproxy import SlowAdcProxy from .registers import Register, Adc_register import datetime as dt @@ -1013,6 +1014,10 @@ class Detector(CppDetectorApi): """ return self._register + @property + def slowadc(self): + return SlowAdcProxy(self) + @property def daclist(self): """Gets the list of enums for every dac for this detector.""" diff --git a/python/slsdet/slowadcproxy.py b/python/slsdet/slowadcproxy.py new file mode 100644 index 000000000..291f526a8 --- /dev/null +++ b/python/slsdet/slowadcproxy.py @@ -0,0 +1,25 @@ +from .utils import element_if_equal +from .enums import dacIndex +class SlowAdcProxy: + """ + Proxy class to allow for more intuitive reading the slow ADCs + """ + def __init__(self, det): + self.det = det + + def __getitem__(self, key): + dac_index = dacIndex(int(dacIndex.SLOW_ADC0)+key) + return element_if_equal(self.det.getSlowADC(dac_index)) + + def __repr__(self): + rstr = '' + for i in range(7): + r = element_if_equal(self.__getitem__(i)) + if isinstance(r, list): + rstr += ' '.join(f'{item} mV' for item in r) + else: + rstr += f'{i}: {r} mV\n' + + return rstr.strip('\n') + +