forked from joelowney/PythonForPicam
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPiTypesMore.py
123 lines (102 loc) · 4.07 KB
/
PiTypesMore.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
"""
PythonForPicam is a Python ctypes interface to the Princeton Instruments PICAM Library
Copyright (C) 2013 Joe Lowney. The copyright holder can be reached at [email protected]
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import ctypes as ctypes
from PiTypes import *
##### Some of the types defined dependent on an enum: PicamStringSize. From picam.h we have the following:
"""
typedef enum PicamStringSize
{
PicamStringSize_SensorName = 64,
PicamStringSize_SerialNumber = 64,
PicamStringSize_FirmwareName = 64,
PicamStringSize_FirmwareDetail = 256
} PicamStringSize;
"""
### Which is why I define the following:
PicamStringSize_SensorName = PicamStringSize_SerialNumber = PicamStringSize_FirmwareName = 64
PicamStringSize_FirmwareDetail = 256
"""
typedef struct PicamCameraID
{
PicamModel model;
PicamComputerInterface computer_interface;
pichar sensor_name[PicamStringSize_SensorName];
pichar serial_number[PicamStringSize_SerialNumber];
} PicamCameraID;
"""
class PicamCameraID(ctypes.Structure):
_fields_ = [("model", PicamModel),
("computer_interface", PicamComputerInterface),
("sensor_name", pichar * PicamStringSize_SensorName),
("serial_number", pichar * PicamStringSize_SerialNumber)]
# PicamHandle
PicamHandle = ctypes.c_void_p
# PicamFirmwareDetail
"""
typedef struct PicamFirmwareDetail
{
pichar name[PicamStringSize_FirmwareName];
pichar detail[PicamStringSize_FirmwareDetail];
} PicamFirmwareDetail;
"""
class PicamFirmwareDetail(ctypes.Structure):
_fields_ = [("name", pichar * PicamStringSize_FirmwareName),
("detail", pichar * PicamStringSize_FirmwareDetail)]
##### Types defined on pp57-70 (chapter 4: Camera Parameter Values, Inofrmation, Constraints, and Commitment)
### Saving this for later!
##### Types defined on p76 (chapter 5: Camera Data Acquisition)
# PicamAvailableData
"""
typedef struct PicamAvailableData
{
void* initial_readout;
pi64s readout_count;
} PicamAvailableData;
"""
class PicamAvailableData(ctypes.Structure):
_fields_ = [("initial_readout", ctypes.c_void_p), ("readout_count", pi64s)]
class PicamAvailableData2(ctypes.Structure):
_fields_ = [ ( "initial_readout", ctypes.POINTER(type(ctypes.c_void_p()))), ("readout_count", pi64s)]
# PicamAcquisitionErrorsMask
"""
typedef enum PicamAcquisitionErrorsMask
{
PicamAcquisitionErrorsMask_None = 0x0,
PicamAcquisitionErrorsMask_DataLost = 0x1,
PicamAcquisitionErrorsMask_ConnectionLost = 0x2
} PicamAcquisitionErrorsMask; /* (0x4) */
"""
PicamAcquisitionErrorsMask = ctypes.c_int
# PicamAcquisitionStatus
class PicamAcquisitionStatus(ctypes.Structure):
_fields_ = [("running",pibln),
("errors",PicamAcquisitionErrorsMask),
("readout_rate",piflt)]
# PicamRoi
class PicamRoi(ctypes.Structure):
_fields_ = [("x",piint),
("width",piint),
("x_binning",piint),
("y",piint),
("height",piint),
("y_binning",piint)]
class PicamRois(ctypes.Structure):
_fields_ = [("roi_array",ctypes.POINTER(PicamRoi)),
("roi_count",piint)]
# the following is based on:
# http://stackoverflow.com/questions/17101845/python-ctypes-array-of-structs
def __init__(self):
elements = (PicamRoi * 10)() # assume 10 rois at the most
self.roi_array = ctypes.cast(elements,ctypes.POINTER(PicamRoi))