diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index 819522a56..9f6d60a1d 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -2013,7 +2013,7 @@ class Detector(CppDetectorApi): Note ----- - By default, the on-chip gain switching is active during the entire exposure. This mode disables the on-chip gain switching comparator automatically after 93.75% of exposure time (only for longer than 100us).\n + By default, the on-chip gain switching is active during the entire exposure. This mode disables the on-chip gain switching comparator automatically after 93.75% of exposure time (only for longer than 100us). The % is only for chipv1.0, the duration can be set for chipv1.1.\n Default is 0 or this mode disabled (comparator enabled throughout). 1 enables mode. 0 disables mode. """ return self.getAutoCompDisable() @@ -2022,6 +2022,31 @@ class Detector(CppDetectorApi): def auto_comp_disable(self, value): ut.set_using_dict(self.setAutoCompDisable, value) + @property + @element + def comp_disable_time(self): + """[Jungfrau] Time before end of exposure when comparator is disabled. + + Note + ----- + It is only possible for chipv1.1. + :getter: always returns in seconds. To get in datetime.delta, use getComparatorDisableTime + + Example + ----------- + >>> d.comp_disable_time = 1.05 + >>> d.comp_disable_time = datetime.timedelta(minutes = 3, seconds = 1.23) + >>> d.comp_disable_time + 181.23 + >>> d.getComparatorDisableTime() + [datetime.timedelta(seconds=181, microseconds=230000)] + """ + return ut.reduce_time(self.getComparatorDisableTime()) + + @comp_disable_time.setter + def comp_disable_time(self, value): + ut.set_time_using_dict(self.setComparatorDisableTime, value) + @property @element diff --git a/python/src/detector.cpp b/python/src/detector.cpp index 4b3200ce0..d751d5e18 100644 --- a/python/src/detector.cpp +++ b/python/src/detector.cpp @@ -978,6 +978,14 @@ void init_det(py::module &m) { (void (Detector::*)(bool, sls::Positions)) & Detector::setAutoCompDisable, py::arg(), py::arg() = Positions{}) + .def("getComparatorDisableTime", + (Result(Detector::*)(sls::Positions) const) & + Detector::getComparatorDisableTime, + py::arg() = Positions{}) + .def("setComparatorDisableTime", + (void (Detector::*)(sls::ns, sls::Positions)) & + Detector::setComparatorDisableTime, + py::arg(), py::arg() = Positions{}) .def("getNumberOfAdditionalStorageCells", (Result(Detector::*)(sls::Positions) const) & Detector::getNumberOfAdditionalStorageCells, diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index 6c92644f8..d03e8a9f5 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -1662,6 +1662,32 @@ int autoCompDisable(int on) { EXT_DAQ_CTRL_CMP_LGC_ENBL_OFST); } +int setComparatorDisableTime(int64_t val) { + if (getChipVersion() != 11) { + return FAIL; + } + if (val < 0) { + LOG(logERROR, + ("Invalid comp disable time: %lld ns\n", (long long int)val)); + return FAIL; + } + LOG(logINFO, ("Setting comp disable time %lld ns\n", (long long int)val)); + val *= (1E-3 * CLK_RUN); + bus_w(COMP_DSBLE_TIME_REG, val); + + // validate for tolerance + int64_t retval = getComparatorDisableTime(); + val /= (1E-3 * CLK_RUN); + if (val != retval) { + return FAIL; + } + return OK; +} + +int64_t getComparatorDisableTime() { + return bus_r(COMP_DSBLE_TIME_REG) / (1E-3 * CLK_RUN); +} + void configureASICTimer() { LOG(logINFO, ("Configuring ASIC Timer\n")); bus_w(ASIC_CTRL_REG, (bus_r(ASIC_CTRL_REG) & ~ASIC_CTRL_PRCHRG_TMR_MSK) | diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index b971e56ad..de06ff9ff 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -450,6 +450,8 @@ int powerChip(int on); int isChipConfigured(); void configureChip(); int autoCompDisable(int on); +int setComparatorDisableTime(int64_t val); +int64_t getComparatorDisableTime(); void configureASICTimer(); int setClockDivider(enum CLKINDEX ind, int val); int getClockDivider(enum CLKINDEX ind); diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h index d1f0aa6e6..594de8402 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h @@ -258,4 +258,6 @@ int get_chip_version(int); int get_default_dac(int); int set_default_dac(int); int get_gain_mode(int); -int set_gain_mode(int); \ No newline at end of file +int set_gain_mode(int); +int get_comp_disable_time(int); +int set_comp_disable_time(int); \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 35668d4c9..eb3887bfb 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -384,6 +384,8 @@ void function_table() { flist[F_SET_DEFAULT_DAC] = &set_default_dac; flist[F_GET_GAIN_MODE] = &get_gain_mode; flist[F_SET_GAIN_MODE] = &set_gain_mode; + flist[F_GET_COMP_DISABLE_TIME] = &get_comp_disable_time; + flist[F_SET_COMP_DISABLE_TIME] = &set_comp_disable_time; // check if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { @@ -8613,3 +8615,61 @@ int set_gain_mode(int file_des) { #endif return Server_SendResult(file_des, INT32, NULL, 0); } + +int get_comp_disable_time(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int64_t retval = -1; +#ifndef JUNGFRAUD + functionNotImplemented(); +#else + // get only + if (getChipVersion() != 11) { + ret = FAIL; + strcpy(mess, + "Cannot get comparator disable time. Only valid for chipv1.1\n"); + LOG(logERROR, (mess)); + } else { + retval = getComparatorDisableTime(); + LOG(logDEBUG1, + ("retval comp disable time %lld ns\n", (long long int)retval)); + } +#endif + return Server_SendResult(file_des, INT64, &retval, sizeof(retval)); +} + +int set_comp_disable_time(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int64_t arg = -1; + if (receiveData(file_des, &arg, sizeof(arg), INT64) < 0) + return printSocketReadError(); + LOG(logDEBUG1, ("Setting comp disable time %lld ns\n", (long long int)arg)); + +#ifndef JUNGFRAUD + functionNotImplemented(); +#else + // only set + if (Server_VerifyLock() == OK) { + if (getChipVersion() != 11) { + ret = FAIL; + strcpy(mess, "Cannot get comparator disable time. Only valid for " + "chipv1.1\n"); + LOG(logERROR, (mess)); + } else { + ret = setComparatorDisableTime(arg); + int64_t retval = getComparatorDisableTime(); + LOG(logDEBUG1, ("retval get comp disable time %lld ns\n", + (long long int)retval)); + if (ret == FAIL) { + sprintf(mess, + "Could not set comp disable time. Set %lld ns, read " + "%lld ns.\n", + (long long int)arg, (long long int)retval); + LOG(logERROR, (mess)); + } + } + } +#endif + return Server_SendResult(file_des, INT64, NULL, 0); +} \ No newline at end of file diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index dc4f6c6ba..08eaa8bc8 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -1131,15 +1131,23 @@ class Detector { /** [Jungfrau] Advanced * //TODO naming - * By default, the on-chip gain switching is active during the entire - * exposure. This mode disables the on-chip gain switching comparator - * automatically after 93.75% of exposure time (only for longer than - * 100us).\n - * Default is false or this mode disabled(comparator enabled throughout). - * true enables mode. 0 disables mode. + * By default, the on-chip gain switching is active during the + * entire exposure. This mode disables the on-chip gain switching comparator + * automatically after 93.75% of exposure time (only for longer than 100us). + * The % is for chipv1.0. One can set the duration for chipv1.1 using + * setComparatorDisableTime\n Default is false or this mode + * disabled(comparator enabled throughout). true enables mode. 0 disables + * mode. */ void setAutoCompDisable(bool value, Positions pos = {}); + /** [Jungfrau] */ + Result getComparatorDisableTime(Positions pos = {}) const; + + /** [Jungfrau] Time before end of exposure when comparator is disabled. It + * is only possible for chipv1.1.*/ + void setComparatorDisableTime(ns t, Positions pos = {}); + /** [Jungfrau] Advanced TODO naming */ Result getNumberOfAdditionalStorageCells(Positions pos = {}) const; diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index 190cfde8a..3f8b93659 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1729,37 +1729,6 @@ std::string CmdProxy::TemperatureEvent(int action) { return os.str(); } -std::string AutoComparatorDisable(const int action) { - std::ostringstream os; - os << cmd << ' '; - if (action == slsDetectorDefs::HELP_ACTION) - os << "[0, 1]\n\t[Jungfrau] Auto comparator disable mode. By default, " - "the on-chip gain switching is active during the entire " - "exposure.This mode disables the on - chip gain switching " - "comparator automatically after 93.75% of exposure time (only " - "for longer than 100us). \n\tDefault is 0 or this mode " - "disabled(comparator enabled throughout). 1 enables mode. 0 " - "disables mode." - << '\n'; - else if (action == slsDetectorDefs::GET_ACTION) { - if (!args.empty()) { - WrongNumberOfParameters(0); - } - auto t = det->GETFCN(std::vector{det_id}); - os << OutString(t) << '\n'; - } else if (action == slsDetectorDefs::PUT_ACTION) { - if (args.size() != 1) { - WrongNumberOfParameters(1); - } - auto val = CONV(args[0]); - det->SETFCN(val, std::vector{det_id}); - os << args.front() << '\n'; - } else { - throw sls::RuntimeError("Unknown action"); - } - return os.str(); -} - /* Gotthard Specific */ std::string CmdProxy::ROI(int action) { diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index 47f5cc7a1..036f8b972 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -925,7 +925,8 @@ class CmdProxy { {"temp_threshold", &CmdProxy::temp_threshold}, {"temp_control", &CmdProxy::temp_control}, {"temp_event", &CmdProxy::TemperatureEvent}, - {"auto_comp_disable", &CmdProxy::AutoComparatorDisable}, + {"auto_comp_disable", &CmdProxy::auto_comp_disable}, + {"comp_disable_time", &CmdProxy::comp_disable_time}, {"storagecells", &CmdProxy::storagecells}, {"storagecell_start", &CmdProxy::storagecell_start}, {"storagecell_delay", &CmdProxy::storagecell_delay}, @@ -1123,7 +1124,6 @@ class CmdProxy { std::string DataStream(int action); /* Jungfrau Specific */ std::string TemperatureEvent(int action); - std::string AutoComparatorDisable(int action); /* Gotthard Specific */ std::string ROI(int action); std::string ClearROI(int action); @@ -1837,6 +1837,24 @@ class CmdProxy { "to be less than threshold temperature and temperature event has to be " "cleared."); + INTEGER_COMMAND_VEC_ID( + auto_comp_disable, getAutoCompDisable, setAutoCompDisable, + StringTo, + "[0, 1]\n\t[Jungfrau] Auto comparator disable mode. By default, the " + "on-chip gain switching is active during the entire exposure.This mode " + "disables the on - chip gain switching comparator automatically after " + "93.75% (only for chipv1.0) of exposure time (only for longer than " + "100us). It is possible to set the duration for chipv1.1 using " + "comp_disable_time command.\n\tDefault is 0 or this mode " + "disabled(comparator enabled throughout). 1 enables mode. 0 disables " + "mode. "); + + TIME_COMMAND(comp_disable_time, getComparatorDisableTime, + setComparatorDisableTime, + "[duration] [(optional unit) ns|us|ms|s]\n\t[Jungfrau] Time " + "before end of exposure when comparator is disabled. It is " + "only possible for chipv1.1."); + INTEGER_COMMAND_SET_NOID_GET_ID( storagecells, getNumberOfAdditionalStorageCells, setNumberOfAdditionalStorageCells, StringTo, diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index ea889fff2..cd89fec41 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -1459,6 +1459,14 @@ void Detector::setAutoCompDisable(bool value, Positions pos) { pimpl->Parallel(&Module::setAutoComparatorDisableMode, pos, value); } +Result Detector::getComparatorDisableTime(Positions pos) const { + return pimpl->Parallel(&Module::getComparatorDisableTime, pos); +} + +void Detector::setComparatorDisableTime(ns t, Positions pos) { + pimpl->Parallel(&Module::setComparatorDisableTime, pos, t.count()); +} + Result Detector::getNumberOfAdditionalStorageCells(Positions pos) const { return pimpl->Parallel(&Module::getNumberOfAdditionalStorageCells, pos); } diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index ac9ecc212..cac7590ea 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -1577,6 +1577,14 @@ void Module::setAutoComparatorDisableMode(bool val) { sendToDetector(F_AUTO_COMP_DISABLE, static_cast(val)); } +int64_t Module::getComparatorDisableTime() const { + return sendToDetector(F_GET_COMP_DISABLE_TIME); +} + +void Module::setComparatorDisableTime(int64_t value) { + sendToDetector(F_SET_COMP_DISABLE_TIME, value, nullptr); +} + int Module::getNumberOfAdditionalStorageCells() const { return sendToDetector(F_GET_NUM_ADDITIONAL_STORAGE_CELLS); } diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index d7f75fef3..6855d91b5 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -363,6 +363,8 @@ class Module : public virtual slsDetectorDefs { void resetTemperatureEvent(); bool getAutoComparatorDisableMode() const; void setAutoComparatorDisableMode(bool val); + int64_t getComparatorDisableTime() const; + void setComparatorDisableTime(int64_t value); int getNumberOfAdditionalStorageCells() const; void setNumberOfAdditionalStorageCells(int value); int getStorageCellStart() const; diff --git a/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp b/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp index f894e4105..9a540f3a5 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp @@ -283,6 +283,36 @@ TEST_CASE("auto_comp_disable", "[.cmd]") { } } +TEST_CASE("comp_disable_time", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::JUNGFRAU) { + auto prev_val = det.getComparatorDisableTime(); + { + std::ostringstream oss; + proxy.Call("comp_disable_time", {"125ns"}, -1, PUT, oss); + REQUIRE(oss.str() == "comp_disable_time 125ns\n"); + } + { + std::ostringstream oss; + proxy.Call("comp_disable_time", {}, -1, GET, oss); + REQUIRE(oss.str() == "comp_disable_time 125ns\n"); + } + { + std::ostringstream oss; + proxy.Call("comp_disable_time", {"0"}, -1, PUT, oss); + REQUIRE(oss.str() == "comp_disable_time 0\n"); + } + for (int i = 0; i != det.size(); ++i) { + det.setComparatorDisableTime(prev_val[i], {i}); + } + } else { + REQUIRE_THROWS(proxy.Call("comp_disable_time", {}, -1, GET)); + REQUIRE_THROWS(proxy.Call("comp_disable_time", {"0"}, -1, PUT)); + } +} + TEST_CASE("storagecells", "[.cmd]") { Detector det; CmdProxy proxy(&det); diff --git a/slsSupportLib/include/sls/sls_detector_funcs.h b/slsSupportLib/include/sls/sls_detector_funcs.h index 0a955cec0..952843f21 100755 --- a/slsSupportLib/include/sls/sls_detector_funcs.h +++ b/slsSupportLib/include/sls/sls_detector_funcs.h @@ -235,6 +235,8 @@ enum detFuncs { F_SET_DEFAULT_DAC, F_GET_GAIN_MODE, F_SET_GAIN_MODE, + F_GET_COMP_DISABLE_TIME, + F_SET_COMP_DISABLE_TIME, NUM_DET_FUNCTIONS, RECEIVER_ENUM_START = 256, /**< detector function should not exceed this @@ -576,6 +578,8 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_SET_DEFAULT_DAC: return "F_SET_DEFAULT_DAC"; case F_GET_GAIN_MODE: return "F_GET_GAIN_MODE"; case F_SET_GAIN_MODE: return "F_SET_GAIN_MODE"; + case F_GET_COMP_DISABLE_TIME: return "F_GET_COMP_DISABLE_TIME"; + case F_SET_COMP_DISABLE_TIME: return "F_SET_COMP_DISABLE_TIME"; case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START";