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
|
# -*- coding: utf-8 -*-
import vimbastructure as structs
from vimbadll import VimbaDLL
from vimbaexception import VimbaException
from vimbasystem import VimbaSystem
from vimbacamera import VimbaCamera
from vimbainterface import VimbaInterface
from ctypes import *
class Vimba(object):
"""
An Allied Vision Technology Vimba API.
This API provides access to AVT cameras.
"""
# todo - assign camera info and feature info as own object proeprties
def __init__(self):
# create own system singleton object
self._system = VimbaSystem()
# lists of VimbaCameraInfo and VimbaInterfaceInfo objects
# can't be called before startup() so populate later
self._cameraInfos = None
self._interfaceInfos = None
# dict of {camera ID : VimbaCamera object} as we don't want to forget them
self._cameras = {}
# dict of {interface ID : VimbaInterface object} as we don't want to forget them
self._interfaces = {}
def _getInterfaceInfos(self):
"""
Gets interface info of all available interfaces.
:returns: list -- interface info for available interfaces.
"""
if self._interfaceInfos is None:
# args
dummyInterfaceInfo = structs.VimbaInterfaceInfo()
numFound = c_uint32(-1)
# call once just to get the number of interfaces
# Vimba DLL will return an error code
errorCode = VimbaDLL.interfacesList(byref(dummyInterfaceInfo),
0,
byref(numFound),
sizeof(dummyInterfaceInfo))
if errorCode != 0:
print errorCode
raise VimbaException(errorCode)
numInterfaces = numFound.value
# args
interfaceInfoArray = (structs.VimbaInterfaceInfo * numInterfaces)()
# call again to get the features
# Vimba DLL will return an error code
errorCode = VimbaDLL.interfacesList(interfaceInfoArray,
numInterfaces,
byref(numFound),
sizeof(dummyInterfaceInfo))
if errorCode != 0:
raise VimbaException(errorCode)
self._interfaceInfos = list(interfaceInfo for interfaceInfo in interfaceInfoArray)
return self._interfaceInfos
def _getCameraInfos(self):
"""
Gets camera info of all attached cameras.
:returns: list -- camera info for available cameras.
"""
if self._cameraInfos is None:
# args
dummyCameraInfo = structs.VimbaCameraInfo()
numFound = c_uint32(-1)
# call once just to get the number of cameras
# Vimba DLL will return an error code
errorCode = VimbaDLL.camerasList(byref(dummyCameraInfo),
0,
byref(numFound),
sizeof(dummyCameraInfo))
if errorCode != 0:
print errorCode
raise VimbaException(errorCode)
numCameras = numFound.value
# args
cameraInfoArray = (structs.VimbaCameraInfo * numCameras)()
# call again to get the features
# Vimba DLL will return an error code
errorCode = VimbaDLL.camerasList(cameraInfoArray,
numCameras,
byref(numFound),
sizeof(dummyCameraInfo))
if errorCode != 0:
raise VimbaException(errorCode)
self._cameraInfos = list(camInfo for camInfo in cameraInfoArray)
return self._cameraInfos
def getSystem(self):
"""
Gets system singleton object.
:returns: VimbaSystem object -- the system singleton object.
"""
return self._system
def getInterfaceIds(self):
"""
Gets IDs of all available interfaces.
:returns: list -- interface IDs for available interfaces.
"""
return list(interfaceInfo.interfaceIdString for interfaceInfo in self._getInterfaceInfos())
def getCameraIds(self):
"""
Gets IDs of all available cameras.
:returns: list -- camera IDs for available cameras.
"""
return list(camInfo.cameraIdString for camInfo in self._getCameraInfos())
def getInterfaceInfo(self, interfaceId):
"""
Gets interface info object of specified interface.
:param interfaceId: the ID of the interface object to get.
:returns: VimbaInterfaceInfo object -- the interface info object specified.
"""
# don't do this live as we already have this info
# return info object if it exists
for interfaceInfo in self._getInterfaceInfos():
if interfaceInfo.interfaceIdString == interfaceId:
return interfaceInfo
# otherwise raise error
raise VimbaException(-54)
def getCameraInfo(self, cameraId):
"""
Gets camera info object of specified camera.
:param cameraId: the ID of the camera object to get.
:returns: VimbaCameraInfo object -- the camera info object specified.
"""
# don't do this live as we already have this info
# return info object if it exists
for camInfo in self._getCameraInfos():
if camInfo.cameraIdString == cameraId:
return camInfo
# otherwise raise error
raise VimbaException(-50)
def getInterface(self, interfaceId):
"""
Gets interface object based on interface ID string. Will not recreate
interface object if it already exists.
:param interfaceId: the ID of the interface.
:returns: VimbaInterface object -- the interface object specified.
"""
# check ID is valid
if interfaceId in self.getInterfaceIds():
# create it if it doesn't exist
if interfaceId not in self._interfaces:
self._interfaces[interfaceId] = VimbaInterface(interfaceId)
return self._interfaces[interfaceId]
raise VimbaException(-54)
def getCamera(self, cameraId):
"""
Gets camera object based on camera ID string. Will not recreate
camera object if it already exists.
:param cameraId: the ID of the camera.
:returns: VimbaCamera object -- the camera object specified.
"""
# check ID is valid
if cameraId in self.getCameraIds():
# create it if it doesn't exist
if cameraId not in self._cameras:
self._cameras[cameraId] = VimbaCamera(cameraId)
return self._cameras[cameraId]
raise VimbaException(-50)
def getVersion(self):
"""
Retrieve the version number of VimbaC.
:returns: string - Vimba API version info.
"""
# args
versionInfo = structs.VimbaVersion()
# Vimba DLL will return an error code
errorCode = VimbaDLL.versionQuery(versionInfo,
sizeof(versionInfo))
if errorCode != 0:
raise VimbaException(errorCode)
versionStr = '.'.join([str(versionInfo.major),
str(versionInfo.minor),
str(versionInfo.patch)])
return versionStr
def startup(self):
"""
Initialize the VimbaC API.
"""
# Vimba DLL will return an error code
errorCode = VimbaDLL.startup()
if errorCode != 0:
raise VimbaException(errorCode)
def shutdown(self):
"""
Perform a shutdown on the API.
"""
VimbaDLL.shutdown()
|