From 8ef6f32be6ff9606b21577b5ce85495d97f030ad Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Thu, 20 Aug 2020 12:19:35 +0200 Subject: [PATCH] example and updated python bindings --- docs/src/pyexamples.rst | 33 ++++++++++++++- python/src/detector.cpp | 92 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 113 insertions(+), 12 deletions(-) diff --git a/docs/src/pyexamples.rst b/docs/src/pyexamples.rst index 781145c12..5685040e6 100755 --- a/docs/src/pyexamples.rst +++ b/docs/src/pyexamples.rst @@ -134,4 +134,35 @@ hang around until the main process exits. time.sleep(0.1) #Join the process - p.join() \ No newline at end of file + p.join() + + +------------------------------ +Setting and getting times +------------------------------ + +:: + + import datetime as dt + from slsdet import Detector + + d = Detector() + + # The simplest way is to set the exposure time in + # seconds by using the exptime property + # This sets the exposure time for all modules + d.exptime = 0.5 + + # exptime also accepts a python datetime.timedelta + # which can be used to set the time in almost any unit + + t = dt.timedelta(milliseconds = 2.3) + d.exptime = t + + # or combination of units + t = dt.timedelta(minutes = 3, seconds = 1.23) + d.exptime = t + + #exptime however always returns the time in seconds + >>> d.exptime + 181.23 \ No newline at end of file diff --git a/python/src/detector.cpp b/python/src/detector.cpp index 00300df96..022d0b479 100644 --- a/python/src/detector.cpp +++ b/python/src/detector.cpp @@ -180,6 +180,14 @@ void init_det(py::module &m) { (Result(Detector::*)(sls::Positions) const) & Detector::getDelayAfterTriggerLeft, py::arg() = Positions{}) + .def("getDynamicRange", + (Result(Detector::*)(sls::Positions) const) & + Detector::getDynamicRange, + py::arg() = Positions{}) + .def("setDynamicRange", + (void (Detector::*)(int)) & Detector::setDynamicRange, py::arg()) + .def("getDynamicRangeList", (std::vector(Detector::*)() const) & + Detector::getDynamicRangeList) .def("getTimingMode", (Result(Detector::*)(sls::Positions) const) & Detector::getTimingMode, @@ -188,6 +196,9 @@ void init_det(py::module &m) { (void (Detector::*)(defs::timingMode, sls::Positions)) & Detector::setTimingMode, py::arg(), py::arg() = Positions{}) + .def("getTimingModeList", + (std::vector(Detector::*)() const) & + Detector::getTimingModeList) .def("getSpeed", (Result(Detector::*)(sls::Positions) const) & Detector::getSpeed, @@ -364,6 +375,18 @@ void init_det(py::module &m) { (void (Detector::*)(sls::Positions)) & Detector::sendSoftwareTrigger, py::arg() = Positions{}) + .def("getScan", + (Result(Detector::*)(sls::Positions) const) & + Detector::getScan, + py::arg() = Positions{}) + .def("setScan", + (void (Detector::*)(const defs::scanParameters)) & + Detector::setScan, + py::arg()) + .def("getScanErrorMessage", + (Result(Detector::*)(sls::Positions) const) & + Detector::getScanErrorMessage, + py::arg() = Positions{}) .def("getNumberofUDPInterfaces", (Result(Detector::*)(sls::Positions) const) & Detector::getNumberofUDPInterfaces, @@ -458,6 +481,14 @@ void init_det(py::module &m) { .def("setDestinationUDPPort2", (void (Detector::*)(int, int)) & Detector::setDestinationUDPPort2, py::arg(), py::arg()) + .def("reconfigureUDPDestination", + (void (Detector::*)(sls::Positions)) & + Detector::reconfigureUDPDestination, + py::arg() = Positions{}) + .def("validateUDPConfiguration", + (void (Detector::*)(sls::Positions)) & + Detector::validateUDPConfiguration, + py::arg() = Positions{}) .def("printRxConfiguration", (Result(Detector::*)(sls::Positions) const) & Detector::printRxConfiguration, @@ -670,6 +701,14 @@ void init_det(py::module &m) { (void (Detector::*)(int, sls::Positions)) & Detector::setRxZmqTimer, py::arg(), py::arg() = Positions{}) + .def("getRxZmqStartingFrame", + (Result(Detector::*)(sls::Positions) const) & + Detector::getRxZmqStartingFrame, + py::arg() = Positions{}) + .def("setRxZmqStartingFrame", + (void (Detector::*)(int, sls::Positions)) & + Detector::setRxZmqStartingFrame, + py::arg(), py::arg() = Positions{}) .def("getRxZmqPort", (Result(Detector::*)(sls::Positions) const) & Detector::getRxZmqPort, @@ -700,12 +739,6 @@ void init_det(py::module &m) { (void (Detector::*)(const sls::IpAddr, sls::Positions)) & Detector::setClientZmqIp, py::arg(), py::arg() = Positions{}) - .def("getDynamicRange", - (Result(Detector::*)(sls::Positions) const) & - Detector::getDynamicRange, - py::arg() = Positions{}) - .def("setDynamicRange", - (void (Detector::*)(int)) & Detector::setDynamicRange, py::arg()) .def("getSubExptime", (Result(Detector::*)(sls::Positions) const) & Detector::getSubExptime, @@ -939,11 +972,11 @@ void init_det(py::module &m) { (void (Detector::*)(const int, const int, sls::Positions)) & Detector::setInjectChannel, py::arg(), py::arg(), py::arg() = Positions{}) - .def( - "getVetoPhoton", - (Result>(Detector::*)(const int, sls::Positions)) & - Detector::getVetoPhoton, - py::arg(), py::arg() = Positions{}) + .def("getVetoPhoton", + (void (Detector::*)(const int, const std::string &, + sls::Positions)) & + Detector::getVetoPhoton, + py::arg(), py::arg(), py::arg() = Positions{}) .def("setVetoPhoton", (void (Detector::*)(const int, const int, const int, const std::string &, sls::Positions)) & @@ -954,6 +987,11 @@ void init_det(py::module &m) { (void (Detector::*)(const int, const int, sls::Positions)) & Detector::setVetoReference, py::arg(), py::arg(), py::arg() = Positions{}) + .def("setVetoFile", + (void (Detector::*)(const int, const std::string &, + sls::Positions)) & + Detector::setVetoFile, + py::arg(), py::arg(), py::arg() = Positions{}) .def("getBurstMode", (Result(Detector::*)(sls::Positions)) & Detector::getBurstMode, @@ -962,6 +1000,20 @@ void init_det(py::module &m) { (void (Detector::*)(defs::burstMode, sls::Positions)) & Detector::setBurstMode, py::arg(), py::arg() = Positions{}) + .def("getCDSGain", + (Result(Detector::*)(sls::Positions) const) & + Detector::getCDSGain, + py::arg() = Positions{}) + .def("setCDSGain", + (void (Detector::*)(bool, sls::Positions)) & Detector::setCDSGain, + py::arg(), py::arg() = Positions{}) + .def("getFilter", + (Result(Detector::*)(sls::Positions) const) & + Detector::getFilter, + py::arg() = Positions{}) + .def("setFilter", + (void (Detector::*)(int, sls::Positions)) & Detector::setFilter, + py::arg(), py::arg() = Positions{}) .def("getCurrentSource", (Result(Detector::*)(sls::Positions) const) & Detector::getCurrentSource, @@ -987,6 +1039,24 @@ void init_det(py::module &m) { (void (Detector::*)(const bool, sls::Positions)) & Detector::setVeto, py::arg(), py::arg() = Positions{}) + .def("getADCConfiguration", + (Result(Detector::*)(const int, const int, sls::Positions) + const) & + Detector::getADCConfiguration, + py::arg(), py::arg(), py::arg() = Positions{}) + .def("setADCConfiguration", + (void (Detector::*)(const int, const int, const int, + sls::Positions)) & + Detector::setADCConfiguration, + py::arg(), py::arg(), py::arg(), py::arg() = Positions{}) + .def("getBadChannels", + (void (Detector::*)(const std::string &, sls::Positions) const) & + Detector::getBadChannels, + py::arg(), py::arg() = Positions{}) + .def("setBadChannels", + (void (Detector::*)(const std::string &, sls::Positions)) & + Detector::setBadChannels, + py::arg(), py::arg() = Positions{}) .def("getCounterMask", (Result(Detector::*)(sls::Positions) const) & Detector::getCounterMask,