forked from atsommer/Simplicio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSC2Driver.cpp
More file actions
207 lines (190 loc) · 5.62 KB
/
Copy pathSC2Driver.cpp
File metadata and controls
207 lines (190 loc) · 5.62 KB
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
#include "stdafx.h"
#include "SC2Driver.h"
namespace forms2{
using namespace System;
using namespace System::Windows::Forms;
SC2Driver::SC2Driver(void){
//mode = NULL_SETTING;
//trig = NULL_SETTING;
roix1 = NULL_SETTING;
roix2 = NULL_SETTING;
roiy1 = NULL_SETTING;
roiy2 = NULL_SETTING;
hbin = NULL_SETTING;
vbin = NULL_SETTING;
sBufNr = -1;
hDialog= NULL;
strGeneral.wSize = sizeof(strGeneral);// initialize all structure size members
strGeneral.strCamType.wSize = sizeof(strGeneral.strCamType);
strCamType.wSize = sizeof(strCamType);
strSensor.wSize = sizeof(strSensor);
strSensor.strDescription.wSize = sizeof(strSensor.strDescription);
strDescription.wSize = sizeof(strDescription);
strTiming.wSize = sizeof(strTiming);
strStorage.wSize = sizeof(strStorage);
strRecording.wSize = sizeof(strRecording);
strImage.wSize = sizeof(strImage);
strImage.strSegment[0].wSize = sizeof(strImage.strSegment[0]);
strImage.strSegment[1].wSize = sizeof(strImage.strSegment[0]);
strImage.strSegment[2].wSize = sizeof(strImage.strSegment[0]);
strImage.strSegment[3].wSize = sizeof(strImage.strSegment[0]);
}
int SC2Driver::initCamera(){
//HANDLE hCam;
hCam = NULL;
int iRetCode = PCO_OpenCamera(&hCam, 0);// Try to open camera
if (iRetCode != PCO_NOERROR)
{
disconnected();
MessageBox::Show( String::Concat("No camera detected or other initialization error."),"Box",MessageBoxButtons::OK);
return INIT_ERROR;
}
else // if successfull...
{
iRetCode = PCO_GetGeneral(hCam, &strGeneral);// Get infos from camera
if (iRetCode != PCO_NOERROR)
{
disconnected();
return INIT_ERROR;
}
iRetCode = PCO_GetCameraType(hCam, &strCamType);
if (iRetCode != PCO_NOERROR)
{
disconnected();
return INIT_ERROR;
}
iRetCode = PCO_GetSensorStruct(hCam, &strSensor);
if (iRetCode != PCO_NOERROR)
{
disconnected();
return INIT_ERROR;
}
iRetCode = PCO_GetCameraDescription(hCam, &strDescription);
if (iRetCode != PCO_NOERROR)
{
disconnected();
return INIT_ERROR;
}
iRetCode = PCO_GetTimingStruct(hCam, &strTiming);
if (iRetCode != PCO_NOERROR)
{
disconnected();
return INIT_ERROR;
}
iRetCode = PCO_GetRecordingStruct(hCam, &strRecording);
if (iRetCode != PCO_NOERROR)
{
disconnected();
return INIT_ERROR;
}
}
/*
if (strCamType.wCamType == CAMERATYPE_PCO_USBPIXELFLY)
MessageBox::Show("Pixelfly.usb detected","Box",MessageBoxButtons::OK);
*/
return 0;
}
void SC2Driver::disconnected(){
//connection to camera was lost
}
int SC2Driver::openCameraDialog(){
PCO_CloseDialogCam(hDialog);
HWND hmain = 0;
int err = PCO_OpenDialogCam(&hDialog, hCam, 0, 0,0, 0, 400, 300, "SC2 Camera control window");
return err;
}
void SC2Driver::lockCameraDialog(bool lock){
PCO_EnableDialogCam(hDialog, !lock);
}
void SC2Driver::closeCamera(){
PCO_CloseCamera(hCam);
}
void SC2Driver::expose(){
DWORD wImage=0;
PCO_AddBuffer(hCam, wImage, wImage, sBufNr);
}
void SC2Driver::stop(){
PCO_SetRecordingState(hCam, 0x0000);
PCO_CancelImages(hCam);
//PCO_FreeBuffer(hCam, sBufNr);
}
int SC2Driver::getImageStatus(){
//return Driver::CAMERA_IDLE;
DWORD err = WaitForSingleObject(hEvent, 2000);
//return Driver::CAMERA_IDLE;
DWORD statDLL, statDrv;
err = PCO_GetBufferStatus(hCam, sBufNr, &statDLL, &statDrv);
if (err){
String^ layerStr;
if (err & PCO_ERROR_FIRMWARE) layerStr = gcnew String("Firmware");
else if (err & PCO_ERROR_DRIVER) layerStr = gcnew String("Driver");
else if (err & PCO_ERROR_SDKDLL) layerStr = gcnew String("SDK-dll");
else if (err & PCO_ERROR_APPLICATION) layerStr= gcnew String("application");
//MessageBox::Show(String::Concat("Layer: ",layerStr),"Box",MessageBoxButtons::OK);
char errorText[1000];
PCO_GetErrorText(err, errorText, 1000);
MessageBox::Show(String::Concat(gcnew String(errorText)," sBufNr = ",(int) sBufNr),"Box",MessageBoxButtons::OK);
return Driver::IMAGE_ERROR;
}
if (statDLL)// & (0x40000000 | 0x00008000))
return Driver::CAMERA_IDLE;
else
return Driver::CAMERA_BUSY;
}
int SC2Driver::getImageWidth(){
return getCols();
}
int SC2Driver::getImageHeight(){
int dbl = isDouble() ? 2 : 1;
return getRows()*dbl;
}
void SC2Driver::readImage(UInt16 *buffer){
}
int SC2Driver::armCamera(){
PCO_ArmCamera(hCam);
sBufNr = -1;//allocate a new buffer
DWORD size = getRows()*getCols()*isDouble()*sizeof(WORD);
//wBuf;//pointer to image data, wBuf[0...size]
//HANDLE hEvent;
PCO_FreeBuffer(hCam, 0);
int err = PCO_AllocateBuffer(hCam, &sBufNr, size,&wBuf ,&hEvent);
if (err){
char errorText[1000];
PCO_GetErrorText(err, errorText, 1000);
MessageBox::Show(String::Concat(gcnew String(errorText)," sBufNr = ",(int) sBufNr),"Box",MessageBoxButtons::OK);
}
//setRecordingstate, Addbuffer
PCO_SetRecordingState(hCam, 0x0001);
//DWORD wImage=0;
//PCO_AddBuffer(hCam, wImage, wImage, sBufNr);
PCO_CamLinkSetImageParameters(hCam, getImageWidth(), getImageHeight());
PCO_SetStorageMode(hCam, 1);
return 0;
}
//settings
int SC2Driver::getRows(){
getSettings();
return roiy2-roiy1 + 1;
}
int SC2Driver::getCols(){
getSettings();
return roix2-roix1+1;
}
bool SC2Driver::isDouble(){
WORD dbl;
int err = PCO_GetDoubleImageMode(hCam, &dbl);
if (dbl) return true;
else return false;
}
void SC2Driver::update(){
}
void SC2Driver::getSettings(){
WORD x1, x2, y1, y2;
//PCO_GetROI(hCam, &roix1, &roiy1, &roix2, &roiy2);
PCO_GetROI(hCam, &x1, &y1, &x2, &y2);
roix1 = (int) x1;
roix2 = (int) x2;
roiy1 = (int) y1;
roiy2 = (int) y2;
}
}