Exemplo n.º 1
0
int CountCameras()
{
    // Load driver
    err = SBIGUnivDrvCommand(CC_OPEN_DRIVER, NULL, NULL);
    if (err != CE_NO_ERROR)
    {
        fprintf(stderr,"Error opening camera driver\n");
        return(1);
    }

    // Query the USB bus to figure out how many cameras are hooked up.
    err = SBIGUnivDrvCommand(CC_QUERY_USB, NULL, &qur);
    if (err != CE_NO_ERROR)
    {
        fprintf(stderr,"Error querying USB bus\n");
        return(1);
    }

    // Close driver
    err = SBIGUnivDrvCommand(CC_CLOSE_DRIVER, NULL, NULL);
    if ( err != CE_NO_ERROR ) 
    {
        fprintf (stderr, "SBIG close driver error\n");
        return(1);
    }

    ccd_ncam = qur.camerasFound;

    return(0);

}
Exemplo n.º 2
0
SbigDetector::~SbigDetector() {
  cout << "Cleaning up detector." << endl;
  if (has_cooled_) DisableCooling();

  SBIGUnivDrvCommand(CC_CLOSE_DEVICE, NULL, NULL);
  SBIGUnivDrvCommand(CC_CLOSE_DRIVER, NULL, NULL);
}
Exemplo n.º 3
0
int  PrintUSBNetworkInformation()
{
    // Load driver
    err = SBIGUnivDrvCommand(CC_OPEN_DRIVER, NULL, NULL);
    if (err != CE_NO_ERROR)
    {
        fprintf(stderr,"Error opening camera driver\n");
        return(1);
    }

    // Query the USB bus to figure out how many cameras are hooked up.
    err = SBIGUnivDrvCommand(CC_QUERY_USB, NULL, &qur);
    if (err != CE_NO_ERROR)
    {
        fprintf(stderr,"Error querying USB bus\n");
        return(1);
    }

    fprintf(stdout,"Found %d cameras\n",qur.camerasFound);
    for(int i=0; i<qur.camerasFound; i++){
        switch(i)
        {
            case 0:
                fprintf(stdout,"USB1: ");
                break;
            case 1:
                fprintf(stdout,"USB2: ");
                break;
            case 2:
                fprintf(stdout,"USB3: ");
                break;
            case 3:
                fprintf(stdout,"USB4: ");
                break;
            default:
                fprintf(stdout,"Error: More than 4 cameras found.\n");
                return(1);
        }
        fprintf(stdout,"id = %-9s name = %s \n",qur.usbInfo[i].serialNumber,qur.usbInfo[i].name);

    }

    // Close driver
    err = SBIGUnivDrvCommand(CC_CLOSE_DRIVER, NULL, NULL);
    if ( err != CE_NO_ERROR ) 
    {
        fprintf (stderr, "SBIG close driver error\n");
        return(1);
    }

    return(0);

}
Exemplo n.º 4
0
void InterruptHandler(int sig)
{
    int phase=2;
    fprintf(stdout,"Integration terminated by user.\n");
    for (int cam_num = 0; cam_num <ccd_ncam; cam_num++)
    {
        CaptureImage(&phase,ccd_image_data[cam_num],ccd_type,0,FALSE,0,0,0,0);
        SBIGUnivDrvCommand(CC_CLOSE_DEVICE, NULL, NULL);
        SBIGUnivDrvCommand(CC_CLOSE_DRIVER, NULL, NULL);
    }
    release_lock();
    exit(EXIT_FAILURE);
}
Exemplo n.º 5
0
bool SbigDetector::SendCommand(short command, void* params, void* results) {
  last_error_ = SBIGUnivDrvCommand(command, params, results);
  if (last_error_ != CE_NO_ERROR) {
    GetErrorStringParams err_query{static_cast<uint16_t>(last_error_)};
    GetErrorStringResults err_string;
    SBIGUnivDrvCommand(CC_GET_ERROR_STRING, &err_query, &err_string);
    cerr << "SBIG Error (" << last_error_ << "): " << err_string.errorString
         << endl;
    error_callback_(command, last_error_);
    return false;
  }
  return true;
}
Exemplo n.º 6
0
int	main(int /* argc */, char * /* argv */[]) {
	printf("open driver\n");
	short	e = SBIGUnivDrvCommand(CC_OPEN_DRIVER, NULL, NULL);
	if (e != CE_NO_ERROR) {
		perror("cannot open driver", e);
		exit(EXIT_FAILURE);
	}

	printf("open device\n");
	OpenDeviceParams	openparams;
	openparams.deviceType = 0x7f02;
	e = SBIGUnivDrvCommand(CC_OPEN_DEVICE, &openparams, NULL);
	if (e != CE_NO_ERROR) {
		perror("cannot open device", e);
		exit(EXIT_FAILURE);
	}

	printf("establish link\n");
	EstablishLinkParams	establishparams;
	establishparams.sbigUseOnly = 0;
	EstablishLinkResults	results;
	e = SBIGUnivDrvCommand(CC_ESTABLISH_LINK, &establishparams, &results);
	if (e != CE_NO_ERROR) {
		perror("cannot establish link", e);
		exit(EXIT_FAILURE);
	}

	printf("get driver info\n");
	GetDriverInfoParams	driverinfoparams;
	driverinfoparams.request = 0;
	GetDriverInfoResults0	driverinfo;
	e = SBIGUnivDrvCommand(CC_GET_DRIVER_INFO, &driverinfoparams,
		&driverinfo);
	if (e != CE_NO_ERROR) {
		perror("cannot get driver info", e);
		exit(EXIT_FAILURE);
	}
	printf("driver: %s, version %04x\n", driverinfo.name,
		driverinfo.version);

	QueryTemperatureStatusParams    tempparams;
	QueryTemperatureStatusResults2  tempresults;
	tempparams.request = TEMP_STATUS_ADVANCED2;
	e = SBIGUnivDrvCommand(CC_QUERY_TEMPERATURE_STATUS,
		&tempparams, &tempresults);
	if (e != CE_NO_ERROR) {
		perror("cannot get temperature info", e);
		exit(EXIT_FAILURE);
	}
}
Exemplo n.º 7
0
int DisableTemperatureRegulation() 
{
    strp2.regulation = 0;
    err = SBIGUnivDrvCommand(CC_SET_TEMPERATURE_REGULATION2,&strp2, NULL);
    check_sbig_error(err,"Unable to disable temperature regulation\n");
    return(0);
}
Exemplo n.º 8
0
int FilterWheelPosition() 
{
    cfwp.cfwModel = CFWSEL_CFW402;
    cfwp.cfwCommand = CFWC_QUERY;
    err= SBIGUnivDrvCommand(CC_CFW, &cfwp, &cfwr); 
    return (cfwr.cfwPosition);
}
Exemplo n.º 9
0
int FilterWheelStatus()
{
    cfwp.cfwModel = CFWSEL_CFW402;
    cfwp.cfwCommand = CFWC_QUERY;
    err= SBIGUnivDrvCommand(CC_CFW, &cfwp, &cfwr); 
    return (cfwr.cfwStatus);
}
Exemplo n.º 10
0
int NumberOfFilters() 
{
    cfwp.cfwModel = CFWSEL_CFW402;
    cfwp.cfwCommand = CFWC_GET_INFO;
    err= SBIGUnivDrvCommand(CC_CFW, &cfwp, &cfwr); 
    return((int)cfwr.cfwResult2);
}
Exemplo n.º 11
0
int GetCameraStatus(int *image_status)
{
    ccd_image_status = IDLE;
    qcsp.command = CC_START_EXPOSURE;
    err = SBIGUnivDrvCommand(CC_QUERY_COMMAND_STATUS, &qcsp, &qcsr);
    check_sbig_error(err,"Unable to determine camera status.\n");

    switch ( qcsr.status&3 )
    {
	case CS_IDLE:
	    ccd_image_status = IDLE;  
	    break;

	case CS_IN_PROGRESS:
	    ccd_image_status = INTEGRATING;
	    break;

	case CS_INTEGRATING:
	    ccd_image_status = INTEGRATING;
	    break;

	case CS_INTEGRATION_COMPLETE:
	    ccd_image_status = COMPLETE;
	    break;
    }

    *image_status = ccd_image_status;
    return(0);
}
/**
 * \brief Query the state of the guider port.
 *
 * \returns a bit mask indicating the logical state of the four guider port
 * output relays.
 */
