This commit is contained in:
Erik Frojdh 2019-06-12 10:41:50 +02:00
parent 1fed3553b9
commit 55229f77a3
7 changed files with 14 additions and 64 deletions

View File

@ -7,49 +7,3 @@ from .errors import DetectorError
import functools 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

View File

@ -10,7 +10,6 @@ from collections.abc import Iterable
from collections import namedtuple from collections import namedtuple
from _sls_detector import DetectorApi from _sls_detector import DetectorApi
from .decorators import error_handling
from .detector_property import DetectorProperty from .detector_property import DetectorProperty
from .errors import DetectorError, DetectorValueError from .errors import DetectorError, DetectorValueError
from .registers import Register from .registers import Register
@ -97,9 +96,6 @@ class Detector:
def busy(self, value): def busy(self, value):
self._api.setAcquiringFlag(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 @property
def client_version(self): def client_version(self):

View File

@ -13,7 +13,6 @@ from functools import partial
from .adcs import Adc, DetectorAdcs from .adcs import Adc, DetectorAdcs
from .dacs import DetectorDacs from .dacs import DetectorDacs
from .decorators import error_handling
from .detector import Detector from .detector import Detector
from .detector_property import DetectorProperty from .detector_property import DetectorProperty
from .utils import element_if_equal from .utils import element_if_equal

View File

@ -5,7 +5,6 @@ Jungfrau detector class and support functions.
Inherits from Detector. Inherits from Detector.
""" """
from .adcs import Adc, DetectorAdcs from .adcs import Adc, DetectorAdcs
from .decorators import error_handling
from .detector import Detector from .detector import Detector
from .dacs import DetectorDacs from .dacs import DetectorDacs
from .utils import element_if_equal from .utils import element_if_equal

View File

@ -8,7 +8,6 @@ from .utils import element_if_equal
from .adcs import DetectorAdcs, Adc from .adcs import DetectorAdcs, Adc
from .dacs import DetectorDacs from .dacs import DetectorDacs
from .detector_property import DetectorProperty from .detector_property import DetectorProperty
from .decorators import error_handling
from .registers import Register, Adc_register from .registers import Register, Adc_register
class JungfrauCTBDacs(DetectorDacs): class JungfrauCTBDacs(DetectorDacs):

View File

@ -1,9 +1,7 @@
from .decorators import error_handling, property_error_handling
class Register: class Register:
def __init__(self, detector): def __init__(self, detector):
self._detector = detector self._detector = detector
@property_error_handling
def __getitem__(self, key): def __getitem__(self, key):
return self._detector._api.readRegister(key) return self._detector._api.readRegister(key)

View File

@ -284,9 +284,11 @@ PYBIND11_MODULE(_sls_detector, m) {
.def("getPatternWord", &Detector::getPatternWord, py::arg("addr"), .def("getPatternWord", &Detector::getPatternWord, py::arg("addr"),
py::arg("det_id") = -1) py::arg("det_id") = -1)
.def("setPatternIOControl", &Detector::setPatternIOControl, py::arg("word"), py::arg("det_id") = -1) .def("setPatternIOControl", &Detector::setPatternIOControl,
.def("setPatternClockControl", &Detector::setPatternClockControl, py::arg("word"), py::arg("det_id") = -1) py::arg("word"), py::arg("det_id") = -1)
.def("setPatternClockControl", &Detector::setPatternClockControl,
py::arg("word"), py::arg("det_id") = -1)
.def("setPatternWaitAddr", &Detector::setPatternWaitAddr, .def("setPatternWaitAddr", &Detector::setPatternWaitAddr,
py::arg("level"), py::arg("addr"), py::arg("det_id") = -1) py::arg("level"), py::arg("addr"), py::arg("det_id") = -1)
.def("getPatternWaitAddr", &Detector::getPatternWaitAddr, .def("getPatternWaitAddr", &Detector::getPatternWaitAddr,
@ -303,8 +305,6 @@ PYBIND11_MODULE(_sls_detector, m) {
.def("getNumberOfDetectors", &Detector::getNumberOfDetectors) .def("getNumberOfDetectors", &Detector::getNumberOfDetectors)
.def("getDetectorGeometry", &Detector::getDetectorGeometry); .def("getDetectorGeometry", &Detector::getDetectorGeometry);
// Experimental API to use the multi directly and inherit from to reduce // Experimental API to use the multi directly and inherit from to reduce
// code duplication need to investigate how to handle documentation // code duplication need to investigate how to handle documentation
py::class_<multiSlsDetector> multiDetectorApi(m, "multiDetectorApi"); py::class_<multiSlsDetector> multiDetectorApi(m, "multiDetectorApi");
@ -316,10 +316,15 @@ PYBIND11_MODULE(_sls_detector, m) {
py::arg() = -1, py::arg("det_id") = -1), py::arg() = -1, py::arg("det_id") = -1),
py::cpp_function(&multiSlsDetector::setOnline, py::arg(), py::cpp_function(&multiSlsDetector::setOnline, py::arg(),
py::arg("flag"), py::arg("det_id") = -1)) py::arg("flag"), py::arg("det_id") = -1))
// .def("_setOnline", &multiSlsDetector::setOnline, py::arg("flag") = .def_property("exptime",
// -1, py::cpp_function(&multiSlsDetector::setExposureTime,
// py::arg("det_id") = -1) 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( .def_property_readonly(
"hostname", py::cpp_function(&multiSlsDetector::getHostname, "hostname", py::cpp_function(&multiSlsDetector::getHostname,
py::arg(), py::arg("det_id") = -1)) py::arg(), py::arg("det_id") = -1))