Merge pull request #7 from hinxx/init-no-segfault

Do not segfault if camera initialization fails in constructor.

I am merging this pull request.  Note that I have merged a previous pull request for EMGain support #6 into master.  The RELEASE.md file for R2-5 is now:
R2-5 (July XXX, 2016)
----
* Added support for Electron Multiplying (EM) Gain.  Thanks to Mike Dunning for this.
* Add ability to set the BaselineClamp in the Andor SDK.  Thanks to Matt Pearson for this.
* Enforce minimum values of ADShutterOpenDelay and ADShutterCloseDelay based on query of SDK.
* Fix bug when setting MinX and MinY with binning.  There was an incorrect factor of 2 present.
  Thanks to Hinko Kocevar for this fix.

@hinxx you will need to update your master because of the previous merges.
This commit is contained in:
Mark Rivers
2016-07-13 07:34:04 -05:00
committed by GitHub
2 changed files with 31 additions and 18 deletions

View File

@@ -110,7 +110,7 @@ AndorCCD::AndorCCD(const char *portName, const char *installPath, int shamrockID
: ADDriver(portName, 1, NUM_ANDOR_DET_PARAMS, maxBuffers, maxMemory,
asynEnumMask, asynEnumMask,
ASYN_CANBLOCK, 1, priority, stackSize),
mExiting(false), mShamrockId(shamrockID), mSPEDoc(0)
mExiting(false), mShamrockId(shamrockID), mSPEDoc(0), mInitOK(false)
{
int status = asynSuccess;
@@ -156,6 +156,18 @@ AndorCCD::AndorCCD(const char *portName, const char *installPath, int shamrockID
return;
}
// Initialize ADC enums
for (i=0; i<MAX_ADC_SPEEDS; i++) {
mADCSpeeds[i].EnumValue = i;
mADCSpeeds[i].EnumString = (char *)calloc(MAX_ENUM_STRING_SIZE, sizeof(char));
}
// Initialize Pre-Amp enums
for (i=0; i<MAX_PREAMP_GAINS; i++) {
mPreAmpGains[i].EnumValue = i;
mPreAmpGains[i].EnumString = (char *)calloc(MAX_ENUM_STRING_SIZE, sizeof(char));
}
// Initialize camera
try {
printf("%s:%s: initializing camera\n",
@@ -177,18 +189,6 @@ AndorCCD::AndorCCD(const char *portName, const char *installPath, int shamrockID
return;
}
// Initialize ADC enums
for (i=0; i<MAX_ADC_SPEEDS; i++) {
mADCSpeeds[i].EnumValue = i;
mADCSpeeds[i].EnumString = (char *)calloc(MAX_ENUM_STRING_SIZE, sizeof(char));
}
// Initialize Pre-Amp enums
for (i=0; i<MAX_PREAMP_GAINS; i++) {
mPreAmpGains[i].EnumValue = i;
mPreAmpGains[i].EnumString = (char *)calloc(MAX_ENUM_STRING_SIZE, sizeof(char));
}
/* Set some default values for parameters */
status = setStringParam(ADManufacturer, "Andor");
@@ -273,6 +273,7 @@ AndorCCD::AndorCCD(const char *portName, const char *installPath, int shamrockID
return;
}
printf("CCD initialized OK!\n");
mInitOK = true;
}
/**
@@ -723,6 +724,7 @@ asynStatus AndorCCD::setupShutter(int command)
int openTime, closeTime;
int shutterExTTL;
int shutterMode;
AndorCapabilities capabilities;
asynStatus status=asynSuccess;
static const char *functionName = "setupShutter";
@@ -755,11 +757,14 @@ asynStatus AndorCCD::setupShutter(int command)
}
try {
asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW,
"%s:%s:, SetShutter(%d,%d,%d,%d)\n",
driverName, functionName, shutterExTTL, shutterMode, closeTime, openTime);
checkStatus(SetShutter(shutterExTTL, shutterMode, closeTime, openTime));
capabilities.ulSize = sizeof(capabilities);
checkStatus(GetCapabilities(&capabilities));
if (capabilities.ulFeatures & AC_FEATURES_SHUTTER) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW,
"%s:%s:, SetShutter(%d,%d,%d,%d)\n",
driverName, functionName, shutterExTTL, shutterMode, closeTime, openTime);
checkStatus(SetShutter(shutterExTTL, shutterMode, closeTime, openTime));
}
} catch (const std::string &e) {
asynPrint(pasynUserSelf, ASYN_TRACE_ERROR,
"%s:%s: %s\n",
@@ -851,6 +856,8 @@ unsigned int AndorCCD::checkStatus(unsigned int returnStatus)
throw std::string("ERROR: Problem communicating with camera.");
} else if (returnStatus == DRV_LOAD_FIRMWARE_ERROR) {
throw std::string("ERROR: Error loading firmware.");
} else if (returnStatus == DRV_NOT_SUPPORTED) {
throw std::string("ERROR: Feature not supported.");
} else {
sprintf(message, "ERROR: Unknown error code=%d returned from Andor SDK.", returnStatus);
throw std::string(message);
@@ -978,6 +985,10 @@ asynStatus AndorCCD::setupAcquisition()
AndorADCSpeed_t *pSpeed;
static const char *functionName = "setupAcquisition";
if (!mInitOK) {
return asynDisabled;
}
getIntegerParam(ADImageMode, &imageMode);
getIntegerParam(ADNumExposures, &numExposures);
if (numExposures <= 0) {

View File

@@ -209,6 +209,8 @@ class AndorCCD : public ADDriver {
tagCSMAHEAD *mSPEHeader;
TiXmlDocument *mSPEDoc;
// Camera init status
bool mInitOK;
};
#define NUM_ANDOR_DET_PARAMS ((int)(&LAST_ANDOR_PARAM - &FIRST_ANDOR_PARAM + 1))