diff --git a/slsDetectorServers/mythen3DetectorServer/RegisterDefs.h b/slsDetectorServers/mythen3DetectorServer/RegisterDefs.h index 4cd7ddc9f..847d396e6 100644 --- a/slsDetectorServers/mythen3DetectorServer/RegisterDefs.h +++ b/slsDetectorServers/mythen3DetectorServer/RegisterDefs.h @@ -132,7 +132,7 @@ #define CONTROL_STP_ACQSTN_MSK (0x00000001 << CONTROL_STP_ACQSTN_OFST) #define CONTROL_STRT_PATTERN_OFST (2) #define CONTROL_STRT_PATTERN_MSK (0x00000001 << CONTROL_STRT_PATTERN_OFST) -#define CONTROL_STRT_READOUT_OFST (3) // not connected in software yet +#define CONTROL_STRT_READOUT_OFST (3) #define CONTROL_STRT_READOUT_MSK (0x00000001 << CONTROL_STRT_READOUT_OFST) #define CONTROL_STRT_SW_TRIGGER_OFST (4) #define CONTROL_STRT_SW_TRIGGER_MSK (0x00000001 << CONTROL_STRT_SW_TRIGGER_OFST) diff --git a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer index fedf3ee7f..7e66b07c4 100755 Binary files a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer and b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer differ diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index c2644a1eb..0e89c7811 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -2407,6 +2407,22 @@ int softwareTrigger() { return OK; } +int startReadOut() { + LOG(logINFOBLUE, ("Starting Readout\n")); +#ifdef VIRTUAL + // cannot set #frames and exptiem temporarily to 1 and 0, + // because have to set it back after readout (but this is non blocking) + return startStateMachine(); +#endif + cleanFifos(); + + // start readout + bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_STRT_READOUT_MSK); + + LOG(logINFO, ("Status Register: %08x\n", bus_r(STATUS_REG))); + return OK; +} + enum runStatus getRunStatus() { LOG(logDEBUG1, ("Getting status\n")); // scan error or running diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index e2b0b3b67..c63064d9f 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -567,8 +567,7 @@ int stopStateMachine(); #if defined(EIGERD) || defined(MYTHEN3D) int softwareTrigger(); #endif - -#ifdef EIGERD +#if defined(EIGERD) || defined(MYTHEN3D) int startReadOut(); #endif enum runStatus getRunStatus(); diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h index 9bccf5a23..a445323ee 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h @@ -239,4 +239,5 @@ int get_bad_channels(int); int set_bad_channels(int); int reconfigure_udp(int); int validate_udp_configuration(int); -int get_bursts_left(int); \ No newline at end of file +int get_bursts_left(int); +int start_readout(int); \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 436084fa1..3a39ad220 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -358,6 +358,7 @@ void function_table() { flist[F_RECONFIGURE_UDP] = &reconfigure_udp; flist[F_VALIDATE_UDP_CONFIG] = &validate_udp_configuration; flist[F_GET_BURSTS_LEFT] = &get_bursts_left; + flist[F_START_READOUT] = &start_readout; // check if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { @@ -8103,4 +8104,44 @@ int get_bursts_left(int file_des) { LOG(logDEBUG1, ("retval num bursts left %lld\n", (long long int)retval)); #endif return Server_SendResult(file_des, INT64, &retval, sizeof(retval)); -} \ No newline at end of file +} + +int start_readout(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); +#ifndef MYTHEN3D + functionNotImplemented(); +#else + if (Server_VerifyLock() == OK) { + enum runStatus s = getRunStatus(); + if (s == RUNNING || s == WAITING) { + ret = FAIL; + strcpy(mess, "Could not start readout because the detector is " + "already running!\n"); + LOG(logERROR, (mess)); + } else if (configured == FAIL) { + ret = FAIL; + strcpy(mess, "Could not start readout because "); + strcat(mess, configureMessage); + LOG(logERROR, (mess)); + } else { + memset(scanErrMessage, 0, MAX_STR_LENGTH); + sharedMemory_setScanStop(0); + sharedMemory_setScanStatus(IDLE); // if it was error + // start readout + ret = startReadOut(); + if (ret == FAIL) { +#ifdef VIRTUAL + sprintf(mess, + "Could not start readout. Could not create udp " + "socket in server. Check udp_dstip & udp_dstport.\n"); +#else + sprintf(mess, "Could not start readout\n"); +#endif + LOG(logERROR, (mess)); + } + } + } +#endif + return Server_SendResult(file_des, INT32, NULL, 0); +} diff --git a/slsDetectorSoftware/include/Detector.h b/slsDetectorSoftware/include/Detector.h index b91bc058e..0947733d2 100644 --- a/slsDetectorSoftware/include/Detector.h +++ b/slsDetectorSoftware/include/Detector.h @@ -456,6 +456,11 @@ class Detector { * WAITING and automatically returns to idle at the end of acquisition. */ void startDetector(); + /** [Mythen3] Non blocking: start detector readout of counters in chip. + * Status changes to TRANSMITTING and automatically returns to idle at the + * end of readout. */ + void startDetectorReadout(); + /** Non blocking: Abort detector acquisition. Status changes to IDLE or * STOPPED. Goes to stop server. */ void stopDetector(); diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index daaf7588f..4df0a4c98 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -835,6 +835,7 @@ class CmdProxy { {"rx_start", &CmdProxy::rx_start}, {"rx_stop", &CmdProxy::rx_stop}, {"start", &CmdProxy::start}, + {"readout", &CmdProxy::readout}, {"stop", &CmdProxy::stop}, {"rx_status", &CmdProxy::ReceiverStatus}, {"status", &CmdProxy::DetectorStatus}, @@ -1429,7 +1430,14 @@ class CmdProxy { EXECUTE_SET_COMMAND_NOID( start, startDetector, "\n\tStarts detector acquisition. Status changes to RUNNING or WAITING " - "and automatically returns to idle at the end of acquisition."); + "and automatically returns to idle at the end of acquisition. If the " + "acquisition was abruptly stopped, some detectors come back to " + "STOPPED."); + + EXECUTE_SET_COMMAND_NOID( + readout, startDetectorReadout, + "\n\t[Mythen3] Starts detector readout. Status changes to TRANSMITTING " + "and automatically returns to idle at the end of readout."); EXECUTE_SET_COMMAND_NOID(stop, stopDetector, "\n\tAbort detector acquisition. Status changes " diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 296293cd4..2186531b2 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -593,6 +593,10 @@ void Detector::startDetector() { pimpl->Parallel(&Module::startAcquisition, {}); } +void Detector::startDetectorReadout() { + pimpl->Parallel(&Module::startReadout, {}); +} + void Detector::stopDetector() { pimpl->Parallel(&Module::stopAcquisition, {}); } Result Detector::getDetectorStatus(Positions pos) const { diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 82bc848fb..a856fe145 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -407,6 +407,11 @@ void Module::startAcquisition() { sendToDetector(F_START_ACQUISITION); } +void Module::startReadout() { + shm()->stoppedFlag = false; + sendToDetector(F_START_READOUT); +} + void Module::stopAcquisition() { // get status before stopping acquisition runStatus s = ERROR, r = ERROR; diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index 2d8ae07af..f9f808750 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -160,6 +160,7 @@ class Module : public virtual slsDetectorDefs { void startReceiver(); void stopReceiver(); void startAcquisition(); + void startReadout(); void stopAcquisition(); void restreamStopFromReceiver(); void startAndReadAll(); diff --git a/slsDetectorSoftware/tests/test-CmdProxy-mythen3.cpp b/slsDetectorSoftware/tests/test-CmdProxy-mythen3.cpp index 8f10e628d..e63417664 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-mythen3.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-mythen3.cpp @@ -115,6 +115,23 @@ TEST_CASE("Setting and reading back MYTHEN3 dacs", "[.cmd][.dacs][.new]") { } } +/* acquisition */ + +TEST_CASE("readout", "[.cmd][.new]") { + Detector det; + CmdProxy proxy(&det); + // PUT only command + REQUIRE_THROWS(proxy.Call("readout", {}, -1, GET)); + auto det_type = det.getDetectorType().squash(); + if (det_type != defs::MYTHEN3) { + REQUIRE_THROWS(proxy.Call("readout", {}, -1, GET)); + } else { + std::ostringstream oss; + proxy.Call("readout", {}, -1, PUT, oss); + REQUIRE(oss.str() == "readout successful\n"); + } +} + /* Mythen3 Specific */ TEST_CASE("counters", "[.cmd][.new]") { diff --git a/slsSupportLib/include/sls_detector_funcs.h b/slsSupportLib/include/sls_detector_funcs.h index 3d38dccf1..bda81ab11 100755 --- a/slsSupportLib/include/sls_detector_funcs.h +++ b/slsSupportLib/include/sls_detector_funcs.h @@ -214,6 +214,7 @@ enum detFuncs { F_RECONFIGURE_UDP, F_VALIDATE_UDP_CONFIG, F_GET_BURSTS_LEFT, + F_START_READOUT, NUM_DET_FUNCTIONS, RECEIVER_ENUM_START = 256, /**< detector function should not exceed this @@ -533,6 +534,7 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_RECONFIGURE_UDP: return "F_RECONFIGURE_UDP"; case F_VALIDATE_UDP_CONFIG: return "F_VALIDATE_UDP_CONFIG"; case F_GET_BURSTS_LEFT: return "F_GET_BURSTS_LEFT"; + case F_START_READOUT: return "F_START_READOUT"; case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START"; diff --git a/slsSupportLib/include/versionAPI.h b/slsSupportLib/include/versionAPI.h index ced7db62a..ed09b5851 100644 --- a/slsSupportLib/include/versionAPI.h +++ b/slsSupportLib/include/versionAPI.h @@ -9,4 +9,4 @@ #define APIGOTTHARD2 0x201016 #define APIJUNGFRAU 0x201016 #define APIMOENCH 0x201013 -#define APIMYTHEN3 0x201020 +#define APIMYTHEN3 0x201026