uint8_t	SbigGuiderPort::active() {
	SbigLock	lock;
	camera.sethandle();
	QueryCommandStatusParams	params;
	QueryCommandStatusResults	results;
	params.command = CC_ACTIVATE_RELAY;
	short	e = SBIGUnivDrvCommand(CC_QUERY_COMMAND_STATUS,
		&params, &results);
	if (e != CE_NO_ERROR) {
		debug(LOG_ERR, DEBUG_LOG, 0, "cannot activate relays: %s",
			sbig_error(e).c_str());
		throw SbigError(e);
	}
	uint8_t	result = 0;
	if (results.status & 0x8) {
		result |= RAPLUS;
	}
	if (results.status & 0x4) {
		result |= RAMINUS;
	}
	if (results.status & 0x2) {
		result |= DECPLUS;
	}
	if (results.status & 0x1) {
		result |= DECMINUS;
	}
	return result;
}
Exemplo n.º 13
0
void	perror(const char *errormsg, short errorcode) {
	GetErrorStringParams    params;
	params.errorNo = errorcode;
	GetErrorStringResults   results;

	SBIGUnivDrvCommand(CC_GET_ERROR_STRING, &params, &results);
	fprintf(stderr, "%s: %s\n", errormsg, results.errorString);
}
Exemplo n.º 14
0
int SetFilter(CFW_POSITION pos) 
{
    cfwp.cfwModel = CFWSEL_CFW402;
    cfwp.cfwCommand = CFWC_GOTO;
    cfwp.cfwParam1 = pos;
    // R = CFWP_1, G = CFWP_2, B = CFWP_3, Clear = CFWP_4
    err= SBIGUnivDrvCommand(CC_CFW, &cfwp, &cfwr); 
    return(err);
}
Exemplo n.º 15
0
int RegulateTemperature(double sp) 
{
    ccd_camera_info[active_camera].setpoint=sp;
    strp2.ccdSetpoint = sp;
    strp2.regulation = 1;
    err = SBIGUnivDrvCommand(CC_SET_TEMPERATURE_REGULATION2,&strp2, NULL);
    check_sbig_error(err,"Unable to regulate camera\n");
    ccd_camera_info[active_camera].setpoint = sp;
    return(0);
}
Exemplo n.º 16
0
int GetCameraTemperature()
{
    qtsp.request=2;
    err = SBIGUnivDrvCommand(CC_QUERY_TEMPERATURE_STATUS,&qtsp,&qtsr2);
    check_sbig_error(err,"Unable to get temperature information\n");
    ccd_camera_info[active_camera].power = qtsr2.imagingCCDPower;
    ccd_camera_info[active_camera].temperature = qtsr2.imagingCCDTemperature;
    ccd_camera_info[active_camera].ambientTemperature = qtsr2.ambientTemperature;
    ccd_camera_info[active_camera].setpoint = qtsr2.ccdSetpoint;
    return(0);
}
Exemplo n.º 17
0
int DisconnectAllCameras()
{
    for (int i=0;i<ccd_ncam;i++)
    {
        err = SetActiveCamera(i);
    
        err = SBIGUnivDrvCommand(CC_CLOSE_DEVICE, NULL, NULL);
        if (err != CE_NO_ERROR )
        {
            fprintf (stderr, "SBIG close device error\n");
        }
       
        err = SBIGUnivDrvCommand(CC_CLOSE_DRIVER, NULL, NULL);
        if ( err != CE_NO_ERROR ) 
        {
            fprintf (stderr, "SBIG close driver error\n");
        } 
    }

    return(0); 
}
Exemplo n.º 18
0
int SetActiveCamera(int camnum) {
    active_camera = camnum;
    ccd_image_name = ccd_camera_info[camnum].name;
    ccd_serial_number = ccd_camera_info[camnum].serial_number;
    ccd_camera_type = ccd_camera_info[camnum].camera_type;
    ccd_image_width = ccd_camera_info[camnum].width;
    ccd_image_height = ccd_camera_info[camnum].height;
    ccd_image_gain= ccd_camera_info[camnum].gain;
    sdhp.handle = ccd_camera_info[camnum].handle;

    err = SBIGUnivDrvCommand(CC_SET_DRIVER_HANDLE,&sdhp, NULL);
    if (verbosity)
        fprintf(stderr,"Activating camera with %d x %d format\n",ccd_image_width,ccd_image_height);
    check_sbig_error(err,"Unable to get handle to camera\n");
    return(0);
}
/**
 * \brief Control guider port relays.
 *
 * The parameters indicate which ports have to be enabled for how long
 * (in seconds). 
 * \param raplus	how long to turn on the RA+ output
 * \param raminus	how long to turn on the RA- output
 * \param decplus	how long to turn on the DEC+ output
 * \param decminus	how long to turn on the DEC- output
 */
