~ubuntu-branches/ubuntu/lucid/libapogee2/lucid

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include <time.h>
#include "ApnCamera.h"


int main()
{
	CApnCamera *ApogeeCamera;			// Camera interface
	
	int	 	hr;				// Return code 
	FILE*		filePtr;			// File pointer 
	unsigned short	NumTdiRows;			// Number of images to take
	double		TdiRate;			// TDI rate (in seconds)
	unsigned short* pBuffer;
	unsigned long	ImgSizeBytes;
	char		szFilename[80];			// File name


	printf( "Apogee Alta Bulk TDI Sample Applet\n" );


	// Create the CApnCamera object
	ApogeeCamera = (CApnCamera *)new CApnCamera();


	// Initialize camera using the default properties
	hr = ApogeeCamera->InitDriver( 1,0,0 );

	if ( hr )
	{
		printf( "Connection to camera succeeded.\n" );
	}
	else
	{
		printf( "Failed to connect to camera" );
		
		ApogeeCamera	= NULL;		// Release CApnCamera object
		exit(1);
	}

/*      Do a system reset to ensure known state, flushing enabled etc */
        ApogeeCamera->ResetSystem();


	printf("Current CCD temperature : %f\n",ApogeeCamera->read_TempCCD());


	// Query user for number of TDI rows
	printf( "Number of TDI Rows:  " );
	scanf( "%d", &NumTdiRows );
	printf( "Image to contain %d rows.\n", NumTdiRows );

	// Query user for TDI rate
	printf( "Interval between rows (TDI rate):  " );
	scanf( "%lf", &TdiRate );
	printf( "TDI rate set to %lf seconds.\n", TdiRate );

	// Set the TDI row count
	ApogeeCamera->write_TDIRows (NumTdiRows);

	// Set the TDI rate
	ApogeeCamera->write_TDIRate (TdiRate);

	// Toggle the camera mode for TDI
	ApogeeCamera->write_CameraMode (Apn_CameraMode_TDI);

	// Toggle the sequence download variable
	ApogeeCamera->write_SequenceBulkDownload (true);
	
	// Set the image size
	long ImgXSize = ApogeeCamera->m_ApnSensorInfo->m_ImagingColumns;
	long ImgYSize = NumTdiRows;		// Since SequenceBulkDownload = true

	// Display the camera model
//	_bstr_t szCamModel( ApogeeCamera->CameraModel );
//	printf( "Camera Model:  %s\n", (char*)szCamModel );
	
	// Display the driver version
//	_bstr_t szDriverVer( ApogeeCamera->DriverVersion );
//	printf( "Driver Version:  %s\n", (char*)szDriverVer );

	// Create a buffer for one image, which will be reused for
	// each image in the sequence
	pBuffer		= new unsigned short[ ImgXSize * ImgYSize];
	ImgSizeBytes	= ImgXSize * ImgYSize * 2;

	// Initialize the output file
	sprintf( szFilename, "BulkTdiData.raw" );
	filePtr = fopen( szFilename, "wb" );
	if ( filePtr == NULL )
	{
		printf( "ERROR:  Failed to open output file.  No file will be written." );
	}

	// Do a sequence of 0.001s dark frames (bias frames)
	printf( "Starting camera exposure...\n" );
	ApogeeCamera->Expose( 0.1, true );

	// Check camera status to make sure image data is ready
	while ( ApogeeCamera->read_ImagingStatus() != Apn_Status_ImageReady );

	// Get the image data from the camera
	printf( "Retrieving image data from camera...\n" );
	ApogeeCamera->GetImage( pBuffer );

	if ( filePtr == NULL )
	{
		printf( "ERROR:  Failed to open file for writing output data." );
	}
	else
	{
		printf( "Writing line data to output file \"%s...\"\n", szFilename );

		fwrite( pBuffer, sizeof(unsigned short), (ImgSizeBytes/2), filePtr );
	}

	// Close the file
	if ( filePtr != NULL )
	{
		printf( "Closing output file.\n" );
		fclose( filePtr );
	}

	ApogeeCamera->CloseDriver();
	delete ApogeeCamera;		// Release CApnCamera COM object

	// Delete the memory buffer for storing the image
	delete [] pBuffer;

	
	exit(0);


}