-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsdk.py
4802 lines (3807 loc) · 192 KB
/
sdk.py
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
@author: ziegler
"""
import ctypes as C
import sys
import os
import time
from datetime import datetime
import platform
import numpy
class sdk:
"""
This class provides the basic methods for using pco cameras.
"""
# -------------------------------------------------------------------------
class exception(Exception):
def __str__(self):
return ("Exception: {0} {1:08x}".format(self.args[0],
self.args[1] & (2**32-1)))
# -------------------------------------------------------------------------
def __init__(self, debuglevel='off', timestamp='off', name=''):
if platform.architecture()[0] != '64bit':
print('Python Interpreter not x64')
raise OSError
self.__dll_name = 'SC2_Cam.dll'
dll_path = os.path.dirname(__file__).replace('\\', '/')
try:
self.SC2_Cam = C.windll.LoadLibrary(dll_path + '/' + self.__dll_name)
except OSError:
print('Error: ' + '"' + self.__dll_name + '" not found in directory "' + dll_path + '".')
raise
self.camera_handle = C.c_void_p(0)
self.lens_control = C.c_void_p(0)
self.debuglevel = debuglevel
self.timestamp = timestamp
self.name = name
# -------------------------------------------------------------------------
def log(self, name, error, data=None, start_time=0.0):
if self.timestamp == 'on' and self.debuglevel != 'off':
curr_time = datetime.now()
formatted_time = curr_time.strftime('%Y-%m-%d %H:%M:%S.%f')
ts = '[{0} /{1:6.3f} s] '.format(formatted_time, time.time() - start_time)
else:
ts = ''
if self.debuglevel == 'error' and error != 0:
print(ts + '[' + self.name +']' + '[sdk] ' + name + ':', self.get_error_text(error))
elif self.debuglevel == 'verbose':
print(ts + '[' + self.name +']' + '[sdk] ' + name + ':', self.get_error_text(error))
elif self.debuglevel == 'extra verbose':
print(ts + '[' + self.name +']' + '[sdk] ' + name + ':', self.get_error_text(error))
if data is not None:
for key, value in data.items():
print(' -', key + ':', value)
# ---------------------------------------------------------------------
def get_error_text(self, errorcode):
"""
"""
self.SC2_Cam.PCO_GetErrorText.argtypes = [C.c_uint32,
C.POINTER(C.c_uint32),
C.c_uint32]
buffer = (C.c_char * 500)()
p_buffer = C.cast(buffer, C.POINTER(C.c_ulong))
self.SC2_Cam.PCO_GetErrorText(errorcode, p_buffer, 500)
temp_list = []
for i in range(100):
temp_list.append(buffer[i])
output_string = bytes.join(b'', temp_list).decode('ascii')
return output_string.strip("\0")
# ---------------------------------------------------------------------
def get_camera_handle(self):
return self.camera_handle
# ---------------------------------------------------------------------
# 2.1.1 PCO_OpenCamera
# ---------------------------------------------------------------------
def open_camera(self):
"""
This function is used to get a connection to a camera. This function
scans through all available interfaces and tries to connect to the next
available camera.
"""
self.SC2_Cam.PCO_OpenCamera.argtypes = [C.POINTER(C.c_void_p),
C.c_uint16]
start_time = time.time()
error = self.SC2_Cam.PCO_OpenCamera(self.camera_handle, 0)
ret = {}
ret.update({'camera handle': self.camera_handle})
self.log(sys._getframe().f_code.co_name, error, start_time=start_time)
if error:
raise self.exception(sys._getframe().f_code.co_name, error)
return ret
# -------------------------------------------------------------------------
# 2.1.2 PCO_OpenCameraEx
# -------------------------------------------------------------------------
def open_camera_ex(self, interface, camera_number=0):
"""
This function is used to get a connection to a specific camera.
"""
class PCO_OPEN_STRUCT(C.Structure):
_pack_ = 1
_fields_ = [
("wSize", C.c_uint16),
("wInterfaceType", C.c_uint16),
("wCameraNumber", C.c_uint16),
("wCameraNumAtInterface", C.c_uint16),
("wOpenFlags", C.c_uint16 * 10),
("dwOpenFlags", C.c_uint32 * 5),
("wOpenPtr", C.c_void_p * 6),
("zzwDummy", C.c_uint16 * 8)]
self.SC2_Cam.PCO_OpenCameraEx.argtypes = [C.POINTER(C.c_void_p),
PCO_OPEN_STRUCT]
interface_dict = {'FireWire': 1,
#'': 2,
#'': 3,
#'': 4,
'GigE': 5,
'USB 2.0': 6,
'Camera Link Silicon Software': 7,
'USB 3.0': 8,
#'WLAN': 9,
#'': 10,
'CLHS': 11}
strOpenStruct = PCO_OPEN_STRUCT()
strOpenStruct.wSize = C.sizeof(PCO_OPEN_STRUCT)
strOpenStruct.wInterfaceType = interface_dict[interface]
strOpenStruct.wCameraNumber = camera_number
strOpenStruct.wCameraNumAtInterface = 0
strOpenStruct.wOpenFlags[0] = 0x0000
strOpenStruct.wOpenFlags[1] = 0x0000
strOpenStruct.wOpenFlags[2] = 0x0000
strOpenStruct.dwOpenFlags[0] = 0x00000000
strOpenStruct.dwOpenFlags[1] = 0x00000000
strOpenStruct.dwOpenFlags[2] = 0x00000000
strOpenStruct.dwOpenFlags[3] = 0x00000000
strOpenStruct.dwOpenFlags[4] = 0x00000000
strOpenStruct.wOpenPtr[0] = 0
strOpenStruct.wOpenPtr[1] = 0
strOpenStruct.wOpenPtr[2] = 0
strOpenStruct.wOpenPtr[3] = 0
strOpenStruct.wOpenPtr[4] = 0
strOpenStruct.wOpenPtr[5] = 0
start_time = time.time()
error = self.SC2_Cam.PCO_OpenCameraEx(self.camera_handle, strOpenStruct)
self.log(sys._getframe().f_code.co_name, error, start_time=start_time)
PCO_ERROR_DRIVER_FIREWIRE = 0x00300000
PCO_ERROR_DRIVER_USB = 0x00310000
PCO_ERROR_DRIVER_GIGE = 0x00320000
PCO_ERROR_DRIVER_CAMERALINK = 0x00330000
PCO_ERROR_DRIVER_USB3 = 0x00340000
PCO_ERROR_DRIVER_WLAN = 0x00350000
PCO_ERROR_DRIVER_NODRIVER = 0x80002006
PCO_ERROR_DRIVER_NOTINIT = 0x80002001
if error == 0:
return {'error': 0}
if error & 0xFF00FFFF == PCO_ERROR_DRIVER_NODRIVER:
return {'error': PCO_ERROR_DRIVER_NODRIVER}
if error & 0xFF00FFFF == PCO_ERROR_DRIVER_NOTINIT:
return {'error': PCO_ERROR_DRIVER_NOTINIT}
if error:
raise self.exception(sys._getframe().f_code.co_name, error)
# -------------------------------------------------------------------------
# 2.1.3 PCO_CloseCamera
# -------------------------------------------------------------------------
def close_camera(self):
"""
This function is used to close the connection to a previously opened
camera.
"""
self.SC2_Cam.PCO_CloseCamera.argtypes = [C.c_void_p]
start_time = time.time()
error = self.SC2_Cam.PCO_CloseCamera(self.camera_handle)
self.log(sys._getframe().f_code.co_name, error, start_time=start_time)
if error:
raise self.exception(sys._getframe().f_code.co_name, error)
# -------------------------------------------------------------------------
# 2.1.4 PCO_ResetLib
# -------------------------------------------------------------------------
def reset_lib(self):
"""
This function is used to set the sc2_cam library to an initial state.
All camera handles have to be closed with close_camera before this
function is called.
"""
self.SC2_Cam.PCO_ResetLib.argtypes = [C.POINTER(C.c_void_p)]
start_time = time.time()
error = self.SC2_Cam.PCO_ResetLib(self.camera_handle)
self.log(sys._getframe().f_code.co_name, error, start_time=start_time)
if error:
raise self.exception(sys._getframe().f_code.co_name, error)
# -------------------------------------------------------------------------
# 2.1.5 PCO_CheckDeviceAvailability (for the moment intentionally not implemented)
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# 2.2.1 PCO_GetCameraDescription
# -------------------------------------------------------------------------
def get_camera_description(self):
"""
Sensor and camera specific description is queried.
:return: camera description
:rtype: dict
"""
class PCO_Description(C.Structure):
_pack_ = 1
_fields_ = [
("wSize", C.c_uint16),
("wSensorTypeDESC", C.c_uint16),
("wSensorSubTypeDESC", C.c_uint16),
("wMaxHorzResStdDESC", C.c_uint16),
("wMaxVertResStdDESC", C.c_uint16),
("wMaxHorzResExtDESC", C.c_uint16),
("wMaxVertResExtDESC", C.c_uint16),
("wDynResDESC", C.c_uint16),
("wMaxBinHorzDESC", C.c_uint16),
("wBinHorzSteppingDESC", C.c_uint16),
("wMaxBinVertDESC", C.c_uint16),
("wBinVertSteppingDESC", C.c_uint16),
("wRoiHorStepsDESC", C.c_uint16),
("wRoiVertStepsDESC", C.c_uint16),
("wNumADCsDESC", C.c_uint16),
("wMinSizeHorzDESC", C.c_uint16),
("dwPixelRateDESC", C.c_uint32 * 4),
("ZZdwDummypr", C.c_uint32 * 20),
("wConvFactDESC", C.c_uint16 * 4),
("sCoolingSetpoints", C.c_short * 10),
("ZZdwDummycv", C.c_uint16 * 8),
("wSoftRoiHorStepsDESC", C.c_uint16),
("wSoftRoiVertStepsDESC", C.c_uint16),
("wIRDESC", C.c_uint16),
("wMinSizeVertDESC", C.c_uint16),
("dwMinDelayDESC", C.c_uint32),
("dwMaxDelayDESC", C.c_uint32),
("dwMinDelayStepDESC", C.c_uint32),
("dwMinExposDESC", C.c_uint32),
("dwMaxExposDESC", C.c_uint32),
("dwMinExposStepDESC", C.c_uint32),
("dwMinDelayIRDESC", C.c_uint32),
("dwMaxDelayIRDESC", C.c_uint32),
("dwMinExposIRDESC", C.c_uint32),
("dwMaxExposIRDESC", C.c_uint32),
("wTimeTableDESC", C.c_uint16),
("wDoubleImageDESC", C.c_uint16),
("sMinCoolSetDESC", C.c_short),
("sMaxCoolSetDESC", C.c_short),
("sDefaultCoolSetDESC", C.c_short),
("wPowerDownModeDESC", C.c_uint16),
("wOffsetRegulationDESC", C.c_uint16),
("wColorPatternDESC", C.c_uint16),
("wPatternTypeDESC", C.c_uint16),
("wDummy1", C.c_uint16),
("wDummy2", C.c_uint16),
("wNumCoolingSetpoints", C.c_uint16),
("dwGeneralCapsDESC1", C.c_uint32),
("dwGeneralCapsDESC2", C.c_uint32),
("dwExtSyncFrequency", C.c_uint32 * 4),
("dwGeneralCapsDESC3", C.c_uint32),
("dwGeneralCapsDESC4", C.c_uint32),
("ZzdwDummy", C.c_uint32)]
self.SC2_Cam.PCO_GetCameraDescription.argtypes = [C.c_void_p,
C.POINTER(PCO_Description)]
strDescription = PCO_Description()
strDescription.wSize = C.sizeof(PCO_Description)
start_time = time.time()
error = self.SC2_Cam.PCO_GetCameraDescription(self.camera_handle,
strDescription)
ret = {}
ret.update({'sensor type': strDescription.wSensorTypeDESC})
ret.update({'sensor subtype': strDescription.wSensorSubTypeDESC})
ret.update({'max. horizontal resolution standard': strDescription.wMaxHorzResStdDESC})
ret.update({'max. vertical resolution standard': strDescription.wMaxVertResStdDESC})
ret.update({'max. horizontal resolution extended': strDescription.wMaxHorzResExtDESC})
ret.update({'max. vertical resolution extended': strDescription.wMaxVertResExtDESC})
ret.update({'dynamic': strDescription.wDynResDESC})
ret.update({'max. binning horizontal': strDescription.wMaxBinHorzDESC})
ret.update({'binning horizontal stepping': strDescription.wBinHorzSteppingDESC})
ret.update({'max. binning vert': strDescription.wMaxBinVertDESC})
ret.update({'binning vert stepping': strDescription.wBinVertSteppingDESC})
ret.update({'roi hor steps': strDescription.wRoiHorStepsDESC})
ret.update({'roi vert steps': strDescription.wRoiVertStepsDESC})
ret.update({'number adcs': strDescription.wNumADCsDESC})
ret.update({'min size horz': strDescription.wMinSizeHorzDESC})
prtuple = (strDescription.dwPixelRateDESC[0],
strDescription.dwPixelRateDESC[1],
strDescription.dwPixelRateDESC[2],
strDescription.dwPixelRateDESC[3])
ret.update({'pixel rate': list(prtuple)})
cftuple = (strDescription.wConvFactDESC[0],
strDescription.wConvFactDESC[1],
strDescription.wConvFactDESC[2],
strDescription.wConvFactDESC[3])
ret.update({'conversion factor': list(cftuple)})
cstuple = (strDescription.sCoolingSetpoints[0],
strDescription.sCoolingSetpoints[1],
strDescription.sCoolingSetpoints[2],
strDescription.sCoolingSetpoints[3],
strDescription.sCoolingSetpoints[4],
strDescription.sCoolingSetpoints[5],
strDescription.sCoolingSetpoints[6],
strDescription.sCoolingSetpoints[7],
strDescription.sCoolingSetpoints[8],
strDescription.sCoolingSetpoints[9])
ret.update({'cooling setpoints': list(cstuple)})
ret.update({'soft roi hor steps': strDescription.wSoftRoiHorStepsDESC})
ret.update({'soft roi vert steps': strDescription.wSoftRoiVertStepsDESC})
ret.update({'ir': strDescription.wIRDESC})
ret.update({'min size vert': strDescription.wMinSizeVertDESC})
ret.update({'Min Delay DESC': strDescription.dwMinDelayDESC})
ret.update({'Max Delay DESC': strDescription.dwMaxDelayDESC})
ret.update({'Min Delay StepDESC': strDescription.dwMinDelayStepDESC})
ret.update({'Min Expos DESC': strDescription.dwMinExposDESC})
ret.update({'Max Expos DESC': strDescription.dwMaxExposDESC})
ret.update({'Min Expos Step DESC': strDescription.dwMinExposStepDESC})
ret.update({'Min Delay IR DESC': strDescription.dwMinDelayIRDESC})
ret.update({'Max Delay IR DESC': strDescription.dwMaxDelayIRDESC})
ret.update({'Min Expos IR DESC': strDescription.dwMinExposIRDESC})
ret.update({'Max ExposIR DESC': strDescription.dwMaxExposIRDESC})
ret.update({'Time Table DESC': strDescription.wTimeTableDESC})
ret.update({'wDoubleImageDESC': strDescription.wDoubleImageDESC})
ret.update({'Min Cool Set DESC': strDescription.sMinCoolSetDESC})
ret.update({'Max Cool Set DESC': strDescription.sMaxCoolSetDESC})
ret.update({'Default Cool Set DESC': strDescription.sDefaultCoolSetDESC})
ret.update({'Power Down Mode DESC': strDescription.wPowerDownModeDESC})
ret.update({'Offset Regulation DESC': strDescription.wOffsetRegulationDESC})
ret.update({'Color Pattern DESC': strDescription.wColorPatternDESC})
ret.update({'Pattern Type DESC': strDescription.wPatternTypeDESC})
ret.update({'Num Cooling Setpoints': strDescription.wNumCoolingSetpoints})
ret.update({'dwGeneralCapsDESC1': strDescription.dwGeneralCapsDESC1})
ret.update({'dwGeneralCapsDESC2': strDescription.dwGeneralCapsDESC2})
efstuple = (strDescription.dwExtSyncFrequency[0],
strDescription.dwExtSyncFrequency[1],
strDescription.dwExtSyncFrequency[2],
strDescription.dwExtSyncFrequency[3])
ret.update({'ext sync frequency': list(efstuple)})
ret.update({'dwGeneralCapsDESC3': strDescription.dwGeneralCapsDESC3})
ret.update({'dwGeneralCapsDESC4': strDescription.dwGeneralCapsDESC4})
self.log(sys._getframe().f_code.co_name, error, ret, start_time=start_time)
if error:
raise self.exception(sys._getframe().f_code.co_name, error)
return ret
# -------------------------------------------------------------------------
# 2.2.2 PCO_GetCameraDescriptionEx
# -------------------------------------------------------------------------
def get_camera_description_ex(self, description_type):
"""
"""
class PCO_Description(C.Structure):
_pack_ = 1
_fields_ = [
("wSize", C.c_uint16),
("wSensorTypeDESC", C.c_uint16),
("wSensorSubTypeDESC", C.c_uint16),
("wMaxHorzResStdDESC", C.c_uint16),
("wMaxVertResStdDESC", C.c_uint16),
("wMaxHorzResExtDESC", C.c_uint16),
("wMaxVertResExtDESC", C.c_uint16),
("wDynResDESC", C.c_uint16),
("wMaxBinHorzDESC", C.c_uint16),
("wBinHorzSteppingDESC", C.c_uint16),
("wMaxBinVertDESC", C.c_uint16),
("wBinVertSteppingDESC", C.c_uint16),
("wRoiHorStepsDESC", C.c_uint16),
("wRoiVertStepsDESC", C.c_uint16),
("wNumADCsDESC", C.c_uint16),
("wMinSizeHorzDESC", C.c_uint16),
("dwPixelRateDESC", C.c_uint32 * 4),
("ZZdwDummypr", C.c_uint32 * 20),
("wConvFactDESC", C.c_uint16 * 4),
("sCoolingSetpoints", C.c_short * 10),
("ZZdwDummycv", C.c_uint16 * 8),
("wSoftRoiHorStepsDESC", C.c_uint16),
("wSoftRoiVertStepsDESC", C.c_uint16),
("wIRDESC", C.c_uint16),
("wMinSizeVertDESC", C.c_uint16),
("dwMinDelayDESC", C.c_uint32),
("dwMaxDelayDESC", C.c_uint32),
("dwMinDelayStepDESC", C.c_uint32),
("dwMinExposDESC", C.c_uint32),
("dwMaxExposDESC", C.c_uint32),
("dwMinExposStepDESC", C.c_uint32),
("dwMinDelayIRDESC", C.c_uint32),
("dwMaxDelayIRDESC", C.c_uint32),
("dwMinExposIRDESC", C.c_uint32),
("dwMaxExposIRDESC", C.c_uint32),
("wTimeTableDESC", C.c_uint16),
("wDoubleImageDESC", C.c_uint16),
("sMinCoolSetDESC", C.c_short),
("sMaxCoolSetDESC", C.c_short),
("sDefaultCoolSetDESC", C.c_short),
("wPowerDownModeDESC", C.c_uint16),
("wOffsetRegulationDESC", C.c_uint16),
("wColorPatternDESC", C.c_uint16),
("wPatternTypeDESC", C.c_uint16),
("wDummy1", C.c_uint16),
("wDummy2", C.c_uint16),
("wNumCoolingSetpoints", C.c_uint16),
("dwGeneralCapsDESC1", C.c_uint32),
("dwGeneralCapsDESC2", C.c_uint32),
("dwExtSyncFrequency", C.c_uint32 * 4),
("dwGeneralCapsDESC3", C.c_uint32),
("dwGeneralCapsDESC4", C.c_uint32),
("ZzdwDummy", C.c_uint32)]
class PCO_Description_2(C.Structure):
_pack_ = 1
_fields_ = [
("wSize", C.c_uint16),
("ZZwAlignDummy1", C.c_uint16),
("dwMinPeriodicalTimeDESC2", C.c_uint32),
("dwMaxPeriodicalTimeDESC2", C.c_uint32),
("dwMinPeriodicalConditionDESC2", C.c_uint32),
("dwMaxNumberOfExposuresDESC2", C.c_uint32),
("lMinMonitorSignalOffsetDESC2", C.c_long),
("dwMaxMonitorSignalOffsetDESC2", C.c_uint32),
("dwMinPeriodicalStepDESC2", C.c_uint32),
("dwStartTimeDelayDESC2", C.c_uint32),
("dwMinMonitorStepDESC2", C.c_uint32),
("dwMinDelayModDESC2", C.c_uint32),
("dwMaxDelayModDESC2", C.c_uint32),
("dwMinDelayStepModDESC2", C.c_uint32),
("dwMinExposureModDESC2", C.c_uint32),
("dwMaxExposureModDESC2", C.c_uint32),
("dwMinExposureStepModDESC2", C.c_uint32),
("dwModulateCapsDESC2", C.c_uint32),
("dwReserved", C.c_uint32 * 16),
("ZZdwDummy", C.c_uint32 * 41)]
desc = {'PCO_DESCRIPTION': 0, 'PCO_DESCRIPTION_2': 1}
wType = C.c_uint16(desc[description_type])
if description_type == 'PCO_DESCRIPTION':
self.SC2_Cam.PCO_GetCameraDescriptionEx.argtypes = [C.c_void_p,
C.POINTER(PCO_Description),
C.c_uint16]
strDescEx = PCO_Description()
strDescEx.wSize = C.sizeof(PCO_Description)
elif description_type == 'PCO_DESCRIPTION_2':
self.SC2_Cam.PCO_GetCameraDescriptionEx.argtypes = [C.c_void_p,
C.POINTER(PCO_Description_2),
C.c_uint16]
strDescEx = PCO_Description_2()
strDescEx.wSize = C.sizeof(PCO_Description_2)
start_time = time.time()
error = self.SC2_Cam.PCO_GetCameraDescriptionEx(self.camera_handle,
strDescEx,
wType)
ret = {}
ret.update({'___': 1})
self.log(sys._getframe().f_code.co_name, error, ret, start_time=start_time)
if error:
raise self.exception(sys._getframe().f_code.co_name, error)
return ret
# -------------------------------------------------------------------------
# 2.3.1 PCO_GetGeneral (for the moment intentionally not implemented)
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# 2.3.2 PCO_GetCameraType
# -------------------------------------------------------------------------
def get_camera_type(self):
"""
This function retrieves the camera type code, hardware/firmware
version, serial number and interface type of the camera.
:return: {'camera type': str,
'camera subtype': str,
'serial number': int,
'interface type': str}
:rtype: dict
"""
class PCO_SC2_Hardware_DESC(C.Structure):
_pack_ = 1
_fields_ = [
("szName", C.c_char * 16),
("wBatchNo", C.c_uint16),
("wRevision", C.c_uint16),
("wVariant", C.c_uint16),
("ZZwDummy", C.c_uint16 * 20)]
class PCO_SC2_Firmware_DESC(C.Structure):
_pack_ = 1
_fields_ = [
("szName", C.c_char * 16),
("bMinorRev", C.c_uint8),
("bMajorRev", C.c_uint8),
("wVariant", C.c_uint16),
("ZZwDummy", C.c_uint16 * 22)]
class PCO_HW_Vers(C.Structure):
_pack_ = 1
_fields_ = [
("BoardNum", C.c_uint16),
("Board", PCO_SC2_Hardware_DESC * 10)]
class PCO_FW_Vers(C.Structure):
_pack_ = 1
_fields_ = [
("DeviceNum", C.c_uint16),
("Device", PCO_SC2_Firmware_DESC * 10)]
class PCO_CameraType(C.Structure):
_pack_ = 1
_fields_ = [
("wSize", C.c_uint16),
("wCamType", C.c_uint16),
("wCamSubType", C.c_uint16),
("ZZwAlignDummy1", C.c_uint16),
("dwSerialNumber", C.c_uint32),
("dwHWVersion", C.c_uint32),
("dwFWVersion", C.c_uint32),
("wInterfaceType", C.c_uint16),
("strHardwareVersion", PCO_HW_Vers),
("strFirmwareVersion", PCO_FW_Vers),
("ZZwDummy", C.c_uint16 * 39)]
self.SC2_Cam.PCO_GetCameraType.argtypes = [C.c_void_p,
C.POINTER(PCO_CameraType)]
strCamType = PCO_CameraType()
strCamType.wSize = C.sizeof(PCO_CameraType)
start_time = time.time()
error = self.SC2_Cam.PCO_GetCameraType(self.camera_handle,
strCamType)
ret = {}
if error == 0:
camera_type = {0x0100: 'pco.1200HS',
0x0200: 'pco.1300',
0x0220: 'pco.1600',
0x0240: 'pco.2000',
0x0260: 'pco.4000',
0x0830: 'pco.1400',
0x1000: 'pco.dimax',
0x1010: 'pco.dimax_TV',
0x1020: 'pco.dimax CS',
0x1400: 'pco.flim',
0x1600: 'pco.panda',
0x0800: 'pco.pixelfly usb',
0x1300: 'pco.edge 5.5 CL',
0x1302: 'pco.edge 4.2 CL',
0x1310: 'pco.edge GL',
0x1320: 'pco.edge USB3',
0x1340: 'pco.edge CLHS',
0x1304: 'pco.edge MT',
0x1800: 'pco.edge family'}
interface_type = {0x0001: 'FireWire',
0x0002: 'Camera Link',
0x0003: 'USB 2.0',
0x0004: 'GigE',
0x0005: 'Serial Interface',
0x0006: 'USB 3.0',
0x0007: 'CLHS',
0x0009: 'USB 3.1 Gen 1'}
ret.update({'camera type': camera_type.get(strCamType.wCamType, strCamType.wCamType)})
ret.update({'camera subtype': strCamType.wCamSubType})
ret.update({'serial number': strCamType.dwSerialNumber})
ret.update({'interface type': interface_type.get(strCamType.wInterfaceType, strCamType.wInterfaceType)})
self.log(sys._getframe().f_code.co_name, error, ret, start_time=start_time)
if error:
raise self.exception(sys._getframe().f_code.co_name, error)
return ret
# -------------------------------------------------------------------------
# 2.3.3 PCO_GetCameraHealthStatus
# -------------------------------------------------------------------------
def get_camera_health_status(self):
"""
This function retrieves information about the current camera status.
It is recommended to call this function frequently (e.g. every 5s or
after calling arm_camera()) in order to recognize camera internal
problems. This helps to prevent camera hardware from damage.
:return: {'warning': int,
'error': int,
'status': int}
:rtype: dict
"""
self.SC2_Cam.PCO_GetCameraHealthStatus.argtypes = [C.c_void_p,
C.POINTER(C.c_uint32),
C.POINTER(C.c_uint32),
C.POINTER(C.c_uint32)]
dwWarning = C.c_uint32()
dwError = C.c_uint32()
dwStatus = C.c_uint32()
start_time = time.time()
error = self.SC2_Cam.PCO_GetCameraHealthStatus(self.camera_handle,
dwWarning,
dwError,
dwStatus)
ret = {}
if error == 0:
ret.update({'warning': dwWarning.value})
ret.update({'error': dwError.value})
ret.update({'status': dwStatus.value})
self.log(sys._getframe().f_code.co_name, error, ret, start_time=start_time)
if error:
raise self.exception(sys._getframe().f_code.co_name, error)
return ret
# -------------------------------------------------------------------------
# 2.3.4 PCO_GetTemperature
# -------------------------------------------------------------------------
def get_temperature(self):
"""
This function retrieves the current temperatures in °C of the imaging
sensor, camera and additional devices e.g. power supply.
:return: {'sensor temperature': float,
'camera temperature': float,
'power temperature': float}
:rtype: dict
"""
start_time = time.time()
self.SC2_Cam.PCO_GetTemperature.argtypes = [C.c_void_p,
C.POINTER(C.c_short),
C.POINTER(C.c_short),
C.POINTER(C.c_short)]
sCCDTemp, sCamTemp, sPowTemp = (C.c_short(), C.c_short(), C.c_short())
start_time = time.time()
error = self.SC2_Cam.PCO_GetTemperature(self.camera_handle,
sCCDTemp,
sCamTemp,
sPowTemp)
ret = {}
if error == 0:
ret.update({'sensor temperature': float((sCCDTemp.value)/10.0)})
ret.update({'camera temperature': float(sCamTemp.value)})
ret.update({'power temperature': float(sPowTemp.value)})
self.log(sys._getframe().f_code.co_name, error, ret, start_time=start_time)
if error:
raise self.exception(sys._getframe().f_code.co_name, error)
return ret
# -------------------------------------------------------------------------
# 2.3.5 PCO_GetInfoString
# -------------------------------------------------------------------------
def get_info_string(self, info_type):
"""
This function retrieves some information about the camera, e.g. sensor
name.
:param info_type:
* INFO_STRING_PCO_INTERFACE, camera name & interface information
* INFO_STRING_CAMERA, camera name
* INFO_STRING_SENSOR, sensor name
* INFO_STRING_PCO_MATERIALNUMBER, production number
* INFO_STRING_BUILD, firmware build number and date
* INFO_STRING_PCO_INCLUDE, firmware build include revision
:return: {'info string': str}
:rtype: dict
"""
self.SC2_Cam.PCO_GetInfoString.argtypes = [C.c_void_p,
C.c_uint32,
C.POINTER(C.c_char),
C.c_uint16]
info = {'INFO_STRING_PCO_INTERFACE': 0,
'INFO_STRING_CAMERA': 1,
'INFO_STRING_SENSOR': 2,
'INFO_STRING_PCO_MATERIALNUMBER': 3,
'INFO_STRING_BUILD': 4,
'INFO_STRING_PCO_INCLUDE': 5}
buffer = (C.c_char * 500)()
p_buffer = C.cast(buffer, C.POINTER(C.c_char))
start_time = time.time()
error = self.SC2_Cam.PCO_GetInfoString(self.camera_handle,
info[info_type],
p_buffer,
500)
ret = {}
if error == 0:
temp_list = []
for i in range(500):
temp_list.append(buffer[i])
output_string = bytes.join(b'', temp_list).decode('ascii')
ret.update({'info string': output_string.strip("\0")})
self.log(sys._getframe().f_code.co_name, error, ret, start_time=start_time)
if error:
raise self.exception(sys._getframe().f_code.co_name, error)
return ret
# -------------------------------------------------------------------------
# 2.3.6 PCO_GetCameraName
# -------------------------------------------------------------------------
def get_camera_name(self):
"""
This function retrieves the name of the camera.
:return: {'camera name': str}
:rtype: dict
>>> get_camera_name()
{'camera name': 'pco.edge 5.5 M CLHS'}
"""
self.SC2_Cam.PCO_GetCameraName.argtypes = [C.c_void_p,
C.POINTER(C.c_char),
C.c_uint32]
buffer = (C.c_char * 40)()
p_buffer = C.cast(buffer, C.POINTER(C.c_char))
start_time = time.time()
error = self.SC2_Cam.PCO_GetCameraName(self.camera_handle,
p_buffer,
40)
ret = {}
if error == 0:
temp_list = []
for i in range(40):
temp_list.append(buffer[i])
output_string = bytes.join(b'', temp_list).decode('ascii')
ret.update({'camera name': output_string.strip("\0")})
self.log(sys._getframe().f_code.co_name, error, ret, start_time=start_time)
if error:
raise self.exception(sys._getframe().f_code.co_name, error)
return ret
# -------------------------------------------------------------------------
# 2.3.7 PCO_GetFirmwareInfo
# -------------------------------------------------------------------------
def get_firmware_info(self, device):
"""
Query firmware versions of all devices in the camera such as main
microprocessor, main FPGA and coprocessors of the interface boards.
:return: {'device 0 name': str,
'device 0 major': int,
'device 0 minor': int,
'device 0 variant': int}
:rtype: dict
"""
class PCO_SC2_Firmware_DESC(C.Structure):
_pack_ = 1
_fields_ = [
("szName", C.c_char * 16),
("bMinorRev", C.c_uint8),
("bMajorRev", C.c_uint8),
("wVariant", C.c_uint16),
("ZZwDummy", C.c_uint16 * 22)]
class PCO_FW_Vers(C.Structure):
_pack_ = 1
_fields_ = [
("DeviceNum", C.c_uint16),
("Device", PCO_SC2_Firmware_DESC * 10)]
self.SC2_Cam.PCO_GetFirmwareInfo.argtypes = [C.c_void_p,
C.c_uint16,
C.POINTER(PCO_FW_Vers)]
pstrFirmWareVersion = PCO_FW_Vers()
deviceX = C.c_uint16(device)
start_time = time.time()
error = self.SC2_Cam.PCO_GetFirmwareInfo(self.camera_handle,
deviceX,
pstrFirmWareVersion)
ret = {}
if error == 0:
ret.update({'name': pstrFirmWareVersion.Device[0].szName.decode('ascii')})
ret.update({'major': pstrFirmWareVersion.Device[0].bMajorRev})
ret.update({'minor': pstrFirmWareVersion.Device[0].bMinorRev})
ret.update({'variant': pstrFirmWareVersion.Device[0].wVariant})
self.log(sys._getframe().f_code.co_name, error, ret, start_time=start_time)
if error:
raise self.exception(sys._getframe().f_code.co_name, error)
return ret
# -------------------------------------------------------------------------
# 2.3.8 PCO_GetColorCorrectionMatrix
# -------------------------------------------------------------------------
def get_color_correction_matrix(self):
"""
This function returns the color multiplier matrix from the camera. The
color multiplier matrix can be used to normalize the color values of a
color camera to a color temperature of 6500 K. The color multiplier
matrix is specific for each camera and is determined through a special
calibration procedure.
:return: {'ccm': tuple}
:rtype: dict
"""
self.SC2_Cam.PCO_GetColorCorrectionMatrix.argtypes = [C.c_void_p,
C.POINTER(C.c_double)]
Matrix = (C.c_double * 9)()
pdMatrix = C.cast(Matrix, C.POINTER(C.c_double))
start_time = time.time()
error = self.SC2_Cam.PCO_GetColorCorrectionMatrix(self.camera_handle,
pdMatrix)
ret = {}
if error == 0:
mtuple = (Matrix[0],
Matrix[1],
Matrix[2],
Matrix[3],
Matrix[4],
Matrix[5],
Matrix[6],
Matrix[7],
Matrix[8])
ret.update({'ccm': list(mtuple)})
self.log(sys._getframe().f_code.co_name, error, ret, start_time=start_time)
if error:
raise self.exception(sys._getframe().f_code.co_name, error)
return ret
# -------------------------------------------------------------------------
# 2.4.1 PCO_ArmCamera
# -------------------------------------------------------------------------
def arm_camera(self):
"""
This function arms, this means prepare the camera for a following
recording. All configurations and settings made up to this moment are
accepted, validated and the internal settings of the camera are
prepared. If the arm was successful the camera state is changed to
[armed] and the camera is able to start image recording immediately,
when Recording State is set to [run].
"""
self.SC2_Cam.PCO_ArmCamera.argtypes = [C.c_void_p]
start_time = time.time()
error = self.SC2_Cam.PCO_ArmCamera(self.camera_handle)
self.log(sys._getframe().f_code.co_name, error, start_time=start_time)
if error:
raise self.exception(sys._getframe().f_code.co_name, error)
# -------------------------------------------------------------------------
# 2.4.2 PCO_CamLinkSetImageParameters (obsolete)
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# 2.4.3 PCO_SetImageParameter
# -------------------------------------------------------------------------
def set_image_parameters(self, image_width, image_height):
"""
This function sets the image parameters for internal allocated
resources.
"""
self.SC2_Cam.PCO_SetImageParameters.argtypes = [C.c_void_p,
C.c_uint16,
C.c_uint16,
C.c_uint32,
C.c_void_p(),
C.c_int]
wxres = C.c_uint16(image_width)
wyres = C.c_uint16(image_height)
dwFlags = C.c_uint32(2)
param = C.c_void_p(0)
ilen = C.c_int(0)
start_time = time.time()
error = self.SC2_Cam.PCO_SetImageParameters(self.camera_handle,
wxres,
wyres,
dwFlags,
param,
ilen)
self.log(sys._getframe().f_code.co_name, error, start_time=start_time)
if error:
raise self.exception(sys._getframe().f_code.co_name, error)
# -------------------------------------------------------------------------
# 2.4.4 PCO_ResetSettingsToDefault
# -------------------------------------------------------------------------
def reset_settings_to_default(self):
"""
This function can be used to reset all camera settings to its default
values. This function is also executed during a power-up sequence. The
camera must be stopped before calling this command. Default settings
are slightly different for all cameras.
"""
self.SC2_Cam.PCO_ResetSettingsToDefault.argtypes = [C.c_void_p]
start_time = time.time()
error = self.SC2_Cam.PCO_ResetSettingsToDefault(self.camera_handle)
self.log(sys._getframe().f_code.co_name, error, start_time=start_time)
if error:
raise self.exception(sys._getframe().f_code.co_name, error)
# -------------------------------------------------------------------------
# 2.4.5 PCO_SetTimeouts (for the moment intentionally not implemented)
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# 2.4.6 PCO_RebootCamera
# -------------------------------------------------------------------------
def reboot_camera(self):
"""