void init_clara() { at_32 n,handle; C(GetAvailableCameras(&n)); C(GetCameraHandle(n-1,&handle)); C(SetCurrentCamera(handle)); C(Initialize("/usr/local/etc/andor")); // C(SetTriggerMode(1 /*external*/)); C(SetTriggerMode(0 /*internal*/)); C(SetExposureTime(.001)); C(SetReadMode(4 /*image*/)); C(SetAcquisitionMode(1 /*single scan*/)); C(CoolerON()); C(SetADChannel(1 /*fast*/)); C(SetFastExtTrigger(1)); C(SetFrameTransferMode(1)); int h=512, w=512; clara_h=h; clara_w=w; //C(SetIsolatedCropMode(1,h,w,1,1)); C(SetImage(1,1,1,w,1,h)); C(GetSizeOfCircularBuffer(&clara_circ_buf_size)); clara_buf=malloc(sizeof(*clara_buf)* h*w*clara_circ_buf_size); if(!clara_buf) printf("can't allocate memory for pictures\n"); //C(SetAcquisitionMode(5 /*run till abort*/)); C(SetTemperature(-15)); }
QScopeSubscriber::QScopeSubscriber(BLooper *looper) : BSubscriber("QScope") { TriggerRightChannel = false; TriggerSlopeNeg = false; TriggerLevel = 0; SetTimePerDiv(2E-3); the_looper = looper; the_stream = NULL; state = STATE_RECORD; active_buf = 0; scope_counter = 0; record_counter = 0; next_frame = 0.0; old_input = 0; left_min = right_min = 32767; left_max = right_max = left_peak = right_peak = -32768; hold_off_counter = 0; SetHoldOff(0); trigger_start_frame = 0; trigger_total_frames = 0; SetTriggerMode(TRIGGER_LEVEL); }
int trigger_setup(TriggerMode tMode, TriggerSource tSource, double trigLevel) { rs = SetTriggerMode(tMode); ReturnCheck(rs); rs = SetTriggerSource(tSource); ReturnCheck(rs); rs = SetIFPowerTriggerLevel(trigLevel); ReturnCheck(rs); return 0; }
int main(int argc, char *argv[]) { int adcChannel=1, minX=0, minY=0, binX=1, binY=1, sizeX=1024, sizeY=1024; int triggerMode=0, numExposures=2, numImages=3; float mAcquireTime=0.1f, mAccumulatePeriod=1.0f, mAcquirePeriod=4.0f; float acquireTimeAct, accumulatePeriodAct, acquirePeriodAct; int AAKinetics=3, ATInternal=0; time_t startTime, endTime; int acquireStatus; checkStatus(Initialize("/usr/local/etc/andor")); printf("SetTriggerMode(%d)\n", triggerMode); checkStatus(SetTriggerMode(ATInternal)); printf("SetADChannel(%d)\n", adcChannel); checkStatus(SetADChannel(adcChannel)); //Set fastest HS speed. printf("SetHSSpeed(0, 0)\n"); checkStatus(SetHSSpeed(0, 0)); printf("SetImage(%d,%d,%d,%d,%d,%d)\n", binX, binY, minX+1, minX+sizeX, minY+1, minY+sizeY); checkStatus(SetImage(binX, binY, minX+1, minX+sizeX, minY+1, minY+sizeY)); printf("SetExposureTime(%f)\n", mAcquireTime); checkStatus(SetExposureTime(mAcquireTime)); printf("SetAcquisitionMode(AAKinetics)\n"); checkStatus(SetAcquisitionMode(AAKinetics)); printf("SetNumberAccumulations(%d)\n", numExposures); checkStatus(SetNumberAccumulations(numExposures)); printf("SetAccumulationCycleTime(%f)\n", mAccumulatePeriod); checkStatus(SetAccumulationCycleTime(mAccumulatePeriod)); printf("SetNumberKinetics(%d)\n", numImages); checkStatus(SetNumberKinetics(numImages)); printf("SetKineticCycleTime(%f)\n", mAcquirePeriod); checkStatus(SetKineticCycleTime(mAcquirePeriod)); checkStatus(GetAcquisitionTimings(&acquireTimeAct, &accumulatePeriodAct, &acquirePeriodAct)); printf("GetAcquisitionTimings(exposure=%f, accumulate=%f, kinetic=%f)\n", acquireTimeAct, accumulatePeriodAct, acquirePeriodAct); time(&startTime); printf("StartAcquisition()\n"); checkStatus(StartAcquisition()); while (1) { printf("GetStatus()\n"); checkStatus(GetStatus(&acquireStatus)); if (acquireStatus != DRV_ACQUIRING) break; printf("WaitForAcquisition()\n"); checkStatus(WaitForAcquisition()); time(&endTime); printf("Time since start=%f\n", difftime(endTime, startTime)); } return 0; }
void ANDOR885_Camera::setTriggerMode(int mode) throw(std::exception) { int errorValue; // Kinetic series can only be used with external acquisition modes if (mode == TRIGGERMODE_INTERNAL && acquisitionMode == ACQMODE_KINETIC_SERIES) { setAcquisitionMode(ACQMODE_RUN_TILL_ABORT); } errorValue = SetTriggerMode(mode); throwError(errorValue, "Error in setting Trigger Mode"); triggerMode = mode; }
// The entry point for mex void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[]) { /* Check for proper number of input and output arguments */ if (nrhs > 0) { mexErrMsgIdAndTxt( "Mscope:initialiseCamera:invalidNumInputs", "Too many input arguments"); } if (nlhs > 1) { mexErrMsgIdAndTxt( "Mscope:initialiseCamera:maxlhs", "Too many output arguments."); } /* ARRAY FOR STATUS CODES */ unsigned int ac; /* SETUP THE CAMERA */ ac = SetTriggerMode(0); /*CHECK THEY WENT OK */ UINT32_T andorCode32 = (UINT32_T) ac; /* RETURNING THE STATUS CODE */ // define an array of mwSignedIndex called dims (which is our output array dimensions) mwSignedIndex dims[2] = {1,1}; // set the first element of the array plhs to be a mxArray pointer returned by mxCreateNumericArray // the parameters we pass fully describe the memory footprint of this array plhs[0] = mxCreateNumericArray(1, dims, mxUINT32_CLASS, mxREAL); // get a pointer to the data in the mxArray pointed at by plhs[0] double * codePtr = mxGetPr(plhs[0]); // copy the memory from the address of our status code to the location pointed to by outDataPtr memcpy(codePtr, &andorCode32, sizeof(andorCode32)); return; }
//------------------------------------------------------------------------------ // FUNCTION NAME: InitializeCamera() // // RETURNS: If the function terminates before entering the message loop, // return FALSE. // Otherwise, return the WPARAM value sent by the WM_QUIT // message. // // LAST MODIFIED: PMcK 11/11/98 // // DESCRIPTION: calls initialization function, processes message loop // // Windows recognizes this function by name as the initial // entry point for the program. This function calls the // application initialization routine, if no other instance of // the program is running, and always calls the instance // initialization routine. It then executes a message // retrieval and dispatch loop that is the top-level control // structure for the remainder of execution. The loop is // terminated when a WM_QUIT message is received, at which // time this function exits the application instance by // returning the value passed by PostQuitMessage(). // // If the function must abort before entering the message loop, // it returns the conventional value NULL. // // // ARGUMENTS: hInstance - The handle to the instance of this application // that is currently being executed. // // hPrevInstance - The handle to the instance of this // application that was last executed. If this is the only // instance of this application executing, hPrevInstance is // NULL. In Win32 applications, this parameter is always NULL. // // lpCmdLine - A pointer to a null terminated string specifying // the command line of the application. // // nCmdShow - Specifies how the main window is to be diplayed. //------------------------------------------------------------------------------ bool ANDOR885_Camera::InitializeCamera() { AndorCapabilities caps; char aBuffer[256]; int errorValue; bool errorFlag = false; // int test,test2; //need to pause while camera initializes float speed, STemp, gain; int iSpeed, nAD, nAmp, nPreAmp, index, IsPreAmpAvailable; int i; caps.ulSize = sizeof(AndorCapabilities); long numCameras; GetAvailableCameras(&numCameras); GetCurrentDirectoryA(256,aBuffer);// Look in current working directory // for driver files. Note: had to override usual mapping of GetCurrentDirectory to // GetCurrentDirectoryW because of mismatch of argument types. errorValue=Initialize(aBuffer); // Initialize driver in current directory printError(errorValue, "Initialize error", &errorFlag, ANDOR_ERROR); if (errorFlag) return true; // Get camera capabilities errorValue=GetCapabilities(&caps); printError(errorValue, "Get Andor Capabilities information Error", &errorFlag, ANDOR_ERROR); // Get Head Model errorValue=GetHeadModel(model); printError(errorValue, "Get Head Model information Error", &errorFlag, ANDOR_ERROR); // Get detector information errorValue=GetDetector(&imageWidth,&imageHeight); printError(errorValue, "Get Detector information Error", &errorFlag, ANDOR_ERROR); // Set frame transfer mode errorValue=SetFrameTransferMode((frameTransfer == ANDOR_ON) ? 1 : 0); printError(errorValue, "Set Frame Transfer Mode Error", &errorFlag, ANDOR_ERROR); // Set acquisition mode to required setting specified in xxxxWndw.c errorValue=SetAcquisitionMode(acquisitionMode); printError(errorValue, "Set Acquisition Mode Error", &errorFlag, ANDOR_ERROR); if(caps.ulGetFunctions > 32) { GetEMCCDGain(&EMCCDGain); } if(readMode == READMODE_IMAGE) { // This function only needs to be called when acquiring an image. It sets // the horizontal and vertical binning and the area of the image to be // captured. In this example it is set to 1x1 binning and is acquiring the // whole image SetImage(1,1,1,imageWidth,1,imageHeight); } // Set read mode to required setting specified in xxxxWndw.c errorValue=SetReadMode(readMode); printError(errorValue, "Set Read Mode Error", &errorFlag, ANDOR_ERROR); // Set Vertical speed to max /* STemp = 0; VSnumber = 0; GetNumberVSSpeeds(&index); for(iSpeed=0; iSpeed<index; iSpeed++){ GetVSSpeed(iSpeed, &speed); if(speed > STemp){ STemp = speed; VSnumber = iSpeed; } } errorValue=SetVSSpeed(VSnumber); printError(errorValue, "Set Vertical Speed Error", &errorFlag, ANDOR_ERROR); */ if (!notDestructed){ STemp = 0; GetNumberVSSpeeds(&index); for(iSpeed=0; iSpeed < index; iSpeed++){ GetVSSpeed(iSpeed, &speed); verticalShiftSpeed_t.choices[iSpeed] = STI::Utils::valueToString(speed); if(speed > STemp){ STemp = speed; verticalShiftSpeed = iSpeed; } } verticalShiftSpeed_t.initial = (--verticalShiftSpeed_t.choices.end())->second; } errorValue = SetVSSpeed(verticalShiftSpeed); printError(errorValue, "Set Vertical Speed Error", &errorFlag, ANDOR_ERROR); /* Set Vertical Clock Voltage; note: only the fastest vertical shift speeds will benefit from the higher clock voltage; increasing clock voltage adds noise. */ if (!notDestructed) { index = 0; errorValue = GetNumberVSAmplitudes(&index); if (errorValue == DRV_SUCCESS) { for (i = 0; i < index; i++){ if (i == 0){ verticalClockVoltage_t.choices[i] = "Normal"; } else { verticalClockVoltage_t.choices[i] = STI::Utils::valueToString(i); } } verticalClockVoltage_t.initial = (verticalClockVoltage_t.choices.begin())->second; } } errorValue = SetVSAmplitude(0); printError(errorValue, "Set Vertical Clock Voltage Error", &errorFlag, ANDOR_ERROR); // Set Horizontal Speed to max and check bit depth //(scan over all possible AD channels; although, the 885 has only one 14-bit channel) STemp = 0; // HSnumber = 0; ADnumber = 0; if (!notDestructed) { errorValue = GetNumberADChannels(&nAD); if (errorValue != DRV_SUCCESS){ std::cerr << "Get number AD Channel Error\n"; errorFlag = true; } else if (nAD != 1) { std::cerr << "Expect 1 AD channel for this camera. The following code will miss channels\n"; errorFlag = true; } else { errorValue = GetNumberHSSpeeds(0, 0, &index); if(errorValue == DRV_SUCCESS){ for (iSpeed = 0; iSpeed < index; iSpeed++) { GetHSSpeed(0, 0, iSpeed, &speed); horizontalShiftSpeed_t.choices[iSpeed] = STI::Utils::valueToString(speed); if(speed < STemp){ STemp = speed; horizontalShiftSpeed = iSpeed; } } horizontalShiftSpeed_t.initial = horizontalShiftSpeed_t.choices.find(horizontalShiftSpeed)->second; } //getBitDepth if (DRV_SUCCESS != GetBitDepth(0, &bitDepth)) return true; } errorValue = GetNumberAmp(&nAmp); printError(errorValue, "Get Number Amplifiers Error", &errorFlag, ANDOR_ERROR); errorValue = GetNumberPreAmpGains(&nPreAmp); printError(errorValue, "Get Number Preamplifiers Error", &errorFlag, ANDOR_ERROR); if (nAmp == 1 && nAD == 1) { for (i = 0; i < nPreAmp; i++) { errorValue = GetPreAmpGain(i, &gain); errorValue = IsPreAmpGainAvailable(0,0,horizontalShiftSpeed,i,&IsPreAmpAvailable); if (IsPreAmpAvailable == 1) { preAmpGain_t.choices[i] = STI::Utils::valueToString(gain); } } if (!preAmpGain_t.choices.empty()) { preAmpGain = preAmpGain_t.choices.begin()->first; //preAmpGainPos = 0; preAmpGain_t.initial = (preAmpGain_t.choices.begin())->second; // set the initial condition for the preamplifier gain errorValue = SetPreAmpGain(preAmpGain); printError(errorValue, "Set AD Channel Error", &errorFlag, ANDOR_ERROR); } else { std::cerr << "No gains available at this speed. Weird."; errorFlag = true; } } else { std::cerr << "Unexpected number of A/D's or output amps" << std::endl; std::cerr << "Expected A/D's: 1 \t Measured: " << nAD << std::endl; std::cerr << "Expected output Amps: 1 \t Measured: " << nAmp << std::endl; errorFlag = true; } } else { errorValue = SetPreAmpGain(preAmpGain); printError(errorValue, "Set AD Channel Error", &errorFlag, ANDOR_ERROR); } errorValue=SetADChannel(ADnumber); printError(errorValue, "Set AD Channel Error", &errorFlag, ANDOR_ERROR); errorValue=SetHSSpeed(0,horizontalShiftSpeed); printError(errorValue, "Set Horizontal Speed Error", &errorFlag, ANDOR_ERROR); if(errorFlag) //MessageBox(GetActiveWindow(),aBuffer,"Error!",MB_OK); SMD std::cerr<<aBuffer<<std::endl; // Wait for 2 seconds to allow MCD to calibrate fully before allowing an // acquisition to begin // test=GetTickCount(); // do{ // test2=GetTickCount()-test; // }while(test2<2000); Sleep(2000); errorValue = SetExposureTime(exposureTime); printError(errorValue, "Exposure time error", &errorFlag, ANDOR_ERROR); // It is necessary to get the actual times as the system will calculate the // nearest possible time. eg if you set exposure time to be 0, the system // will use the closest value (around 0.01s) GetAcquisitionTimings(&exposureTime,&accumulateTime,&kineticTime); std::cerr << "Actual Exposure Time is " << exposureTime << " s.\n"; // Set Shutter is made up of ttl level, shutter and open close time //Check Get open close time if(openTime==0) openTime=1; if(closeTime==0) closeTime=1; // Set shutter errorValue=SetShutter(ttl,shutterMode,closeTime,openTime); if(errorValue!=DRV_SUCCESS){ std::cerr << "Shutter error\n"; errorFlag = true; } else std::cerr << "Shutter set to specifications\n"; /*// Determine availability of trigger option and set trigger selection std::map<int,std::string>::iterator it; std::vector<int> triggerKeys; for (it = triggerMode_t.choices.begin(); it != triggerMode_t.choices.end(); it++) { errorValue = SetTriggerMode(it->first); if (errorValue != DRV_SUCCESS) triggerKeys.push_back(it->first); } for (int i = 0; i < triggerKeys.size(); i++) triggerMode_t.choices.erase(triggerKeys.at(i)); if (triggerMode_t.choices.empty()) { std::cerr << "No triggerModes found" << std::endl; return true; } else if (triggerMode_t.choices.find(TRIGGERMODE_EXTERNAL_EXPOSURE) != triggerMode_t.choices.end()) triggerMode = TRIGGERMODE_EXTERNAL_EXPOSURE; else if (triggerMode_t.choices.find(TRIGGERMODE_EXTERNAL) != triggerMode_t.choices.end()) triggerMode = TRIGGERMODE_EXTERNAL; else triggerMode = triggerMode_t.choices.begin()->first; errorValue=SetTriggerMode(triggerMode); printError(errorValue, "Set Trigger Mode Error", &errorFlag, ANDOR_ERROR); triggerMode_t.initial = triggerMode_t.choices.find(triggerMode)->second; */ // Determine availability of trigger option and set trigger selection std::map<int,std::string>::iterator it; std::vector<int> triggerKeys; for (it = triggerMode_t.choices.begin(); it != triggerMode_t.choices.end(); it++) { errorValue = SetTriggerMode(it->first); if (errorValue != DRV_SUCCESS) triggerKeys.push_back(it->first); } for (int i = 0; i < triggerKeys.size(); i++) triggerMode_t.choices.erase(triggerKeys.at(i)); if (triggerMode_t.choices.empty()) { std::cerr << "No triggerModes found" << std::endl; return true; } else if (triggerMode_t.choices.find(TRIGGERMODE_EXTERNAL_EXPOSURE) != triggerMode_t.choices.end()) triggerMode = TRIGGERMODE_EXTERNAL_EXPOSURE; else if (triggerMode_t.choices.find(TRIGGERMODE_EXTERNAL) != triggerMode_t.choices.end()) triggerMode = TRIGGERMODE_EXTERNAL; else triggerMode = triggerMode_t.choices.begin()->first; errorValue=SetTriggerMode(triggerMode); printError(errorValue, "Set Trigger Mode Error", &errorFlag, ANDOR_ERROR); triggerMode_t.initial = triggerMode_t.choices.find(triggerMode)->second; errorValue = GetTemperatureRange(&minTemp, &maxTemp); if (errorValue != DRV_SUCCESS){ std::cerr << "Error finding temperature range or camera is not on" << std::endl; errorFlag = true; } else { std::cerr << "Temperature must be between " << minTemp << " and " << maxTemp << std::endl; std::cerr << "Warning: Water cooling is required for temperatures < -58 deg C" << std::endl; //Set temperature if (coolerSetpt > maxTemp || coolerSetpt < minTemp) { std::cerr << "Chosen temperature out of range." << std::endl; if (coolerSetpt > maxTemp) coolerSetpt = maxTemp; else coolerSetpt = minTemp; std::cerr << "Resetting temp to nearest acceptable value " << std::endl; } errorValue = SetTemperature(coolerSetpt); printError(errorValue, "Error setting cooler temperature", &errorFlag, ANDOR_ERROR); int i; errorValue = IsCoolerOn(&i); if (i == 0) { // if it's off and it's supposed to be on, turn it on if (coolerStat == ANDOR_ON) { std::cerr << "Turning on cooler." << std::endl; errorValue = CoolerON(); printError(errorValue, "Error turning on cooler", &errorFlag, ANDOR_ERROR); } } else if (i == 1) { std::cerr << "Cooler is on." << std::endl; //if it's on and it's supposed to be off, turn it off if (coolerStat == ANDOR_OFF) { errorValue = CoolerOFF(); printError(errorValue, "Error turning off cooler", &errorFlag, ANDOR_ERROR); } else { errorValue = GetTemperature(&i); switch(errorValue){ case DRV_TEMP_STABILIZED: std::cerr << "Cooler temp has stabilized at " << i << " deg C" << std::endl; break; case DRV_TEMP_NOT_REACHED: std::cerr << "Cooler temp is " << i << " deg C" << std::endl; std::cerr << "Cooler setpoint has not been reached." << std::endl; std::cerr << "This may be because water cooling is required for setpoints < -58 deg C" << std::endl; std::cerr << "Either wait or try resetting cooler setpoint" << std::endl; break; case DRV_TEMP_DRIFT: std::cerr << "Cooler temp is " << i << " deg C" << std::endl; std::cerr << "Cooler temperature has drifted. Try resetting setpoint" << std::endl; break; case DRV_TEMP_NOT_STABILIZED: std::cerr << "Cooler temp is " << i << " deg C" << std::endl; std::cerr << "Temperature has been reached, but cooler has not stabilized" << std::endl; std::cerr << "Either wait or try resetting cooler setpoint" << std::endl; break; default: std::cerr << "Unrecognized error sequence. Camera may be off or acquiring" << std::endl; break; } } } if(!errorFlag){ std::cerr << "Cooler temperature set to: " << coolerSetpt << std::endl; } } errorValue = SetSpool(0,0,NULL,10); //Disable spooling printError(errorValue, "Spool mode error", &errorFlag, ANDOR_ERROR); // Returns the value from PostQuitMessage return errorFlag; }
void TiePieHS3::sample_after_external_trigger(double _rate, size_t _samples, double _sensitivity ,size_t _resolution) { ADC_Abort(); /* set autoranging off */ SetAutoRanging(Ch1,0); SetAutoRanging(Ch2,0); samples=_samples; if (samples==0 || _rate<=0) return; unsigned short int retval; //samples=1024*1024*1024; // impossible value... provoke error retval=SetRecordLength(samples); if (0!=retval) { char buffer[256]; snprintf(buffer, sizeof(buffer), "could not set record length: SetRecrodLength(%d) returned %d", samples, retval); throw ADC_exception(std::string(buffer)); } if (0!=SetPostSamples(samples)){ throw ADC_exception("could not set post sample number"); } fprintf(stderr,"set sample number to %d\n",samples); /* set sampling frequency */ unsigned int freq=(unsigned int)fabs(floor(_rate)+0.5); unsigned int freq_req=freq; SetSampleFrequency(&freq_req); if (freq!=freq_req) throw ADC_exception("requested frequency could not be set"); rate=freq_req; fprintf(stderr,"set rate to %g\n",rate); /* set resolution */ if (0!=SetResolution(_resolution)) throw ADC_exception("could not set resolution"); unsigned char resolution_set; GetResolution(&resolution_set); if (_resolution!=resolution_set) throw ADC_exception("requested resolution not supported"); resolution=_resolution; fprintf(stderr,"set resolution to %d\n",resolution); #if 0 /* set DC level value to zero */ const double dclevel_req=-2.0; if (E_NO_ERRORS!=SetDcLevel(1, dclevel_req)) throw ADC_exception("could not set dc level for channel 1"); if (E_NO_ERRORS!=SetDcLevel(2, dclevel_req)) throw ADC_exception("could not set dc level for channel 2"); #endif /* set input sensitivity for both channels */ double sensitivity_req1=_sensitivity; SetSensitivity(1,&sensitivity_req1); double sensitivity_req2=_sensitivity; SetSensitivity(2,&sensitivity_req2); if (sensitivity_req1!=_sensitivity || sensitivity_req2!=_sensitivity) throw ADC_exception("requested sensitivity could not be set"); sensitivity=_sensitivity; fprintf(stderr,"set sensitivity to %g\n",sensitivity); /* set input coupling to DC */ if (0!=SetCoupling(Ch1, ctDC) || 0!=SetCoupling(Ch2, ctDC)) throw ADC_exception("could not set coupling to dc"); /* what to measure */ if (E_NO_ERRORS!=SetMeasureMode(mmCh12)) /* Channel 1 and 2 */ throw ADC_exception("could not set measurement mode"); /* the trigger source */ if (E_NO_ERRORS!=SetTriggerSource(tsExternal)) /* external trigger */ throw ADC_exception("could not set trigger source"); /* which slope to trigger */ if (E_NO_ERRORS!=SetTriggerMode(tmRising)) /* 0=Rising slope */ throw ADC_exception("could not set trigger source"); /* set transfer mode */ if (E_NO_ERRORS!=SetTransferMode(tmBlock)) throw ADC_exception("could not set transfer mode"); /* finally start the measurement */ if (0!=ADC_Start()) throw ADC_exception("could not start triggered adc measurement"); fprintf(stderr,"started triggered adc measurement with %d samples, rate=%g, sensitivity=%g, resolution=%d\n",samples,rate,sensitivity,resolution); }