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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
// ApnCamera_USB.cpp: implementation of the CApnCamera_USB class.
//
// Copyright (c) 2003, 2004 Apogee Instruments, Inc.
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ApnCamera_USB.h"
#include "ApogeeUsb.h"
#include "ApogeeUsbErr.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
bool CApnCamera::InitDriver( unsigned long CamIdA,
unsigned short /*CamIdB*/,
unsigned long /*Option*/ )
{
if ( ApnUsbOpen( (unsigned short)CamIdA ) != APN_USB_SUCCESS )
{
return false;
}
m_CameraInterface = Apn_Interface_USB;
// Before trying to initialize, perform a simple loopback test
unsigned short RegData;
unsigned short NewRegData;
RegData = 0x5AA5;
if ( Write( FPGA_REG_SCRATCH, RegData ) != APN_USB_SUCCESS ) return false;
if ( Read( FPGA_REG_SCRATCH, NewRegData ) != APN_USB_SUCCESS ) return false;
if ( RegData != NewRegData ) return false;
RegData = 0xA55A;
if ( Write( FPGA_REG_SCRATCH, RegData ) != APN_USB_SUCCESS ) return false;
if ( Read( FPGA_REG_SCRATCH, NewRegData ) != APN_USB_SUCCESS ) return false;
if ( RegData != NewRegData ) return false;
// The loopback test was successful. Proceed with initialization.
if ( InitDefaults() != 0 )
return false;
return true;
}
bool CApnCamera::CloseDriver()
{
ApnUsbClose();
return true;
}
void CApnCamera::SetNetworkTransferMode( Apn_NetworkMode /*TransferMode*/ )
{
return;
}
bool CApnCamera::GetImageData( unsigned short *pImageBuffer,
unsigned short &Width,
unsigned short &Height,
unsigned long &Count )
{
unsigned short Offset(0);
unsigned short *pTempBuffer;
long i, j;
// Make sure it is okay to get the image data
// The app *should* have done this on its own, but we have to make sure
while ( !ImageReady() )
{
Sleep( 50 );
read_ImagingtqStatus();
}
Width = m_pvtWidth;
Height = m_pvtHeight;
if ( m_pvtBitsPerPixel == 16 )
Offset = 1;
if ( m_pvtBitsPerPixel == 12 )
Offset = 10;
Width -= Offset; // Calculate the true image width
pTempBuffer = new unsigned short[(Width+Offset) * Height];
ApnUsbGetImage( pTempBuffer );
for ( i=0; i<Height; i++ )
{
for ( j=0; j<Width; j++ )
{
pImageBuffer[(i*Width)+j] = pTempBuffer[(i*(Width+Offset))+j+Offset];
}
}
delete [] pTempBuffer;
Count = read_ImageCount();
SignalImagingDone();
return true;
}
bool CApnCamera::GetLineData( unsigned short */*pLineBuffer*/,
unsigned short &Size )
{
Size = 0;
return false;
}
long CApnCamera::PreStartExpose( unsigned short BitsPerPixel )
{
m_pvtWidth = GetExposurePixelsH();
m_pvtHeight = GetExposurePixelsV();
if ( (BitsPerPixel != 16) && (BitsPerPixel != 12) )
{
// Invalid bit depth request
return 1;
}
m_pvtBitsPerPixel = BitsPerPixel;
if ( BitsPerPixel == 16 )
m_pvtWidth += 1;
if ( BitsPerPixel == 12 )
m_pvtWidth += 10;
if ( ApnUsbStartExp( m_pvtWidth, m_pvtHeight ) != APN_USB_SUCCESS )
{
return 1;
}
return 0;
}
long CApnCamera::PostStopExposure( bool DigitizeData )
{
PUSHORT pRequestData;
if ( !DigitizeData )
{
while ( !ImageReady() )
{
Sleep( 50 );
read_ImagingtqStatus();
}
pRequestData = new USHORT[m_pvtWidth*m_pvtHeight];
ApnUsbGetImage( pRequestData );
delete [] pRequestData;
SignalImagingDone();
}
// The following code will eventually be the implementation of the STOP
// command for USB. Currently, this does not work correctly.
// if ( ApnUsbStopExp( DigitizeData ) != APN_USB_SUCCESS )
// {
// return 1;
// }
return 0;
}
long CApnCamera::Read( unsigned short reg, unsigned short& val )
{
if ( ApnUsbReadReg( reg, &val ) != APN_USB_SUCCESS )
{
return 1; // Failure
}
return 0;
}
long CApnCamera::Write( unsigned short reg, unsigned short val )
{
if ( ApnUsbWriteReg( reg, val ) != APN_USB_SUCCESS )
{
return 1; // Failure
}
return 0;
}
long CApnCamera::WriteMultiSRMD( unsigned short reg, unsigned short val[], unsigned short count )
{
if ( ApnUsbWriteRegMulti( reg, val, count ) != APN_USB_SUCCESS )
{
return 1;
}
return 0;
}
long CApnCamera::WriteMultiMRMD( unsigned short reg[], unsigned short val[], unsigned short count )
{
if ( ApnUsbWriteRegMultiMRMD( reg, val, count ) != APN_USB_SUCCESS )
{
return 1;
}
return 0;
}
long CApnCamera::QuerytqStatusRegs( unsigned short& tqStatusReg,
unsigned short& HeatsinkTempReg,
unsigned short& CcdTempReg,
unsigned short& CoolerDriveReg,
unsigned short& VoltageReg,
unsigned short& TdiCounter,
unsigned short& SequenceCounter )
{
/*unsigned short stat,heat,ccdt,cool,volt,tdic,sequ;*/
if ( ApnUsbReadtqStatusRegs( &tqStatusReg,
&HeatsinkTempReg,
&CcdTempReg,
&CoolerDriveReg,
&VoltageReg,
&TdiCounter,
&SequenceCounter ) != APN_USB_SUCCESS )
{
return 1;
}
return 0;
}
|