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);
}
Example #2
0
File: clara.c Project: plops/mma
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 != 2) {
        mexErrMsgIdAndTxt( "Mscope:getLastFrame16:invalidNumInputs",
                "Two input argument required.");
    }
    if (nlhs > 3) {
        mexErrMsgIdAndTxt( "Mscope:getLastFrame16:maxlhs",
                "Too many output arguments.");
    } 
    
    int xPix, yPix;
    
    if (!isScalarArray(prhs[0])) {
        mexErrMsgIdAndTxt("Mscope:setTimings:invalidArg","2-3 floating point scalars required");
    }
    xPix = (unsigned long) mxGetScalar(prhs[0]);
    
    /* validate exposure time etc... */
    if (!isScalarArray(prhs[1])) {
        mexErrMsgIdAndTxt("Mscope:setTimings:invalidArg","2-3 floating point scalars required");
    }
    yPix = (unsigned long) mxGetScalar(prhs[1]);
    
    /* 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;
    GetNumberNewImages(&first,&last);    
    INT32_T last32 = (INT32_T) last;
    
    // long validFirst, validLast; // Comment this out if not getting EXACT frame
    
    // IMPORTANT ONE FOR ACTUAL IMAGE RETRIEVAL        
    UINT32_T returnInt = (UINT32_T) GetMostRecentImage16(imageArray,numPix);
    // UINT32_T returnInt = (UINT32_T) GetImages16(last,last,imageArray,numPix,&validFirst,&validLast);

    
    /* 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, &last32, sizeof(last32));
    
    /* clear up the array we used */
    
    delete imageArray;
    
    return;
}