bool ANDOR885_Camera::getCameraData(int *numAcquired_p, int numExposures, std::vector <WORD>& tempImageVector) { int errorValue = DRV_SUCCESS; bool error = false; long first = 1; long last = 1; long imageSize = imageWidth*imageHeight; long validFirst = 1; long validLast = 1; int tempAcq = 0; int excess = 0; errorValue = GetNumberNewImages(&first, &last); if (errorValue != DRV_NO_NEW_DATA) printError(errorValue, "Error acquiring number of new images", &error, ANDOR_ERROR); if (!error && errorValue != DRV_NO_NEW_DATA){ if(*numAcquired_p + last - first + 1 > numExposures) { excess = *numAcquired_p + last - first + 1 - numExposures; last -= excess; std::cerr << "More images acquired than expected number of exposures" << std::endl; std::cerr << "Ignored extra images" << std::cerr; } errorValue = GetImages16(first, last, &tempImageVector[(*numAcquired_p)*imageSize], (last - first + 1)*imageSize, &validFirst, &validLast); printError(errorValue, "Error acquiring images", &error, ANDOR_ERROR); tempAcq = last - first + 1; *numAcquired_p += tempAcq; } return (error); }
void capture_clara() { C(WaitForAcquisition()); at_32 first,last; C(GetNumberNewImages(&first,&last)); int n=last-first; printf("received %d images\n",1+n); at_32 pixels=(1+n)*clara_h*clara_w; at_32 validfirst,validlast; C(GetImages16(first,last,clara_buf,pixels, &validfirst,&validlast)); if((validlast!=last) || (validfirst!=first)) printf("couldn't get as many images as expected\n"); int i,len=clara_h*clara_w; for(i=0;i<n+1;i++){ unsigned long long sum=0; int j; for(j=0;j<len;j++) sum+=clara_buf[i*len+j]; printf("sum %012lld\n",sum); } }
// 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 != 4) { mexErrMsgIdAndTxt( "Mscope:getImage16Modulo:invalidNumInputs", "Three input arguments required."); } if (nlhs > 3) { mexErrMsgIdAndTxt( "Mscope:getImage16Modulo:maxlhs", "Too many output arguments."); } unsigned long xPix, yPix; long cycleFrame, cycleLength; /* validate arguments etc... */ if (!isScalarArray(prhs[0])) { mexErrMsgIdAndTxt("Mscope:getImage16Modulo:invalidArg","Integer number of pixels"); } xPix = (unsigned long) mxGetScalar(prhs[0]); if (!isScalarArray(prhs[1])) { mexErrMsgIdAndTxt("Mscope:getImage16Modulo:invalidArg","Integer number of pixels"); } yPix = (unsigned long) mxGetScalar(prhs[1]); if (!isScalarArray(prhs[2])) { mexErrMsgIdAndTxt("Mscope:getImage16Modulo:invalidArg","Integer frame in cycle"); } cycleFrame = (long) mxGetScalar(prhs[2]); if (!isScalarArray(prhs[3])) { mexErrMsgIdAndTxt("Mscope:getImage16Modulo:invalidArg","Integer cycle length"); } cycleLength = (long) mxGetScalar(prhs[3]); if (cycleFrame > cycleLength) { mexErrMsgIdAndTxt("Mscope:getImage16Modulo:invalidArg","Cycle length must be greater than cycle frame"); } /* construct the array we will return the image in */ unsigned long numPix = xPix*yPix; // total number of pixels WORD * imageArray = new WORD[numPix]; /* call the Andor SDK functions */ long first, last; unsigned int ac = GetNumberAvailableImages(&first,&last); INT32_T last32 = (INT32_T) last; // work out which image we need to retreive int latestCycleStart = last - last%cycleLength; // so many frames after the most recent cycle start int frame = latestCycleStart + cycleFrame - 2*cycleLength; // if (frame > last) { // frame = frame - cycleLength; // } if (frame < 1) { frame = 1; // give the first frame if we are just starting acquisition } std::printf("\nGetNumAvailIm Code: %i, First: %i, Last: %i, Frame: %i\n",ac,first,last,frame); INT32_T frame32 = (INT32_T) frame; // IMPORTANT ONE FOR ACTUAL IMAGE RETRIEVAL UINT32_T returnInt = (UINT32_T) GetImages16(frame,frame,imageArray,numPix,&first,&last); std::printf("\nValid First: %i, Valid Last: %i, Frame: %i\n",first,last,frame); /* Copy the memory into MATLAB form */ mwSignedIndex returnIntDims[2] = {1,1}; // how many elements does the output code need plhs[0] = mxCreateNumericArray(1, returnIntDims, mxUINT32_CLASS, mxREAL); double * codePtr = mxGetPr(plhs[0]); memcpy(codePtr, &returnInt, sizeof(returnInt)); mwSignedIndex imageDims[2] = {xPix,yPix}; // elements in image plhs[1] = mxCreateNumericArray(2, imageDims, mxUINT16_CLASS, mxREAL); double * imgPtr = mxGetPr(plhs[1]); memcpy(imgPtr, imageArray, numPix*sizeof(imageArray[0])); plhs[2] = mxCreateNumericArray(2, returnIntDims, mxINT32_CLASS, mxREAL); double * latestImNoPtr = mxGetPr(plhs[2]); memcpy(latestImNoPtr, &frame32, sizeof(frame32)); /* clear up the array we used */ delete imageArray; return; }