The following program demonstrates how to open a driver to a single PCI
board, setup the controller, start an exposure, keep track of the read
progress, write the image data to a FITS file, and then close the driver
using the Expose and Readout callback methods of the CController class.
NOTE: The SetDots function is purely for producing a visual effect when
displaying the output to the user.
#include <iostream>
#include <iomanip>
#include "CController.h"
#include "CDeinterlace.h"
#include "CFitsFile.h"
using namespace std;
using namespace arc;
//
// Camera specific data (dsp file, dimensions, expose time)
//
#define TIM_FILE "tim.lod"
#define EXP_TIME ( float )5.0
#define IMG_ROWS 512
#define IMG_COLS 600
void ExposeCallback( float fElapsedTime );
void ReadoutCallback( long pixelCount );
std::string SetDots( const char *cStr );
//
// Main program
//
int main()
{
//
// Create an instance of the ARC controller API
//
CController cController;
cout << endl;
try
{
//
// Find all ARC pci device
//
cout << SetDots( "Getting device bindings" );
cController.GetDeviceBindings();
cout << "done!" << endl;
//
// Open a driver/device connection
//
cout << SetDots( "Opening PCI driver" );
cController.OpenDriver( 0, 4200 * 4200 * sizeof( unsigned short ) );
cout << "done!" << endl;
//
// Setup the controller
//
cout << SetDots( "Setting up controller" );
cController.SetupController( true, // Reset Controller
true, // Test Data Link ( TDL )
true, // Power On
IMG_ROWS, // Image row size
IMG_COLS, // Image col size
TIM_FILE ); // DSP timing file
cout << "done!" << endl;
//
// Expose
//
cout << "Starting exposure ...." << endl;
cController.Expose( EXP_TIME,
IMG_ROWS,
IMG_COLS,
NULL,
ExposeCallback,
ReadoutCallback );
cout << endl;
//
// Deinterlace the image
//
cout << SetDots( "Deinterlacing image" );
CDeinterlace cDeint;
cDeint.RunAlg( cController.mapFd,
IMG_ROWS,
IMG_COLS,
CDeinterlace::DEINTERLACE_CCD_QUAD );
cout << "done!" << endl;
//
// Save the image to FITS
//
cout << SetDots( "Writing FITS" );
CFitsFile cFits( "Image.fit", IMG_ROWS, IMG_COLS );
cFits.Write( cController.mapFd );
cout << "done!" << endl;
//
// Close the driver/device connection
//
cout << SetDots( "Closing PCI driver" );
cController.CloseDriver();
cout << "done!" << endl;
}
catch ( std::runtime_error &e )
{
cout << "failed!" << endl;
cerr << endl << e.what() << endl;
cController.CloseDriver();
}
catch ( ... )
{
cerr << endl << "Error: unknown exception occurred!!!" << endl;
cController.CloseDriver();
}
}
std::string SetDots( const char *cStr )
{
std::string sStr( cStr );
for ( int i=sStr.length(); i<40; i++ )
sStr.append( "." );
return sStr;
}
void ExposeCallback( float fElapsedTime )
{
cout << SetDots( "Elapsed Time" ) << setfill( '0' )
<< setw( 4 ) << fElapsedTime << '\r';
}
void ReadoutCallback( long lPixelCount )
{
cout << SetDots( "Pixels Read" ) << setfill( '0' )
<< setw( 8 ) << lPixelCount << '\r';
}