void	SbigGuiderPort::activate(float raplus, float raminus,
	float decplus, float decminus) {
	SbigLock	lock;
	camera.sethandle();
	ActivateRelayParams	params;
	params.tXPlus = raplus * 100;
	params.tXMinus = raminus * 100;
	params.tYPlus = decplus * 100;
	params.tYMinus = decminus * 100;
	short	e = SBIGUnivDrvCommand(CC_ACTIVATE_RELAY, &params, NULL);
	if (e != CE_NO_ERROR) {
		debug(LOG_ERR, DEBUG_LOG, 0, "cannot activate relays: %s",
			sbig_error(e).c_str());
		throw SbigError(e);
	}
}
Exemplo n.º 20
0
int InitializeCamera(int camnum){

    int info_mode = 0;
    SBIG_DEVICE_TYPE usb;

    switch (camnum) {
	case 0:
	    usb = DEV_USB1;
	    break;
	case 1:
	    usb = DEV_USB2;
	    break;
	case 2:
	    usb = DEV_USB3;
	    break;
	case 3:
	    usb = DEV_USB4;
	    break;
	default:
	    fprintf(stderr,"Cannot assign camera.");
	    return(1);
	    break;
    }


    if (verbosity)
	fprintf(stdout,"Initializing camera %d\n",camnum);

    // Load driver
    err = SBIGUnivDrvCommand(CC_OPEN_DRIVER, NULL, NULL);
    check_sbig_error(err,"Error opening camera driver\n");

    // Open the device
    odp.deviceType = usb;
    err = SBIGUnivDrvCommand(CC_OPEN_DEVICE, &odp, NULL);
    check_sbig_error(err,"Error opening device\n");

    // Connect to the device
    elp.sbigUseOnly = 0;
    err = SBIGUnivDrvCommand(CC_ESTABLISH_LINK, &elp, &elr);
    check_sbig_error(err,"Link to camera could not be established\n");

    // Get handle for the device
    err = SBIGUnivDrvCommand(CC_GET_DRIVER_HANDLE, NULL, &gdhr);
    check_sbig_error(err,"Could not get driver handle\n");

    // Get camera information
    gip.request = CCD_INFO_IMAGING;
    err = SBIGUnivDrvCommand(CC_GET_CCD_INFO, &gip, &info_results_main);
    check_sbig_error(err,"Camera information could not be determined\n");

    // Get camera serial number
    gip.request = CCD_INFO_EXTENDED;
    err = SBIGUnivDrvCommand(CC_GET_CCD_INFO, &gip, &info_results_extended);
    check_sbig_error(err,"Extended camera information could not be determined\n");

    // Store camera info
    strcpy(ccd_camera_info[camnum].name,info_results_main.name);
    strcpy(ccd_camera_info[camnum].serial_number,info_results_extended.serialNumber);
    ccd_camera_info[camnum].camera_type = info_results_main.cameraType;
    ccd_camera_info[camnum].width = info_results_main.readoutInfo[info_mode].width;
    ccd_camera_info[camnum].height = info_results_main.readoutInfo[info_mode].height;
    ccd_camera_info[camnum].gain = info_results_main.readoutInfo[info_mode].gain;
    ccd_camera_info[camnum].handle  = gdhr.handle;

    // Get camera status
    err=GetCameraStatus(&ccd_image_status);
    check_sbig_error(err,"Unable to get camera status\n");
 
    switch (ccd_image_status) {
	case IDLE:
	    if (verbosity) printf("Camera %d is idle.\n",camnum);
	    break;
	case INTEGRATING:
	    if (verbosity) printf("Camera %d is integrating.\n",camnum);
	    break;
	case COMPLETE:
	    if (verbosity) printf("Exposure %d is complete.\n",camnum);
	    break;
	default:
	    fprintf(stderr,"Camera status is indeterminate.\n");
	    return(1); 
	    break;
    }

    // Free the handle. This allows access to other cameras. If we're
    // on the last camera don't free the handle, as no new handle can
    // be assigned... we're at the limit of 4 cameras. Here is how
    // the procedure is explained in the SBIG Universal Driver documentation: 
    //
    // "Each time you call Set Driver Handle with INVALID_HANDLE_VALUE 
    // you are allowing access to an additional camera up to a maximum 
    // of four cameras."

    if (camnum < 3) {
        sdhp.handle = INVALID_HANDLE_VALUE;
        err = SBIGUnivDrvCommand(CC_SET_DRIVER_HANDLE,&sdhp, NULL);

        char errstring[128];
        sprintf(errstring,"Unable to free handle after accessing camera %d\n",camnum);
        check_sbig_error(err,errstring);
    }

    return(0);

}
Exemplo n.º 21
0
int CaptureImage(int *phase,  unsigned short *data,
        int frame, double exposure, int subarea, 
        int x, int y, int width, int height)
{ 
    int i;

    ccd_phase = *phase;

    if ( ccd_phase == 2 )
    {

        /* End an exposure without readout */

        eep.ccd = CCD_IMAGING;
        mcp.fanEnable = TRUE;           /* Fan on */
        mcp.shutterCommand = 2;         /* Shutter closed */
        mcp.ledState = 0;               /* LED off */
        err=SBIGUnivDrvCommand(CC_MISCELLANEOUS_CONTROL, &mcp, NULL);
        err=SBIGUnivDrvCommand(CC_END_EXPOSURE, &eep, NULL);
        ccd_phase = 0;
        *phase = ccd_phase;
        if (err != CE_NO_ERROR)  
        {
            fprintf(stderr,"Error ending image exposure for camera %d\n",active_camera);
            return(1);
        }
        return(0);
    }

    if ( ccd_phase == 0 )
    { 

        /* Send start request to the camera */

        sep2.ccd = CCD_IMAGING;
        sep2.readoutMode = 0;
        sep2.abgState = ABG_LOW7;
        if ( ( frame == LIGHT ) | (frame == FLAT) )
        {  
            /* Shutter open */
            sep2.openShutter =  SC_OPEN_SHUTTER;
        }
        else if ( ( frame == DARK ) | (frame == BIAS ) )
        {
            /* Shutter closed */
            sep2.openShutter =  SC_CLOSE_SHUTTER;
        }
        else
        {
            fprintf(stderr,"Unknown frame type requested in CaptureImage for camera %d\n",active_camera);
            return(1);
        }
        sep2.exposureTime = (int)(100.0*exposure + 0.5);
        sep2.top = 0;
        sep2.left = 0;
        sep2.height = ccd_image_height;
        sep2.width = ccd_image_width;
        if (verbosity) fprintf(stderr,"Calling CC_START_EXPOSURE2\n");
        err=SBIGUnivDrvCommand(CC_START_EXPOSURE2, &sep2, NULL);   
        if (verbosity) fprintf(stderr,"Finished calling CC_START_EXPOSURE2\n");
        check_sbig_error(err,"Request to start camera exposure ignored\n");
        if (verbosity)
            fprintf(stderr,"Exposure started on camera %d\n",active_camera);

        /* Return indicating succesful start and  exposure in progress */

        ccd_phase = 1;
        *phase = ccd_phase;
        return(0);
    }   

    if ( ccd_phase != 1 )
    {
        /* We have already handled all allowed values except 1 */
        /* Reset phase to 0.  This permits recursive calls */
        ccd_phase = 0;
        *phase = ccd_phase;
        return(0) ;
    }

    /* Are we done yet? */
    /* If so, read it, if not reset phase and return */

    GetCameraStatus(&ccd_image_status);

    if ( ccd_image_status != COMPLETE )
    {
        /* The exposure is still underway */
        fprintf(stderr,"Exposure is already in progress on camera %d.\n",active_camera);
        ccd_phase = 1;
        *phase = ccd_phase;
        return(0);
    }  

    /* Test for subarea request */
    /* If not subarea, then default to driver's values for ccd dimensions */
    /* If subarea, then check validity and clamp to allowed bounds */

    if (subarea == FALSE)
    {
        x = 0;
        y = 0;
        width = ccd_image_width;
        height = ccd_image_height;
    }  
    else 
    {
        if (x < 0)
        {
            x = 0;
        }
        if (y < 0)
        {
            y = 0;
        }
        if (x > ccd_image_width  )
        {
            x = ccd_image_width;
        }
        if (y > ccd_image_height )
        {
            y = ccd_image_height;
        }
    }          

    /* Flush the buffers */
    /* This probably isn't necessary.  It's a carryover from earlier versions. */

    fflush(stdout);
    fflush(stderr);
    sync();

    /* End the exposure */

    eep.ccd = CCD_IMAGING;
    srp.ccd = CCD_IMAGING;
    rlp.ccd = CCD_IMAGING;
    erp.ccd = CCD_IMAGING;

    err=SBIGUnivDrvCommand(CC_END_EXPOSURE, &eep, NULL);
    if ( err != CE_NO_ERROR ) 
    {
        return(1);
    } 

    /* Prepare to read the image */

    sync();
    fflush(stdout);

    /* Read it */

    if (verbosity)
        fprintf(stderr,"Reading out camera %d... ",active_camera);
    srp.readoutMode =  0;
    srp.top = y;
    srp.left = x;
    srp.width = width;
    srp.height = height; 

    if (verbosity)
        fprintf(stderr,"Sending CC_START_READOUT to camera %d... ",active_camera);
    err = SBIGUnivDrvCommand(CC_START_READOUT, &srp, NULL);
    check_sbig_error(err,"Error reading out device\n");

    for (i = 0; i < srp.height; ++i) 
    {
        rlp.readoutMode = 0;
        rlp.pixelStart = x;
        rlp.pixelLength = width;
        //if (verbosity)
        //    fprintf(stderr,"Sending CC_READOUT_LINE line %d/%d to camera %d\n",i+1,srp.height,active_camera);
        err = SBIGUnivDrvCommand(CC_READOUT_LINE, &rlp, data + i*width);
        if (err != CE_NO_ERROR) 
        {
            fprintf(stderr,"Unable to read image data from camera %d\n",active_camera);
            ccd_phase = 0;
            *phase = ccd_phase;
            return(1);
        }
    }
    fprintf(stderr,"Readout successful on camera %d\n",active_camera);

    /* Successful readout. Send the End Readout command to the camera. */
    err = SBIGUnivDrvCommand(CC_END_READOUT, &erp, NULL);
    if (err != CE_NO_ERROR) 
    {
        fprintf(stderr,"Unable to end readout from camera %d\n",active_camera);
        ccd_phase = 2;
        *phase = ccd_phase;
        return(1);
    }


    /* Indicate that a new image is available */
    if (verbosity)
        fprintf(stderr,"finished\n");
    ccd_phase = 2;
    *phase = ccd_phase;  
    return(0);
}