areaDetector 3-14
EPICS areaDetector framework
pco_structures.h
Go to the documentation of this file.
1
9#ifndef PCO_STRUCTURES_H_
10#define PCO_STRUCTURES_H_
11
12#ifdef _WIN32
13 #include <windows.h>
14#endif
15
16// ------------------------------------------------------------------------ //
17// -- Defines for Get Camera Type Command: -------------------------------- //
18// ------------------------------------------------------------------------ //
19
20// pco.camera types
21#define CAMERATYPE_PCO1200HS 0x0100
22#define CAMERATYPE_PCO1300 0x0200
23#define CAMERATYPE_PCO1600 0x0220
24#define CAMERATYPE_PCO2000 0x0240
25#define CAMERATYPE_PCO4000 0x0260
26
27// pco.1300 types
28
37 public:
38
39 /*
40 * Constructor for a new single binary command to camera.
41 */
42
44
45 /*
46 * Set command code, as defined in PCO documentation. this is main command word.
47 */
48
49 void setCode(unsigned short cx) {
50 addr = 0;
51 code = cx;
52 // space for length.
53 length = (unsigned short *)data;
54 addUShort(0);
56 }
57
58 /*
59 * commands are created by adding data one word at a time. Add unsigned short to command.
60 */
61
62 void addUShort(unsigned short msg) {
63 unsigned short *ptr;
64 ptr = (unsigned short *)(data + addr);
65 *ptr = msg;
66 addr += 2;
68 };
69
70 /*
71 * add unsigned char to command
72 */
73
74 void addUChar(unsigned char msg) {
75 unsigned char *ptr;
76 ptr = (unsigned char *)(data + addr);
77 *ptr = msg;
78 addr += 1;
80 };
81
82 /*
83 * Add signed short to command.
84 */
85
86 void addShort(short msg) {
87 short *ptr;
88 ptr = (short *)(data + addr);
89 *ptr = msg;
90 addr += 2;
92 };
93
94 /*
95 * Add 32 but signed int to command.
96 */
97
98 void addLong(long msg) {
99 long *ptr;
100 ptr = (long *)(data + addr);
101 *ptr = msg;
102 addr += 4;
103 calcCheckSum();
104 };
105
106 /*
107 * Add unsigned int to the command.
108 */
109
110 void addULong(unsigned long msg) {
111 unsigned long *ptr;
112 ptr = (unsigned long *)(data + addr);
113 *ptr = msg;
114 addr += 4;
115 calcCheckSum();
116 };
117
118
119 /*
120 * Get raw data string into provided memory.
121 */
122
123 unsigned char *getData(void) { return ((unsigned char *)data); };
124
125 /*
126 * Get length of command in bytes. Return in provided memory.
127 */
128
129 unsigned short getLen(void) { return (*length); };
130
131 /*
132 * Get main command code from the binary command.
133 */
134
135 unsigned short getCode(void) { return (code); };
136
137 protected:
138 // code senyt to detector
139 unsigned short code;
140
141 unsigned short *length;
142 unsigned char *checksum;
143
144 char data[256];
145
146
147
148 /*
149 * Calc checksum to command to make it valid.
150 */
151
152 void calcCheckSum(void) {
153 int i;
154 int codelo;
155 int codehi;
156 // addr incl lenggm but not checksum or code
157 *length = addr + 2 + 1;
158 // addr where checksum is stored
159 checksum = (unsigned char *)data + addr;
160 totalsum = 0;
161 codelo = code & 255;
162 codehi = code & (255 * 256);
163 codehi = codehi / 256;
164 totalsum += codelo;
165 totalsum += codehi;
166
167 for (i = 0; i < addr; i++) totalsum += data[i];
168
169 *checksum = (unsigned char)(totalsum & 255);
170 };
171 int addr;
173};
174
181 public:
182
183 /*
184 * Create a new empty response message to be filled by camera serial port data.
185 */
186
188 addr = 0;
189 code = 0;
190 // space for length.
191 length = (unsigned short *)data;
192 addUShort(5);
193 };
194
195 /*
196 * Set main command code in the response.
197 */
198
199 void setCode(unsigned short cx) { code = cx; };
200
201 /*
202 * Set expected return resp. code from camera. camera should send this back.
203 */
204
205 void setExpCode(unsigned short cx) { exp_code = cx; };
206
207 /*
208 * Set error code in this response. camera will send back this code on err condition.
209 */
210
211 void setErrCode(unsigned short cx) { error_code = cx; };
212
213 /*
214 * Set length of response.
215 */
216
217 void setLength(unsigned short lx) {
218 *length = lx;
219 addr = *length - 2;
220 checksum = (unsigned char *)data + addr - 1;
221 };
222
223 /*
224 * Take binary string from serial port, and copy into this response obj for parsing.
225 */
226
227 void copy2Obj(unsigned char *obj, int len) {
228 int k;
229 for (k = 0; k < len; k++) {
230 obj[k] = data[k];
231 }
232 }
233
234 /*
235 * add unsigned char to message.
236 */
237
238 void addUChar(unsigned char msg) {
239 unsigned char *ptr;
240 ptr = (unsigned char *)(data + addr);
241 *ptr = msg;
242 addr += 1;
243 };
244
245 /*
246 * add string of uchars of len to this message.
247 */
248
249 void addUChar(unsigned char *msg, int len) {
250 int i;
251 for (i = 0; i < len; i++) addUChar(*(msg + i));
252 };
253
254 /*
255 * add single ushort to this message.
256 */
257
258 void addUShort(unsigned short msg) {
259 unsigned short *ptr;
260 ptr = (unsigned short *)(data + addr);
261 *ptr = msg;
262 addr += 2;
263 };
264
265 /*
266 * Add signed short to this message.
267 */
268
269 void addShort(short msg) {
270 short *ptr;
271 ptr = (short *)(data + addr);
272 *ptr = msg;
273 addr += 2;
274 };
275
276 /*
277 * Add signed 32 bit int to this message.
278 */
279
280 void addLong(long msg) {
281 long *ptr;
282 ptr = (long *)(data + addr);
283 *ptr = msg;
284 addr += 4;
285 };
286
287 /*
288 * Add unsigned int 32 bit to this message.
289 */
290
291 void addULong(unsigned long msg) {
292 unsigned long *ptr;
293 ptr = (unsigned long *)(data + addr);
294 *ptr = msg;
295 addr += 4;
296 };
297
298 /*
299 * Get a ushort out of message, and inc. internal counter, so we can get each part of message
300 * in sequence.
301 */
302
303 unsigned short getUShort(int adx) {
304 unsigned short *ptr;
305
306 ptr = (unsigned short *)(&data[adx]);
307 return (*ptr);
308 };
309
310
311 /*
312 * get short out of message, inc. internal counter.
313 */
314
315 short getShort(int adx) {
316 short *ptr;
317
318 ptr = (short *)(&data[adx]);
319 return (*ptr);
320 };
321
322
323 /*
324 * get unsigned char from message.
325 */
326
327 unsigned char getUChar(int adx) {
328 unsigned char *ptr;
329
330 ptr = (unsigned char *)(&data[adx]);
331 return (*ptr);
332 };
333
334 /*
335 * Get unsigned long from message.
336 */
337
338 unsigned long getULong(int adx) {
339 unsigned long *ptr;
340
341 ptr = (unsigned long *)(&data[adx]);
342 return (*ptr);
343 };
344
345 /*
346 * Print the contants of the message to screen.
347 */
348
349 void sprintHeader(char *strg) {
351 sprintf(strg, "code: 0x%x length: %d cks: 0x%x verified cks: 0x%x \n",
353 };
354
355 /*
356 * Get raw data string from message.
357 */
358
359 unsigned char *getData(void) { return ((unsigned char *)data); };
360 // data excluding length word
361 /*
362 *Get data string from message, starting 2 bytes from beginning. 1st 2 bytes are not useful.
363 */
364
365 unsigned char *getData2(void) { return (2 + (unsigned char *)data); };
366 /*
367 * get len of messave.
368 */
369
370 unsigned short getLen(void) { return (*length); };
371 /*
372 * Get comand code from message.
373 */
374
375 unsigned short getCode(void) { return (code); };
376 /*
377 * Get expected return code from message.
378 */
379
380 unsigned short getExpCode(void) { return (exp_code); };
381 /*
382 * Get any error code message.
383 */
384
385 unsigned short getErrCode(void) { return (error_code); };
386
387 /*
388 * Make sure checksum from camera is correct.
389 */
390
391 int verifyCheckSum(void) {
392 int i, codelo, codehi;
393 // checksum and length is included in address. not code.
394 verified_length = addr + 2;
395 // address where detector checksum is stored
396 checksum = (unsigned char *)data + addr - 1;
397 totalsum = 0;
398 codelo = code & 255;
399 codehi = code & (255 * 256);
400 codehi = codehi / 256;
401 totalsum += codelo;
402 totalsum += codehi;
403
404 // addr-1 because addr is the checksum, and it is not counted in checksum
405 for (i = 0; i < (addr - 1); i++) totalsum += data[i];
406
407 verified_chksm = (unsigned char)(totalsum & 255);
408
409 if (*length != verified_length) return 1;
410
411 if (*checksum != verified_chksm) return 2;
412
413 return 0;
414 };
415
416 protected:
417 int addr;
418 // code returne from the det.
419 unsigned short code;
420
421 // expected good code from det.
422 unsigned short exp_code;
423
424 // expected error code from det.
425 unsigned short error_code;
426
427 // length from detector
428 unsigned short *length;
429 // checksum from detector
430 unsigned char *checksum;
431 // pc figures out length and checksum we actaully got
432 // if different from what det sent we have errlr.
433 unsigned char verified_chksm;
434 unsigned short verified_length;
435
436 char data[256];
437
439};
440
441#ifndef _WIN32
442#define WORD unsigned short
443#define DWORD unsigned long
444#define SHORT short
445
446#endif
447
452 WORD wSize; // Sizeof this struct
453 WORD wSensorTypeDESC; // Sensor type
454 WORD wSensorSubTypeDESC; // Sensor subtype
455 WORD wMaxHorzResStdDESC; // Maxmimum horz. resolution in std.mode
456 WORD wMaxVertResStdDESC; // Maxmimum vert. resolution in std.mode // 10
457 WORD wMaxHorzResExtDESC; // Maxmimum horz. resolution in ext.mode
458 WORD wMaxVertResExtDESC; // Maxmimum vert. resolution in ext.mode
459 WORD wDynResDESC; // Dynamic resolution of ADC in bit
460 WORD wMaxBinHorzDESC; // Maxmimum horz. binning
461 WORD wBinHorzSteppingDESC; // Horz. bin. stepping (0:bin, 1:lin) // 20
462 WORD wMaxBinVertDESC; // Maxmimum vert. binning
463 WORD wBinVertSteppingDESC; // Vert. bin. stepping (0:bin, 1:lin)
464 WORD wRoiHorStepsDESC; // Minimum granularity of ROI in pixels
465 WORD wRoiVertStepsDESC; // Minimum granularity of ROI in pixels
466 WORD wNumADCsDESC; // Number of ADCs in system // 30
467
468 DWORD dwPixelRateDESC[4]; // Possible pixelrate in Hz // 48
469 // 128
470 WORD wConvFactDESC[4]; // Possible conversion factor in e/cnt // 136
471 // 176
472 WORD wIRDESC; // IR enhancment possibility
473
474 DWORD dwMinDelayDESC; // Minimum delay time in ns
475 DWORD dwMaxDelayDESC; // Maximum delay time in ms
476 DWORD dwMinDelayStepDESC; // Minimum stepping of delay time in ns // 192
477 DWORD dwMinExposureDESC; // Minimum exposure time in ns
478 DWORD dwMaxExposureDESC; // Maximum exposure time in ms // 200
479 DWORD dwMinExposureStepDESC; // Minimum stepping of exposure time in ns
480 DWORD dwMinDelayIRDESC; // Minimum delay time in ns
481 DWORD dwMaxDelayIRDESC; // Maximum delay time in ms // 212
482 DWORD dwMinExposureIRDESC; // Minimum exposure time in ns
483 DWORD dwMaxExposureIRDESC; // Maximum exposure time in ms // 220
484 WORD wTimeTableDESC; // Timetable for exp/del possibility
485 WORD wDoubleImageDESC; // Double image mode possibility
486 SHORT sMinCoolSetDESC; // Minimum value for cooling
487 SHORT sMaxCoolSetDESC; // Maximum value for cooling
488 SHORT sDefaultCoolSetDESC; // Default value for cooling // 230
489 WORD wPowerDownModeDESC; // Power down mode possibility
490 WORD wOffsetRegulationDESC; // Offset regulation possibility
491 WORD wColorPatternDESC; // Color pattern of color chip
492 // four nibbles (0,1,2,3) in word
493 // -----------------
494 // | 3 | 2 | 1 | 0 |
495 // -----------------
496 //
497 // describe row,column 2,2 2,1 1,2 1,1
498 //
499 // column1 column2
500 // -----------------
501 // | | |
502 // | 0 | 1 | row1
503 // | | |
504 // -----------------
505 // | | |
506 // | 2 | 3 | row2
507 // | | |
508 // -----------------
509 //
510 WORD wPatternTypeDESC; // Pattern type of color chip
511 // 0: Bayer pattern RGB
512 // 1: Bayer pattern CMY
513
515};
516
517#endif
Inline class to create a binary command to be sent to pco cameras over serial port.
Definition pco_structures.h:36
void addULong(unsigned long msg)
Definition pco_structures.h:110
unsigned short * length
Definition pco_structures.h:141
char data[256]
Definition pco_structures.h:144
void calcCheckSum(void)
Definition pco_structures.h:152
void setCode(unsigned short cx)
Definition pco_structures.h:49
unsigned short code
Definition pco_structures.h:139
void addUChar(unsigned char msg)
Definition pco_structures.h:74
void addLong(long msg)
Definition pco_structures.h:98
pco_command()
Definition pco_structures.h:43
unsigned short getCode(void)
Definition pco_structures.h:135
int addr
Definition pco_structures.h:171
unsigned short getLen(void)
Definition pco_structures.h:129
void addUShort(unsigned short msg)
Definition pco_structures.h:62
unsigned char * getData(void)
Definition pco_structures.h:123
void addShort(short msg)
Definition pco_structures.h:86
unsigned char * checksum
Definition pco_structures.h:142
int totalsum
Definition pco_structures.h:172
Class to define a single binary response from pco cameras, received over serial port.
Definition pco_structures.h:180
void copy2Obj(unsigned char *obj, int len)
Definition pco_structures.h:227
void addUChar(unsigned char *msg, int len)
Definition pco_structures.h:249
unsigned short error_code
Definition pco_structures.h:425
void addUChar(unsigned char msg)
Definition pco_structures.h:238
void sprintHeader(char *strg)
Definition pco_structures.h:349
unsigned char * getData(void)
Definition pco_structures.h:359
void addULong(unsigned long msg)
Definition pco_structures.h:291
void setCode(unsigned short cx)
Definition pco_structures.h:199
unsigned char getUChar(int adx)
Definition pco_structures.h:327
int addr
Definition pco_structures.h:417
int verifyCheckSum(void)
Definition pco_structures.h:391
void addUShort(unsigned short msg)
Definition pco_structures.h:258
unsigned short * length
Definition pco_structures.h:428
void addLong(long msg)
Definition pco_structures.h:280
unsigned short code
Definition pco_structures.h:419
void setLength(unsigned short lx)
Definition pco_structures.h:217
unsigned char * getData2(void)
Definition pco_structures.h:365
pco_response()
Definition pco_structures.h:187
unsigned short verified_length
Definition pco_structures.h:434
void setExpCode(unsigned short cx)
Definition pco_structures.h:205
unsigned short getCode(void)
Definition pco_structures.h:375
short getShort(int adx)
Definition pco_structures.h:315
unsigned long getULong(int adx)
Definition pco_structures.h:338
int totalsum
Definition pco_structures.h:438
unsigned char * checksum
Definition pco_structures.h:430
unsigned short getErrCode(void)
Definition pco_structures.h:385
unsigned short exp_code
Definition pco_structures.h:422
unsigned char verified_chksm
Definition pco_structures.h:433
unsigned short getLen(void)
Definition pco_structures.h:370
void addShort(short msg)
Definition pco_structures.h:269
void setErrCode(unsigned short cx)
Definition pco_structures.h:211
char data[256]
Definition pco_structures.h:436
unsigned short getUShort(int adx)
Definition pco_structures.h:303
unsigned short getExpCode(void)
Definition pco_structures.h:380
#define WORD
Definition pco_structures.h:442
#define SHORT
Definition pco_structures.h:444
#define DWORD
Definition pco_structures.h:443
aps designed struct based on PCO SDK.
Definition pco_structures.h:451
WORD wTimeTableDESC
Definition pco_structures.h:484
WORD wMaxVertResStdDESC
Definition pco_structures.h:456
WORD wPatternTypeDESC
Definition pco_structures.h:510
DWORD dwMaxExposureDESC
Definition pco_structures.h:478
DWORD dwMinExposureIRDESC
Definition pco_structures.h:482
WORD wMaxVertResExtDESC
Definition pco_structures.h:458
DWORD dwMinDelayStepDESC
Definition pco_structures.h:476
DWORD dwMaxDelayIRDESC
Definition pco_structures.h:481
DWORD dwMaxDelayDESC
Definition pco_structures.h:475
WORD wBinVertSteppingDESC
Definition pco_structures.h:463
DWORD reserved[9]
Definition pco_structures.h:514
WORD wColorPatternDESC
Definition pco_structures.h:491
WORD wBinHorzSteppingDESC
Definition pco_structures.h:461
WORD wSensorTypeDESC
Definition pco_structures.h:453
SHORT sDefaultCoolSetDESC
Definition pco_structures.h:488
SHORT sMaxCoolSetDESC
Definition pco_structures.h:487
DWORD dwMinDelayDESC
Definition pco_structures.h:474
SHORT sMinCoolSetDESC
Definition pco_structures.h:486
WORD wMaxHorzResStdDESC
Definition pco_structures.h:455
DWORD dwMinDelayIRDESC
Definition pco_structures.h:480
WORD wRoiVertStepsDESC
Definition pco_structures.h:465
DWORD dwPixelRateDESC[4]
Definition pco_structures.h:468
DWORD dwMinExposureDESC
Definition pco_structures.h:477
WORD wRoiHorStepsDESC
Definition pco_structures.h:464
WORD wMaxBinHorzDESC
Definition pco_structures.h:460
WORD wConvFactDESC[4]
Definition pco_structures.h:470
WORD wDoubleImageDESC
Definition pco_structures.h:485
DWORD dwMinExposureStepDESC
Definition pco_structures.h:479
WORD wNumADCsDESC
Definition pco_structures.h:466
WORD wSize
Definition pco_structures.h:452
WORD wOffsetRegulationDESC
Definition pco_structures.h:490
WORD wDynResDESC
Definition pco_structures.h:459
WORD wMaxHorzResExtDESC
Definition pco_structures.h:457
DWORD dwMaxExposureIRDESC
Definition pco_structures.h:483
WORD wSensorSubTypeDESC
Definition pco_structures.h:454
WORD wMaxBinVertDESC
Definition pco_structures.h:462
WORD wPowerDownModeDESC
Definition pco_structures.h:489
WORD wIRDESC
Definition pco_structures.h:472