Exemple #1
0
int PvUniversalParam::initialize()
{
   plGetParam( ATTR_CURRENT, mValue );

   if ( mType == TYPE_ENUM )
   {
       mEnumStrings.clear();
       
       uns32 count;
       char enumStr[MAX_ENUM_STR_LEN];
       int32 enumValue;
       if (pl_get_param( mCamera->Handle(), mId, ATTR_COUNT, (void_ptr)&count) != PV_OK)
       {
           mCamera->LogCamError(__LINE__, "PvUniversalParam::initialize() pl_get_param ATTR_COUNT");
           return DEVICE_ERR;
       }
       for ( uns32 i = 0; i < count; i++ )
       {
           if (pl_get_enum_param( mCamera->Handle(), mId, i, &enumValue, enumStr, MAX_ENUM_STR_LEN) != PV_OK )
           {
               mCamera->LogCamError(__LINE__, "PvUniversalParam::initialize() pl_get_enum_param");
               return DEVICE_ERR;
           }
           mEnumStrings.push_back(std::string( enumStr ));
       }
   }
   else
   {
       plGetParam( ATTR_MIN, mValueMin );
       plGetParam( ATTR_MAX, mValueMax );
   }

   return DEVICE_OK;
}
int PvUniversalParam::plGetParam( int16 aAttr, PvUniversalParamValue& aValueOut )
{
    rs_bool pvRet;
    switch (mType)
    {
    case TYPE_INT8:
        pvRet = pl_get_param( mCamera->Handle(), mId, aAttr, &aValueOut.int8_val );
        break;
    case TYPE_UNS8:
        pvRet = pl_get_param( mCamera->Handle(), mId, aAttr, &aValueOut.uns8_val );
        break;
    case TYPE_INT16:
        pvRet = pl_get_param( mCamera->Handle(), mId, aAttr, &aValueOut.int16_val );
        break;
    case TYPE_UNS16:
        pvRet = pl_get_param( mCamera->Handle(), mId, aAttr, &aValueOut.uns16_val );
        break;
    case TYPE_INT32:
        pvRet = pl_get_param( mCamera->Handle(), mId, aAttr, &aValueOut.int32_val );
        break;
    case TYPE_ENUM:
        pvRet = pl_get_param( mCamera->Handle(), mId, aAttr, &aValueOut.enum_val );
        break;
    case TYPE_BOOLEAN:
        pvRet = pl_get_param( mCamera->Handle(), mId, aAttr, &aValueOut.rs_bool_val );
        break;
    case TYPE_UNS32:
        pvRet = pl_get_param( mCamera->Handle(), mId, aAttr, &aValueOut.uns32_val );
        break;
    case TYPE_FLT64:
        pvRet = pl_get_param( mCamera->Handle(), mId, aAttr, &aValueOut.flt64_val );
        break;
#ifdef TYPE_INT64
    case TYPE_INT64:
        pvRet = pl_get_param( mCamera->Handle(), mId, aAttr, &aValueOut.long64_val );
        break;
#endif
    default:
        mCamera->LogCamError(__LINE__, "PvUniversalParam::plGetParam() type not supported");
        pvRet = PV_FAIL;
        break;
    }

    if (pvRet != PV_OK)
        return DEVICE_ERR;
    return DEVICE_OK;
}
Exemple #3
0
double QuantixCamera::getFrameRefreshTime(EventMetadatum &eventMetadatum)
{
	uns16 pixelWriteTimeNS;

	double parallelShiftTimeNS = 80000; // 80 microseconds
	double serialDiscardRateNS = 100;   // 0.1 microseconds
	double serialRecordRateNS;

	int16 pixTime;
	if (!pl_get_param (cameraHandle, PARAM_PIX_TIME, ATTR_CURRENT, &pixTime))
		throw CameraException("Can't access pixel time for frame refresh");

	serialRecordRateNS = (double) pixTime;

	if(!pl_get_param(cameraHandle, PARAM_PIX_TIME, ATTR_CURRENT, (void *) &pixelWriteTimeNS))
	{
		char msg[ERROR_MSG_LEN];		// for error handling
		pl_error_message(pl_error_code(), msg);
		std::cerr << "Pixel readout time error: " << msg << std::endl;
		throw CameraException("Error getting pixel readout time.");
	}

	int parallelRows = (cameraState->imageWidth.getSize());
	int totalPixels = (cameraState->imageHeight.getSize())*(cameraState->imageWidth.getSize());
	int recordedRows = eventMetadatum.cropVector.at(2) + 1;
	int recordedPixels = recordedRows*(eventMetadatum.cropVector.at(3) + 1);
	int binSize;
	if (!STI::Utils::stringToValue(cameraState->binSize.get(), binSize))
		throw CameraException("Error transforming string to value");


	//Based off the 6303 data sheet
	double refreshTime = 0;
	refreshTime += recordedRows*parallelShiftTimeNS;			//Time to shift relevant rows.
	refreshTime += recordedPixels*serialRecordRateNS / binSize / binSize; //Time to record (and discard?) relevent pixels
	refreshTime += (totalPixels - recordedPixels)*serialDiscardRateNS; //Time to discard non-relevant pixels

	
	std::cerr << "Frame Rate (s): " << refreshTime/1000000000 << std::endl; 
	return refreshTime;
}
Exemple #4
0
double QuantixCamera::getMinExposureTime()
{
	//Best Case Scenario: get minimum exposure time from Camera
	flt64 minExpTimeS;

	char enumStr[100];
	int32 enumValue;
	uns32 currentMode = 0;
	//experimentally-determined min exposure time: 0.3*ms, but keep 1 ms to be safe

	if(!pl_get_param(cameraHandle, PARAM_EXP_MIN_TIME, ATTR_CURRENT, (void *)&minExpTimeS))
	{
		pl_get_param(cameraHandle, PARAM_EXP_RES, ATTR_CURRENT, (void *) &currentMode);
		pl_get_enum_param (cameraHandle, PARAM_EXP_RES, currentMode, &enumValue, enumStr, 100);
		if (enumValue == EXP_RES_ONE_MICROSEC)
			minExpTimeS = 0.000001;
		else if (enumValue == EXP_RES_ONE_MILLISEC)
			minExpTimeS = 0.001;
		else
			minExpTimeS = 0;
	}

	return (double) (1000000000 * minExpTimeS);
}
int PvUniversalParam::initialize()
{
    plGetParam( ATTR_CURRENT, mValue );

    if ( mType == TYPE_ENUM )
    {
        mEnumStrings.clear();
        mEnumValues.clear();

        uns32 count;
        int32 enumValue;
        if (pl_get_param( mCamera->Handle(), mId, ATTR_COUNT, (void_ptr)&count) != PV_OK)
        {
            mCamera->LogCamError(__LINE__, "PvUniversalParam::initialize() pl_get_param ATTR_COUNT");
            return DEVICE_ERR;
        }
        for ( uns32 i = 0; i < count; i++ )
        {
            uns32 enumStrLen;
            if ( pl_enum_str_length( mCamera->Handle(), mId, i, &enumStrLen ) != PV_OK )
            {
                mCamera->LogCamError(__LINE__, "PvUniversalParam::initialize() pl_enum_str_length");
                return DEVICE_ERR;
            }
            char* enumStrBuf = new char[enumStrLen+1];
            enumStrBuf[enumStrLen] = '\0';
            if (pl_get_enum_param( mCamera->Handle(), mId, i, &enumValue, enumStrBuf, enumStrLen) != PV_OK )
            {
                mCamera->LogCamError(__LINE__, "PvUniversalParam::initialize() pl_get_enum_param");
                return DEVICE_ERR;
            }
            mEnumStrings.push_back(std::string( enumStrBuf ));
            mEnumValues.push_back(enumValue);
            delete[] enumStrBuf;
        }
    }
    else
    {
        plGetParam( ATTR_MIN, mValueMin );
        plGetParam( ATTR_MAX, mValueMax );
    }

    return DEVICE_OK;
}
Exemple #6
0
// gateway routine
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {

	// declarations
	rs_bool	success = 0;	// flag for successful execution
	char	*param_name;	// parameter name pointer
	double	*param_value;	// parameter value pointer
	int		param_len;		// parameter name length
	int16	hcam;			// camera handle
	uns32	param_id;		// parameter ID

	// validate arguments
	if ((nrhs != 3) || (nlhs > 1)) {
        mexErrMsgTxt("type 'help pvcamset' for syntax");
    }

	// obtain camera handle
	if (!mxIsNumeric(prhs[0])) {
		mexErrMsgTxt("HCAM must be numeric");
	}
	else if (mxGetNumberOfElements(prhs[0]) != 1) {
		mexErrMsgTxt("HCAM must be a scalar");
	}
	else {
		hcam = (int16) mxGetScalar(prhs[0]);
	}

	// obtain parameter name
	if (!mxIsChar(prhs[1])) {
		mexErrMsgTxt("PARAM must be a string");
	}
	else if ((param_len = mxGetNumberOfElements(prhs[1])) < 1) {
		mexErrMsgTxt("PARAM cannot be empty");
	}
	else {
		param_name = (char *) mxCalloc(param_len + 1, sizeof(char));
		if (mxGetString(prhs[1], param_name, param_len + 1)) {
			mexErrMsgTxt("Could not retrieve PARAM from input arguments");
		}
	}

	// obtain parameter value
	if (!mxIsDouble(prhs[2])) {
		mexErrMsgTxt("VALUE must be numeric");
	}
	else if (mxGetNumberOfElements(prhs[2]) != 1) {
		mexErrMsgTxt("VALUE must be a scalar");
	}
	else if ((param_value = mxGetPr(prhs[2])) == NULL) {
		mexErrMsgTxt("Could not retrieve VALUE from input arguments");
	}

	// check for open camera
	if (!pl_cam_check(hcam)) {
		pvcam_error(hcam, "HCAM is not a handle to an open camera");
	}

	// obtain parameter ID
	else if (!pvcam_param_id(hcam, param_name, &param_id)) {
	}

	// obtain parameter availability
	else if (!pl_get_param(hcam, param_id, ATTR_AVAIL, (void *) &attr_avail)) {
		pvcam_error(hcam, "Cannot obtain parameter availability");
	}

	// do not proceed if parameter is not available
	else if (!attr_avail) {
		pvcam_error(hcam, "Parameter not available on this camera");
	}

	// obtain parameter accessibility 
	else if (!pl_get_param(hcam, param_id, ATTR_ACCESS, (void *) &attr_access)) {
		pvcam_error(hcam, "Cannot obtain parameter accessibility");
	}

	// do not proceed if parameter is not write only or read/write
	else if ((attr_access != ACC_WRITE_ONLY) && (attr_access != ACC_READ_WRITE)) {
		pvcam_error(hcam, "Parameter cannot be set");
	}

	// obtain parameter type 
	else if (!pl_get_param(hcam, param_id, ATTR_TYPE, (void *) &attr_type)) {
		pvcam_error(hcam, "Cannot obtain parameter type");
	}

	// obtain parameter count
	else if (!pl_get_param(hcam, param_id, ATTR_COUNT, (void *) &attr_count)) {
		pvcam_error(hcam, "Cannot obtain parameter count");
	}

	// set success flag to return value of pvcam_set_numeric()
	else {
		success = pvcam_set_numeric(hcam, param_id, *param_value);
	}

	// set output to return value of success flag
	plhs[0] = mxCreateDoubleScalar((double) success);

	// free allocated space
	mxFree((void *) param_name);
}
void mexFunction(int nlhs, mxArray *plhs[],
                 int nrhs, const mxArray *prhs[])
{
    // Testing of external linking of classes defined in other dll-s
    // don't forget to copy the current version of the externally linked dll into the same directory where
    // the this file is located
    OBuffer oCircularBuffer;
    char sTest[MAX_STRING_BUFFER_LENGTH];
    oCircularBuffer.Test(sTest, MAX_STRING_BUFFER_LENGTH);

    mexPrintf("Start continous exposure");

    // init stuff
    // prepare variables
    bool bVerbose = false;
    unsigned int expTime, lNonexposureTime, lNumOfFrames;
    double *ptrImageArray=NULL;
    char cam_name[CAM_NAME_LEN];
    int16 hCam = 0;
    rs_bool avFlag;
    rs_bool retCode = FALSE;
    uns16* poImageBuffer = 0;
    uns16** poImagesBuffer[2];
    OCircularBuffer oImageBuffer1, oImageBuffer2;


    // Usage:
    // read command-line arguments
    // correct number of parameters?
    if (nrhs != 11 )
    {
        mexPrintf("\nUsage: >> nmssCAMGetImage(hCam, x,y,w,h,bx,by,expTime)");
        mexPrintf("\nwhere: ");
        mexPrintf("\n        - hCam: the camera handle (integer number)");
        mexPrintf("\n        - x,y: upper left corner of used rectangle on the CCD-chip");
        mexPrintf("\n        - w,h: width and height of that rectangle");
        mexPrintf("\n        - bx,by: binning factors in x- and y-direction");
        mexPrintf("\n        - expTime: exposure time in milliseconds");
        mexPrintf("\n        - lNonexposureTime: time in milliseconds until a new exposure is being taken");
        mexPrintf("\n        - lNumOfFrames: the number of frames to be taken");
        mexPrintf("\n        - verbose: if 0, no output, if 1 output generated and printed");
        mexPrintf("\n");
        return;
    }

    hCam = (uns16) mxGetScalar(prhs[0]);
    uns16 x1=(uns16) mxGetScalar(prhs[1]);
    uns16 y1=(uns16) mxGetScalar(prhs[2]);
    uns16 x2=(uns16) mxGetScalar(prhs[3]);
    uns16 y2=(uns16) mxGetScalar(prhs[4]);
    uns16 by=(uns16) mxGetScalar(prhs[5]);
    uns16 bx=(uns16) mxGetScalar(prhs[6]);
    // exposure time in the unit given by PARAM_EXP_RES (usually ms)
    expTime=(unsigned int) mxGetScalar(prhs[7]);
    lNonexposureTime = (unsigned int) mxGetScalar(prhs[8]);
    lNumOfFrames = (unsigned int) mxGetScalar(prhs[9]);
    // exit, if number of frames is smaller than 1 - no frame - no image
    if (lNumOfFrames < 1)
        throw "Number of frames should be >= 1!";
    if (lNumOfFrames > 1)
        throw "Acquisition of more than 1 frames is not implemented fully yet! :-(";

    bVerbose = ((unsigned int) mxGetScalar(prhs[10]) == 1);

    // greeting to user
    if (bVerbose)
        mexPrintf("\n nmssCAMGetImage();\n");

    try {

        // take picture
        // region of interest
        try {
            nmssCAM_CheckROIRange(hCam, x2, y2, x1, y1);
        }
        catch (...) {
            throw;
        };

        rgn_type reg[1];
        reg[0].s1 = x1-1;
        reg[0].s2 = x2-1;
        reg[0].sbin = bx;
        reg[0].p1 = y1-1;
        reg[0].p2 = y2-1;
        reg[0].pbin = by;

        if (bVerbose)
            mexPrintf("\nROI: (%d; %d) .. (%d; %d)", reg[0].s1,reg[0].s2, reg[0].p1, reg[0].p2);

        // Experimental: Display time resolution setting
        //nmssCAM_disp_time_resolution_setting(hCam);


        // number of images to take
        uns16 expTotal = 1;
        // total number of region definitions
        uns16 regTotal = 1;
        // exposure mode
        int16 mode = TIMED_MODE;
        // number of bytes in the "pixel stream"
        uns32 nNumberOfBytes = 1;
        // status of exposure
        int16 status;
        //
        uns32 na = 0;

        if (bVerbose)
            mexPrintf("\nInitializing exposure controller...");
        retCode = pl_exp_init_seq();
        if (retCode == 0) throw retCode;

        if (bVerbose)
            mexPrintf("\nPreparing camera for readout...");
        retCode = pl_exp_setup_cont( hCam, regTotal, reg, mode , expTime,
                                     &nNumberOfBytes, CIRC_OVERWRITE);
        if (retCode == 0) throw retCode;

        // allocate memory
        if (bVerbose)
        {
            mexPrintf("\nReceived %d bytes", nNumberOfBytes);
            mexPrintf("\nsizeof(uns16)=%d", sizeof(uns16));
        }
        poImagesBuffer = oImageBuffer.CreateFrameBuffer(lNumOfFrames, nNumberOfBytes);

        // ------------------------------------------------------------------------------
        // start image acquisition
        // ------------------------------------------------------------------------------
        if (bVerbose) mexPrintf("\nStarting readout...");

        // start continous acquisition of frames into the circular buffer
        pl_exp_start_cont(hCam, poImagesBuffer, oImageBuffer.GetSize());

        unsigned int k = 0;
        while (k < lNumOfFrames) {

            retCode = pl_exp_start_seq(hCam, (void*)poImagesBuffer[k]);

            if (retCode>0)
            {
                k++;

                clock_t oStartTime = clock();
                clock_t oTimeOut = (expTime / 1000.0 + 60) * CLOCKS_PER_SEC; // timeout 60s

                if (bVerbose)
                    mexPrintf("\nWait until camera is ready...");
                // wait for exposure to finish
                while( pl_exp_check_status(hCam, &status, &na)
                        && (status!=READOUT_COMPLETE)
                        && (status != READOUT_FAILED) )
                {
                    if ((clock() - oStartTime) > oTimeOut)
                        throw "Camera seems to be blocking!";
                    nmssSleep(50);
                }
                plhs[0] = mxCreateString("OK");
            }
            else
                throw retCode;
        }

        // finish acq.
        if (bVerbose)
            mexPrintf("\nFinished readout...");

        if (bVerbose)
            mexPrintf("\nUninitializing exposure controller...it needs some rest, yeah");

        pl_exp_uninit_seq();

        uns16 nXSize = reg[0].s2 - reg[0].s1 + 1;
        uns16 nYSize = reg[0].p2 - reg[0].p1 + 1;
        if (bVerbose)
        {
            uns16 nYSize_chip;
            uns16 nXSize_chip;
            mexPrintf("\nGet YSize of the chip");
            pl_get_param(hCam, PARAM_PAR_SIZE, ATTR_CURRENT, &nYSize_chip);
            mexPrintf("\nGet XSize of the chip");
            pl_get_param(hCam, PARAM_SER_SIZE, ATTR_CURRENT, &nXSize_chip);
            mexPrintf("\nChip size %d x %d", nXSize, nYSize);
        }

        //if (size != nXSize * nYSize)
        //{
        //	std::string sThrowThisError("Error while reading CCD\n");
        //	sThrowThisError += "Number of bytes readed is larger than X x Y!"
        //	throw(sThrowThisError);
        //}
        plhs[1] = mxCreateNumericMatrix(nXSize, nYSize,      // matrix dimensions
                                        mxUINT16_CLASS,      // the camera returns unsigned int
                                        mxREAL);             // no complex numbers


        unsigned short * poImage = (unsigned short *)mxGetData(plhs[1]);
        size_t bytes_to_copy = nXSize * nYSize * mxGetElementSize(plhs[1]);
        if (bVerbose)
        {
            //mexPrintf("\nElement size of plhs[1]= %d", mxGetElementSize(plhs[1]));
            mexPrintf("\nNumber of bytes read from camera: %d", bytes_to_copy);
        }

        // works only for one frame
        memcpy(poImage, poImagesBuffer[0], bytes_to_copy);

        // clean up after multiple exposure
        if (lNumOfFrames >= 1)
            pl_exp_finish_seq(hCam, poImageBuffer,0);
    }
    // camera hardware error message
    catch (rs_bool retCode)
    {
        nmssCAMError(nlhs, plhs);
    }
    // nanobiotech error message
    catch (char* msg)
    {
        //mexPrintf(msg);
        plhs[0] = mxCreateString("ERROR");
        plhs[1] = mxCreateString(msg);
    }
    catch (std::string sErrorMsg)
    {
        //mexPrintf(msg);
        plhs[0] = mxCreateString("ERROR");
        plhs[1] = mxCreateString(sErrorMsg.c_str());
    }


    return;
};
Exemple #8
0
/*****************************************************************************
*
*       SetLongParam_PvCam
*
* Description :: 
*       This routine sets a parameter in PvCam, it takes care of data type for 
*   the user, by taking a long from the user.
*
*-----------------------------------------------------------------------------
*/
bool SetLongParam_PvCam
(   int16 handle,
    uns32 pvcam_cmd,
    long value
)
{
    bool status = false;
    union {
        double dtmp;
        uns8 ubytetmp;
        int16 stmp;
        uns16 ustmp;
        int32 ltmp;
        uns32 ultmp;
        uns32 etmp;
        boolean btmp;
        int8 bytetmp;
    } temp;                     /* temp variable for values, which can be any data type. */
    bool avail;                 /* PvCam available variable. */
    uns16 DataType;             /* PvCam data type variable. */
    uns16 access;               /* PvCam access variable.    */
    bool fcn_status;            /* status of function.       */
    uns32 count;                /* number of values in variable */

    fcn_status = (bool)pl_get_param( handle, pvcam_cmd, ATTR_AVAIL, (void*)&temp );
    avail = (bool)temp.btmp;

    if (fcn_status && avail)
    {
		pl_get_param( handle, pvcam_cmd, ATTR_TYPE,		
                             (void*)&DataType );
	    pl_get_param( handle, pvcam_cmd, ATTR_COUNT,    
                             (void*)&count);
		pl_get_param( handle, pvcam_cmd, ATTR_ACCESS,	
                             (void*)&access );

        /* Make sure this is a valid parameter to set. */
        if (access == ACC_READ_WRITE)
        {
            status = true;
            switch (DataType)
            {
                case TYPE_INT8 :        /* signed char                            */
                    temp.bytetmp = (char) value;
                    pl_set_param(handle, pvcam_cmd, (void *)&temp.bytetmp);
                    break;
                case TYPE_UNS8 :        /* unsigned char                          */
                    temp.ubytetmp = (unsigned char) value;
                    pl_set_param(handle, pvcam_cmd, (void *)&temp.ubytetmp);
                    break;
                case TYPE_INT16 :       /* short                                  */
                    temp.stmp = (short) value;
                    pl_set_param(handle, pvcam_cmd, (void *)&temp.stmp);
                    break;
                case TYPE_UNS16 :       /* unsigned short                         */
                    temp.ustmp = (unsigned short) value;
                    pl_set_param(handle, pvcam_cmd, (void *)&temp.ustmp);
                    break;
                case TYPE_INT32 :       /* long                                   */
                    temp.ltmp = (long) value;
                    pl_set_param(handle, pvcam_cmd, (void *)&temp.ltmp);
                    break;
                case TYPE_UNS32 :       /* unsigned long                          */
                    temp.ultmp = (unsigned long) value;
                    pl_set_param(handle, pvcam_cmd, (void *)&temp.ultmp);
                    break;
                case TYPE_FLT64 :       /* double                                 */
                    temp.dtmp = (double) value;
                    pl_set_param(handle, pvcam_cmd, (void *)&temp.dtmp);
                    break;
                case TYPE_BOOLEAN :     /* Boolean value                          */
                    temp.btmp = (boolean) value;
                    pl_set_param(handle, pvcam_cmd, (void *)&temp.btmp);
                    break;
                case TYPE_ENUM :        /* Can be treat as unsigned long          */
                    temp.ultmp = (unsigned long) value;
                    pl_set_param(handle, pvcam_cmd, (void *)&temp.ultmp);
                    break;
                default:
                /* ptrs not supported yet. */
                case TYPE_VOID_PTR :    /* ptr to void                            */
                case TYPE_VOID_PTR_PTR :/* void ptr to a ptr.                     */
                case TYPE_CHAR_PTR :    /* char                                   */
                    status = false;
                break;
            }
        }
   }

    return(status);
}                           /* end SetLongParam_PvCam */