From 97d1c520e64b88844b81d393fea5da395be151d7 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Fri, 18 Oct 2019 12:24:17 +0200 Subject: [PATCH] python --- python/sls_detector/__init__.py | 1 + python/sls_detector/experimental.py | 88 +++++++++++++++++++++++++++-- python/src/experimental.cpp | 65 ++++++++++++++++----- 3 files changed, 137 insertions(+), 17 deletions(-) diff --git a/python/sls_detector/__init__.py b/python/sls_detector/__init__.py index e3070281e..38a7fbda3 100755 --- a/python/sls_detector/__init__.py +++ b/python/sls_detector/__init__.py @@ -9,5 +9,6 @@ import _sls_detector defs = _sls_detector.slsDetectorDefs runStatus = _sls_detector.slsDetectorDefs.runStatus +speedLevel = _sls_detector.slsDetectorDefs.speedLevel detectorType = _sls_detector.slsDetectorDefs.detectorType detectorSettings = _sls_detector.slsDetectorDefs.detectorSettings diff --git a/python/sls_detector/experimental.py b/python/sls_detector/experimental.py index db646c457..19286201b 100755 --- a/python/sls_detector/experimental.py +++ b/python/sls_detector/experimental.py @@ -2,6 +2,7 @@ from _sls_detector import CppDetectorApi from _sls_detector import slsDetectorDefs runStatus = slsDetectorDefs.runStatus +speedLevel = slsDetectorDefs.speedLevel from .utils import element_if_equal, all_equal from .utils import Geometry, to_geo import datetime as dt @@ -9,6 +10,20 @@ import datetime as dt from functools import wraps from collections import namedtuple +class Register: + """ + Helper class to read and write to registers using a + more Pythonic syntax + """ + def __init__(self, detector): + self._detector = detector + + def __getitem__(self, key): + return self._detector.readRegister(key) + + def __setitem__(self, key, value): + self._detector.writeRegister(key, value) + def freeze(cls): cls.__frozen = False @@ -51,6 +66,7 @@ class ExperimentalDetector(CppDetectorApi): slsDetectorPackage. Default value is 0. """ super().__init__(multi_id) + self._register = Register(self) # CONFIGURATION def __len__(self): @@ -73,7 +89,7 @@ class ExperimentalDetector(CppDetectorApi): @config.setter def config(self, fname): - self.setConfig(fname) + self.loadConfig(fname) @property def parameters(self): @@ -373,10 +389,10 @@ class ExperimentalDetector(CppDetectorApi): # ZMQ Streaming Parameters (Receiver<->Client) @property - def rx_zmqdatastream(self): + def rx_datastream(self): return element_if_equal(self.getRxZmqDataStream()) - @rx_zmqdatastream.setter + @rx_datastream.setter def rx_zmqdatastream(self, enable): self.setRxZmqDataStream(enable) @@ -412,10 +428,74 @@ class ExperimentalDetector(CppDetectorApi): def zmqip(self, ip): self.setClientZmqIp(ip) + #TODO! Change to dst + @property + def rx_udpip(self): + return element_if_equal(self.getDestinationUDPIP()) + + @rx_udpip.setter + def rx_udpip(self, ip): + self.getDestinationUDPIP(ip) + @property def vhighvoltage(self): return element_if_equal(self.getHighVoltage()) @vhighvoltage.setter def vhighvoltage(self, v): - self.setHighVoltage(v) \ No newline at end of file + self.setHighVoltage(v) + + + @property + def trimbits(self): + return NotImplementedError('trimbits are set only') + + @trimbits.setter + def trimbits(self, fname): + self.loadTrimbits(fname) + + @property + def lock(self): + return element_if_equal(self.getDetectorLock()) + + @lock.setter + def lock(self, value): + self.setDetectorLock(value) + + @property + def rx_lock(self): + return element_if_equal(self.getRxLock()) + + @rx_lock.setter + def rx_lock(self, value): + self.setRxLock(value) + + @property + def lastclient(self): + return element_if_equal(self.getLastClientIP()) + + @property + def reg(self): + return self._register + + @property + def ratecorr(self): + """ tau in ns """ + return element_if_equal(self.getRateCorrection()) + + @ratecorr.setter + def ratecorr(self, tau): + self.setRateCorrection(tau) + + @property + def clkdivider(self): + res = [int(value) for value in self.getSpeed()] + return element_if_equal(res) + + @clkdivider.setter + def clkdivider(self, value): + self.setSpeed(speedLevel(value)) + + @property + def frameindex(self): + return self.getRxCurrentFrameIndex() \ No newline at end of file diff --git a/python/src/experimental.cpp b/python/src/experimental.cpp index 707787626..ee1f81650 100644 --- a/python/src/experimental.cpp +++ b/python/src/experimental.cpp @@ -130,33 +130,42 @@ void init_experimental(py::module &m) { .def("selectUDPInterface", &Detector::selectUDPInterface, py::arg(), py::arg() = Positions{}) + // Using lambda to allow for conversion from IpAddr .def("getSourceUDPIP", - [](const Detector &d) { + [](const Detector &d, Positions pos) { std::vector res; - for (const auto &s : d.getSourceUDPIP()) + for (const auto &s : d.getSourceUDPIP(pos)) res.push_back(s.str()); return res; - }) - .def("setSourceUDPIP", &Detector::setSourceUDPIP, py::arg(), + }, py::arg() = Positions{}) + .def("setSourceUDPIP", + [](Detector &d, std::string ip, Positions pos) { + d.setSourceUDPIP(sls::IpAddr(ip), pos); + }, + py::arg(), py::arg() = Positions{}) .def("getSourceUDPIP2", - [](const Detector &d) { + [](const Detector &d, Positions pos) { std::vector res; - for (const auto &s : d.getSourceUDPIP2()) + for (const auto &s : d.getSourceUDPIP2(pos)) res.push_back(s.str()); return res; - }) - .def("setSourceUDPIP2", &Detector::setSourceUDPIP2, py::arg(), + }, py::arg() = Positions{}) - + .def("setSourceUDPIP2", + [](Detector &d, std::string ip, Positions pos) { + d.setSourceUDPIP2(sls::IpAddr(ip), pos); + }, + py::arg(), py::arg() = Positions{}) .def("getSourceUDPMAC", - [](const Detector &d) { + [](const Detector &d, Positions pos) { std::vector res; - for (const auto &s : d.getSourceUDPMAC()) + for (const auto &s : d.getSourceUDPMAC(pos)) res.push_back(s.str()); return res; - }) + }, + py::arg() = Positions{}) .def("setSourceUDPMAC", &Detector::setSourceUDPMAC, py::arg(), py::arg() = Positions{}) @@ -496,13 +505,43 @@ void init_experimental(py::module &m) { .def("readRegister", &Detector::readRegister, py::arg(), py::arg() = Positions{}) + .def("writeRegister", &Detector::writeRegister, py::arg(), py::arg(), + py::arg() = Positions{}) + .def("getStartingFrameNumber", &Detector::getStartingFrameNumber, py::arg() = Positions{}) .def("setStartingFrameNumber", &Detector::setStartingFrameNumber, py::arg(), py::arg() = Positions{}) - // File + /************************************************** + * * + * Insignificant * + * * + * ************************************************/ + .def("getControlPort", &Detector::getControlPort, + py::arg() = Positions{}) + .def("setControlPort", &Detector::setControlPort, py::arg(), + py::arg() = Positions{}) + .def("getStopPort", &Detector::getStopPort, py::arg() = Positions{}) + .def("setStopPort", &Detector::setStopPort, py::arg(), + py::arg() = Positions{}) + .def("getDetectorLock", &Detector::getDetectorLock, + py::arg() = Positions{}) + .def("setDetectorLock", &Detector::setDetectorLock, py::arg(), + py::arg() = Positions{}) + .def("getLastClientIP", &Detector::getLastClientIP, + py::arg() = Positions{}) + .def("executeCommand", &Detector::executeCommand, py::arg(), + py::arg() = Positions{}) + .def("getNumberOfFramesFromStart", + &Detector::getNumberOfFramesFromStart, py::arg() = Positions{}) + .def("getActualTime", &Detector::getActualTime, py::arg() = Positions{}) + .def("getMeasurementTime", &Detector::getMeasurementTime, + py::arg() = Positions{}) + .def("getUserDetails", &Detector::getUserDetails) + .def("getRxCurrentFrameIndex", &Detector::getRxCurrentFrameIndex, + py::arg() = Positions{}) // Time .def("setSubExptime", &Detector::setSubExptime, py::arg(),