From d2320b8b762473cb5be713eae833b94fdcef50e2 Mon Sep 17 00:00:00 2001 From: Benjamin Bradnick Date: Fri, 21 Feb 2020 09:03:40 +0000 Subject: [PATCH] Acquisition setup and start now occur in writeInt32 --- andorApp/src/andorCCD.cpp | 84 +++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/andorApp/src/andorCCD.cpp b/andorApp/src/andorCCD.cpp index 495f9a9..90eb271 100755 --- a/andorApp/src/andorCCD.cpp +++ b/andorApp/src/andorCCD.cpp @@ -311,9 +311,9 @@ AndorCCD::AndorCCD(const char *portName, const char *installPath, int cameraSeri return; } - //Define the polling periods for the status thread. - mPollingPeriod = 0.2; //seconds - mFastPollingPeriod = 0.05; //seconds + // Define the polling periods for the status thread. + mPollingPeriod = 0.2; // seconds + mFastPollingPeriod = 0.05; // seconds mAcquiringData = 0; @@ -627,7 +627,7 @@ asynStatus AndorCCD::writeInt32(asynUser *pasynUser, epicsInt32 value) asynStatus status = asynSuccess; static const char *functionName = "writeInt32"; - //Set in param lib so the user sees a readback straight away. Save a backup in case of errors. + // Set in param lib so the user sees a readback straight away. Save a backup in case of errors. getIntegerParam(function, &oldValue); status = setIntegerParam(function, value); @@ -635,13 +635,28 @@ asynStatus AndorCCD::writeInt32(asynUser *pasynUser, epicsInt32 value) getIntegerParam(ADStatus, &adstatus); if (value && (adstatus == ADStatusIdle)) { try { + // Set up acquisition mAcquiringData = 1; - //We send an event at the bottom of this function. + status = setupAcquisition(); + if (status != asynSuccess) throw std::string("Setup acquisition failed"); + // Open the shutter if we control it + int adShutterMode; + getIntegerParam(ADShutterMode, &adShutterMode); + if (adShutterMode == ADShutterModeEPICS) { + ADDriver::setShutter(ADShutterOpen); + } + // Start acquisition + asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, + "%s:%s:, StartAcquisition()\n", + driverName, functionName); + checkStatus(StartAcquisition()); + // Reset the counters + setIntegerParam(ADNumImagesCounter, 0); + setIntegerParam(ADNumExposuresCounter, 0); } catch (const std::string &e) { asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s: %s\n", driverName, functionName, e.c_str()); - status = asynError; } } if (!value && (adstatus != ADStatusIdle)) { @@ -724,7 +739,7 @@ asynStatus AndorCCD::writeInt32(asynUser *pasynUser, epicsInt32 value) status = ADDriver::writeInt32(pasynUser, value); } - //For a successful write, clear the error message. + // For a successful write, clear the error message. setStringParam(AndorMessage, " "); /* Do callbacks so higher layers see any changes */ @@ -737,7 +752,7 @@ asynStatus AndorCCD::writeInt32(asynUser *pasynUser, epicsInt32 value) asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s:, Sending dataEvent to dataTask ...\n", driverName, functionName); - //Also signal the data readout thread + // Also signal the data readout thread epicsEventSignal(dataEvent); } @@ -816,7 +831,7 @@ asynStatus AndorCCD::writeFloat64(asynUser *pasynUser, epicsFloat64 value) status = ADDriver::writeFloat64(pasynUser, value); } - //For a successful write, clear the error message. + // For a successful write, clear the error message. setStringParam(AndorMessage, " "); /* Do callbacks so higher layers see any changes */ @@ -1063,7 +1078,7 @@ void AndorCCD::statusTask(void) printf("%s:%s: Status thread started...\n", driverName, functionName); while(!mExiting) { - //Read timeout for polling freq. + // Read timeout for polling freq. this->lock(); if (forcedFastPolls > 0) { timeout = mFastPollingPeriod; @@ -1082,10 +1097,10 @@ void AndorCCD::statusTask(void) asynPrint(pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: Got status event\n", driverName, functionName); - //We got an event, rather than a timeout. This is because other software - //knows that data has arrived, or device should have changed state (parameters changed, etc.). - //Force a minimum number of fast polls, because the device status - //might not have changed in the first few polls + // We got an event, rather than a timeout. This is because other software + // knows that data has arrived, or device should have changed state (parameters changed, etc.). + // Force a minimum number of fast polls, because the device status + // might not have changed in the first few polls forcedFastPolls = 5; } @@ -1093,17 +1108,17 @@ void AndorCCD::statusTask(void) this->lock(); try { - //Only read these if we are not acquiring data + // Only read these if we are not acquiring data if (!mAcquiringData) { - //Read cooler status + // Read cooler status checkStatus(IsCoolerOn(&value)); status = setIntegerParam(AndorCoolerParam, value); - //Read temperature of CCD + // Read temperature of CCD checkStatus(GetTemperatureF(&temperature)); status = setDoubleParam(ADTemperatureActual, temperature); } - //Read detector status (idle, acquiring, error, etc.) + // Read detector status (idle, acquiring, error, etc.) checkStatus(GetStatus(&value)); uvalue = static_cast(value); if (uvalue == ASIdle) { @@ -1142,7 +1157,7 @@ void AndorCCD::statusTask(void) callParamCallbacks(); this->unlock(); - } //End of loop + } // End of loop asynPrint(pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: Status thread exiting ...\n", driverName, functionName); @@ -1502,39 +1517,21 @@ void AndorCCD::dataTask(void) // Sanity check that main thread thinks we are acquiring data if (mAcquiringData) { - try { - status = setupAcquisition(); - if (status != asynSuccess) continue; - getIntegerParam(ADShutterMode, &adShutterMode); - getIntegerParam(AndorReadOutMode, &readOutMode); - if (adShutterMode == ADShutterModeEPICS) { - ADDriver::setShutter(ADShutterOpen); - } - asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, - "%s:%s:, StartAcquisition()\n", - driverName, functionName); - checkStatus(StartAcquisition()); - acquiring = 1; - } catch (const std::string &e) { - asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, - "%s:%s: %s\n", - driverName, functionName, e.c_str()); - continue; - } // Read some parameters + getIntegerParam(ADShutterMode, &adShutterMode); + getIntegerParam(AndorReadOutMode, &readOutMode); getIntegerParam(NDDataType, &itemp); dataType = (NDDataType_t)itemp; getIntegerParam(NDAutoSave, &autoSave); getIntegerParam(NDArrayCallbacks, &arrayCallbacks); getIntegerParam(NDArraySizeX, &sizeX); getIntegerParam(NDArraySizeY, &sizeY); - // Reset the counters - setIntegerParam(ADNumImagesCounter, 0); - setIntegerParam(ADNumExposuresCounter, 0); - callParamCallbacks(); + // Set acquiring to 1 + acquiring = 1; } else { asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s:, Data thread is running but main thread thinks we are not acquiring.\n", driverName, functionName); + // Set acquiring to 0 acquiring = 0; } @@ -1633,7 +1630,8 @@ void AndorCCD::dataTask(void) } } } - + + // Close the shutter if we are controlling it if (adShutterMode == ADShutterModeEPICS) { ADDriver::setShutter(ADShutterClosed); }