From 55229f77a37ab17cf4c046af8df92fc7cf8ab9bb Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Wed, 12 Jun 2019 10:41:50 +0200 Subject: [PATCH] python --- python/sls_detector/decorators.py | 46 ----------------------------- python/sls_detector/detector.py | 4 --- python/sls_detector/eiger.py | 1 - python/sls_detector/jungfrau.py | 1 - python/sls_detector/jungfrau_ctb.py | 1 - python/sls_detector/registers.py | 2 -- python/src/main.cpp | 23 +++++++++------ 7 files changed, 14 insertions(+), 64 deletions(-) diff --git a/python/sls_detector/decorators.py b/python/sls_detector/decorators.py index d1ec4482a..8e8f2c600 100755 --- a/python/sls_detector/decorators.py +++ b/python/sls_detector/decorators.py @@ -7,49 +7,3 @@ from .errors import DetectorError import functools -def error_handling(func): - """ - Check for errors registered by the slsDetectorSoftware - """ - @functools.wraps(func) - def wrapper(self, *args, **kwargs): - - # remove any previous errors - self._api.clearErrorMask() - - # call function - result = func(self, *args, **kwargs) - - # check for new errors - m = self.error_mask - if m != 0: - msg = self.error_message - self._api.clearErrorMask() - raise DetectorError(msg) - return result - - return wrapper - - -def property_error_handling(func): - """ - Check for errors registered by the slsDetectorSoftware - """ - - @functools.wraps(func) - def wrapper(self, *args, **kwargs): - # remove any previous errors - self._detector._api.clearErrorMask() - - # call function - result = func(self, *args, **kwargs) - - # check for new errors - m = self._detector.error_mask - if m != 0: - msg = self._detector.error_message - self._detector._api.clearErrorMask() - raise DetectorError(msg) - return result - - return wrapper \ No newline at end of file diff --git a/python/sls_detector/detector.py b/python/sls_detector/detector.py index 512437d18..2dea3f799 100755 --- a/python/sls_detector/detector.py +++ b/python/sls_detector/detector.py @@ -10,7 +10,6 @@ from collections.abc import Iterable from collections import namedtuple from _sls_detector import DetectorApi -from .decorators import error_handling from .detector_property import DetectorProperty from .errors import DetectorError, DetectorValueError from .registers import Register @@ -97,9 +96,6 @@ class Detector: def busy(self, value): self._api.setAcquiringFlag(value) - def clear_errors(self): - """Clear the error mask for the detector. Used to reset after checking.""" - self._api.clearErrorMask() @property def client_version(self): diff --git a/python/sls_detector/eiger.py b/python/sls_detector/eiger.py index 1d48c2241..e5b85338b 100755 --- a/python/sls_detector/eiger.py +++ b/python/sls_detector/eiger.py @@ -13,7 +13,6 @@ from functools import partial from .adcs import Adc, DetectorAdcs from .dacs import DetectorDacs -from .decorators import error_handling from .detector import Detector from .detector_property import DetectorProperty from .utils import element_if_equal diff --git a/python/sls_detector/jungfrau.py b/python/sls_detector/jungfrau.py index 3db0e3fea..0526e9270 100755 --- a/python/sls_detector/jungfrau.py +++ b/python/sls_detector/jungfrau.py @@ -5,7 +5,6 @@ Jungfrau detector class and support functions. Inherits from Detector. """ from .adcs import Adc, DetectorAdcs -from .decorators import error_handling from .detector import Detector from .dacs import DetectorDacs from .utils import element_if_equal diff --git a/python/sls_detector/jungfrau_ctb.py b/python/sls_detector/jungfrau_ctb.py index 8192fe81d..fae5a51f9 100755 --- a/python/sls_detector/jungfrau_ctb.py +++ b/python/sls_detector/jungfrau_ctb.py @@ -8,7 +8,6 @@ from .utils import element_if_equal from .adcs import DetectorAdcs, Adc from .dacs import DetectorDacs from .detector_property import DetectorProperty -from .decorators import error_handling from .registers import Register, Adc_register class JungfrauCTBDacs(DetectorDacs): diff --git a/python/sls_detector/registers.py b/python/sls_detector/registers.py index 48e6f2306..0685dc3ea 100755 --- a/python/sls_detector/registers.py +++ b/python/sls_detector/registers.py @@ -1,9 +1,7 @@ -from .decorators import error_handling, property_error_handling class Register: def __init__(self, detector): self._detector = detector - @property_error_handling def __getitem__(self, key): return self._detector._api.readRegister(key) diff --git a/python/src/main.cpp b/python/src/main.cpp index 76f395bea..eb0f78e28 100755 --- a/python/src/main.cpp +++ b/python/src/main.cpp @@ -284,9 +284,11 @@ PYBIND11_MODULE(_sls_detector, m) { .def("getPatternWord", &Detector::getPatternWord, py::arg("addr"), py::arg("det_id") = -1) - .def("setPatternIOControl", &Detector::setPatternIOControl, py::arg("word"), py::arg("det_id") = -1) - .def("setPatternClockControl", &Detector::setPatternClockControl, py::arg("word"), py::arg("det_id") = -1) - + .def("setPatternIOControl", &Detector::setPatternIOControl, + py::arg("word"), py::arg("det_id") = -1) + .def("setPatternClockControl", &Detector::setPatternClockControl, + py::arg("word"), py::arg("det_id") = -1) + .def("setPatternWaitAddr", &Detector::setPatternWaitAddr, py::arg("level"), py::arg("addr"), py::arg("det_id") = -1) .def("getPatternWaitAddr", &Detector::getPatternWaitAddr, @@ -303,8 +305,6 @@ PYBIND11_MODULE(_sls_detector, m) { .def("getNumberOfDetectors", &Detector::getNumberOfDetectors) .def("getDetectorGeometry", &Detector::getDetectorGeometry); - - // Experimental API to use the multi directly and inherit from to reduce // code duplication need to investigate how to handle documentation py::class_ multiDetectorApi(m, "multiDetectorApi"); @@ -316,10 +316,15 @@ PYBIND11_MODULE(_sls_detector, m) { py::arg() = -1, py::arg("det_id") = -1), py::cpp_function(&multiSlsDetector::setOnline, py::arg(), py::arg("flag"), py::arg("det_id") = -1)) - // .def("_setOnline", &multiSlsDetector::setOnline, py::arg("flag") = - // -1, - // py::arg("det_id") = -1) - + .def_property("exptime", + py::cpp_function(&multiSlsDetector::setExposureTime, + py::arg(), py::arg() = -1, py::arg() = 0, + py::arg("det_id") = -1), + py::cpp_function(&multiSlsDetector::setExposureTime, + py::arg(), py::arg() = -1, py::arg() = 0, + py::arg("det_id") = -1)) + .def("getExposureTime", &multiSlsDetector::setExposureTime, py::arg()=-1, + py::arg() = 0, py::arg("det_id") = -1) .def_property_readonly( "hostname", py::cpp_function(&multiSlsDetector::getHostname, py::arg(), py::arg("det_id") = -1))