aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerric Williams <derricw@alleninstitute.org>2014-07-07 16:41:25 -0700
committerDerric Williams <derricw@alleninstitute.org>2014-07-07 16:41:25 -0700
commit7d46e407f84245dc495ba1c477a331d8c1537ea8 (patch)
tree62c07225c54e23f42e40a6a32f99e001d43e1d11
parente6753b1f2ce8735739fb3ca632eec41ef95525b3 (diff)
downloadpymba-7d46e407f84245dc495ba1c477a331d8c1537ea8.tar.gz
pymba-7d46e407f84245dc495ba1c477a331d8c1537ea8.zip
PEP8 formatting (tabs to spaces, etc). Live view example. 64-bit support.
-rw-r--r--pymba/tests/opencv_liveview_example.py80
-rw-r--r--pymba/vimba.py447
-rw-r--r--pymba/vimbacamera.py222
-rw-r--r--pymba/vimbadll.py787
-rw-r--r--pymba/vimbaexception.py109
-rw-r--r--pymba/vimbafeature.py631
-rw-r--r--pymba/vimbainterface.py72
-rw-r--r--pymba/vimbaobject.py415
-rw-r--r--pymba/vimbastructure.py173
-rw-r--r--pymba/vimbasystem.py30
10 files changed, 1555 insertions, 1411 deletions
diff --git a/pymba/tests/opencv_liveview_example.py b/pymba/tests/opencv_liveview_example.py
new file mode 100644
index 0000000..83331ac
--- /dev/null
+++ b/pymba/tests/opencv_liveview_example.py
@@ -0,0 +1,80 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Mon Jul 07 14:59:03 2014
+
+@author: derricw
+"""
+
+from pymba import *
+import numpy as np
+import cv2
+import time
+
+cv2.namedWindow("test")
+
+vimba = Vimba()
+vimba.startup()
+
+system = vimba.getSystem()
+
+system.runFeatureCommand("GeVDiscoveryAllOnce")
+time.sleep(0.2)
+
+camera_ids = vimba.getCameraIds()
+
+for cam_id in camera_ids:
+ print "Camera found: ", cam_id
+
+c0 = vimba.getCamera(camera_ids[0])
+c0.openCamera()
+
+try:
+ #gigE camera
+ print c0.GevSCPSPacketSize
+ print c0.StreamBytesPerSecond
+ c0.StreamBytesPerSecond = 100000000
+except:
+ #not a gigE camera
+ pass
+
+frame = c0.getFrame()
+frame.announceFrame()
+
+c0.startCapture()
+
+framecount = 0
+droppedframes = []
+
+while 1:
+ print framecount
+ try:
+ frame.queueFrameCapture()
+ success = True
+ except:
+ droppedframes.append(framecount)
+ success = False
+ c0.runFeatureCommand("AcquisitionStart")
+ c0.runFeatureCommand("AcquisitionStop")
+ frame.waitFrameCapture(100)
+ if success:
+ img = np.ndarray(buffer=frame.getBufferByteData(),
+ dtype=np.uint8,
+ shape=(frame.height,frame.width,1))
+ cv2.imshow("test",img)
+ framecount+=1
+ k = cv2.waitKey(1)
+ if k == 0x1b:
+ cv2.destroyAllWindows()
+ print "Frames displayed: %i"%framecount
+ print "Frames dropped: %s"%droppedframes
+ break
+ #del frame
+#print img
+
+
+c0.endCapture()
+c0.revokeAllFrames()
+
+c0.closeCamera()
+
+vimba.shutdown()
diff --git a/pymba/vimba.py b/pymba/vimba.py
index 0add297..678e7b0 100644
--- a/pymba/vimba.py
+++ b/pymba/vimba.py
@@ -7,225 +7,230 @@ 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()
+
+ """
+ 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()
diff --git a/pymba/vimbacamera.py b/pymba/vimbacamera.py
index 747eb4c..e08a69e 100644
--- a/pymba/vimbacamera.py
+++ b/pymba/vimbacamera.py
@@ -7,118 +7,118 @@ from vimbadll import VimbaDLL
from ctypes import *
# camera features are automatically readable as object attributes.
+
+
class VimbaCamera(VimbaObject):
- """
- A Vimba camera object. This class provides the minimal access
- to Vimba functions required to control the camera.
- """
-
- @property
- def cameraIdString(self):
- return self._cameraIdString
-
- # own handle is inherited as self._handle
- def __init__(self, cameraIdString):
-
- # call super constructor
- super(VimbaCamera, self).__init__()
-
- # set ID
- self._cameraIdString = cameraIdString
-
- # set own info
- self._info = self._getInfo()
-
- def getInfo(self):
- """
- Get info of the camera. Does not require
- the camera to be opened.
-
- :returns: VimbaCameraInfo object -- camera information.
- """
- return self._info
-
- def _getInfo(self):
- """
- Get info of the camera. Does not require
- the camera to be opened.
-
- :returns: VimbaCameraInfo object -- camera information.
- """
- # args for Vimba call
- cameraInfo = structs.VimbaCameraInfo()
-
- # Vimba DLL will return an error code
- errorCode = VimbaDLL.cameraInfoQuery(self._cameraIdString,
- byref(cameraInfo),
- sizeof(cameraInfo))
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- return cameraInfo
-
- def openCamera(self):
- """
- Open the camera.
- """
- # args for Vimba call
- cameraAccessMode = 1 # full access (see VmbAccessModeType)
-
- errorCode = VimbaDLL.cameraOpen(self._cameraIdString,
- cameraAccessMode,
- byref(self._handle))
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- def closeCamera(self):
- """
- Close the camera.
- """
- errorCode = VimbaDLL.cameraClose(self._handle)
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- def revokeAllFrames(self):
- """
- Revoke all frames assigned to the camera.
- """
- errorCode = VimbaDLL.frameRevokeAll(self._handle)
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- def startCapture(self):
- """
- Prepare the API for incoming frames.
- """
- errorCode = VimbaDLL.captureStart(self._handle)
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- def endCapture(self):
- """
- Stop the API from being able to receive frames.
- """
- errorCode = VimbaDLL.captureEnd(self._handle)
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- def flushCaptureQueue(self):
- """
- Flush the capture queue.
- """
- errorCode = VimbaDLL.captureQueueFlush(self._handle)
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- # method for easy frame creation
- def getFrame(self):
- """
- Creates and returns a new frame object. Multiple frames
- per camera can therefore be returned.
-
- :returns: VimbaFrame object -- the new frame.
- """
- return VimbaFrame(self)
+ """
+ A Vimba camera object. This class provides the minimal access
+ to Vimba functions required to control the camera.
+ """
+
+ @property
+ def cameraIdString(self):
+ return self._cameraIdString
+
+ # own handle is inherited as self._handle
+ def __init__(self, cameraIdString):
+
+ # call super constructor
+ super(VimbaCamera, self).__init__()
+
+ # set ID
+ self._cameraIdString = cameraIdString
+
+ # set own info
+ self._info = self._getInfo()
+
+ def getInfo(self):
+ """
+ Get info of the camera. Does not require
+ the camera to be opened.
+
+ :returns: VimbaCameraInfo object -- camera information.
+ """
+ return self._info
+
+ def _getInfo(self):
+ """
+ Get info of the camera. Does not require
+ the camera to be opened.
+
+ :returns: VimbaCameraInfo object -- camera information.
+ """
+ # args for Vimba call
+ cameraInfo = structs.VimbaCameraInfo()
+
+ # Vimba DLL will return an error code
+ errorCode = VimbaDLL.cameraInfoQuery(self._cameraIdString,
+ byref(cameraInfo),
+ sizeof(cameraInfo))
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ return cameraInfo
+
+ def openCamera(self):
+ """
+ Open the camera.
+ """
+ # args for Vimba call
+ cameraAccessMode = 1 # full access (see VmbAccessModeType)
+
+ errorCode = VimbaDLL.cameraOpen(self._cameraIdString,
+ cameraAccessMode,
+ byref(self._handle))
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ def closeCamera(self):
+ """
+ Close the camera.
+ """
+ errorCode = VimbaDLL.cameraClose(self._handle)
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ def revokeAllFrames(self):
+ """
+ Revoke all frames assigned to the camera.
+ """
+ errorCode = VimbaDLL.frameRevokeAll(self._handle)
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ def startCapture(self):
+ """
+ Prepare the API for incoming frames.
+ """
+ errorCode = VimbaDLL.captureStart(self._handle)
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ def endCapture(self):
+ """
+ Stop the API from being able to receive frames.
+ """
+ errorCode = VimbaDLL.captureEnd(self._handle)
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ def flushCaptureQueue(self):
+ """
+ Flush the capture queue.
+ """
+ errorCode = VimbaDLL.captureQueueFlush(self._handle)
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+ # method for easy frame creation
+ def getFrame(self):
+ """
+ Creates and returns a new frame object. Multiple frames
+ per camera can therefore be returned.
+ :returns: VimbaFrame object -- the new frame.
+ """
+ return VimbaFrame(self)
diff --git a/pymba/vimbadll.py b/pymba/vimbadll.py
index f21f7f6..16e2264 100644
--- a/pymba/vimbadll.py
+++ b/pymba/vimbadll.py
@@ -1,387 +1,426 @@
# -*- coding: utf-8 -*-
import vimbastructure as structs
from vimbaexception import VimbaException
-from sys import platform
+from sys import platform as sys_plat
+import platform
import os
from ctypes import *
-if platform == "win32":
- from ctypes.util import find_msvcrt
- _cruntime = cdll.LoadLibrary(find_msvcrt())
- vimbaC_path = r'C:\Program Files\Allied Vision Technologies\AVTVimba_1.2\VimbaC\Bin\Win32\VimbaC.dll'
- dll_loader = windll
+if sys_plat == "win32":
+ from ctypes.util import find_msvcrt
+ _cruntime = cdll.LoadLibrary(find_msvcrt())
+ if '64' in platform.architecture()[0]:
+ vimbaC_path = r'C:\Program Files\Allied Vision Technologies\AVTVimba_1.2\VimbaC\Bin\Win64\VimbaC.dll'
+ else:
+ vimbaC_path = r'C:\Program Files\Allied Vision Technologies\AVTVimba_1.2\VimbaC\Bin\Win32\VimbaC.dll'
+ dll_loader = windll
else:
- _cruntime = CDLL("libc.so.6")
- dll_loader = cdll
- assert os.environ.get("GENICAM_GENTL64_PATH"), "you need your GENICAM_GENTL64_PATH environment set. Make sure you have Vimba installed, and you have loaded the /etc/profile.d/ scripts"
- vimba_dir = "/".join(os.environ.get("GENICAM_GENTL64_PATH").split("/")[1:-3])
- vimbaC_path = "/" + vimba_dir + "/VimbaC/DynamicLib/x86_64bit/libVimbaC.so"
+ _cruntime = CDLL("libc.so.6")
+ dll_loader = cdll
+ assert os.environ.get(
+ "GENICAM_GENTL64_PATH"), "you need your GENICAM_GENTL64_PATH environment set. Make sure you have Vimba installed, and you have loaded the /etc/profile.d/ scripts"
+ vimba_dir = "/".join(os.environ.get("GENICAM_GENTL64_PATH").split("/")
+ [1:-3])
+ vimbaC_path = "/" + vimba_dir + "/VimbaC/DynamicLib/x86_64bit/libVimbaC.so"
with open(vimbaC_path) as thefile:
- pass #NJO i think this is kind of like an os.exists ?
+ pass # NJO i think this is kind of like an os.exists ?
class VimbaDLL(object):
- """
- ctypes directives to make the wrapper class work cleanly,
- talks to VimbaC.dll
- """
- # a full list of Vimba API methods
- # (only double dashed methods have been implemented so far)
- #
- # -- VmbVersionQuery()
- #
- # -- VmbStartup()
- # -- VmbShutdown()
- #
- # -- VmbCamerasList()
- # -- VmbCameraInfoQuery()
- # -- VmbCameraOpen()
- # -- VmbCameraClose()
- #
- # -- VmbFeaturesList()
- # -- VmbFeatureInfoQuery()
- # VmbFeatureListAffected()
- # VmbFeatureListSelected()
- # VmbFeatureAccessQuery()
- #
- # -- VmbFeatureIntGet()
- # -- VmbFeatureIntSet()
- # -- VmbFeatureIntRangeQuery()
- # VmbFeatureIntIncrementQuery()
- #
- # -- VmbFeatureFloatGet()
- # -- VmbFeatureFloatSet()
- # -- VmbFeatureFloatRangeQuery()
- #
- # -- VmbFeatureEnumGet()
- # -- VmbFeatureEnumSet()
- # VmbFeatureEnumRangeQuery()
- # VmbFeatureEnumIsAvailable()
- # VmbFeatureEnumAsInt()
- # VmbFeatureEnumAsString()
- # VmbFeatureEnumEntryGet()
- #
- # -- VmbFeatureStringGet()
- # -- VmbFeatureStringSet()
- # VmbFeatureStringMaxlengthQuery()
- #
- # -- VmbFeatureBoolGet()
- # -- VmbFeatureBoolSet()
- #
- # -- VmbFeatureCommandRun()
- # VmbFeatureCommandIsDone()
- #
- # VmbFeatureRawGet()
- # VmbFeatureRawSet()
- # VmbFeatureRawLengthQuery()
- #
- # VmbFeatureInvalidationRegister()
- # VmbFeatureInvalidationUnregister()
- #
- # -- VmbFrameAnnounce()
- # -- VmbFrameRevoke()
- # -- VmbFrameRevokeAll()
- # -- VmbCaptureStart()
- # -- VmbCaptureEnd()
- # -- VmbCaptureFrameQueue()
- # -- VmbCaptureFrameWait()
- # -- VmbCaptureQueueFlush()
- #
- # -- VmbInterfacesList()
- # -- VmbInterfaceOpen()
- # -- VmbInterfaceClose()
- #
- # VmbAncillaryDataOpen()
- # VmbAncillaryDataClose()
- #
- # VmbMemoryRead()
- # VmbMemoryWrite()
- # -- VmbRegistersRead()
- # -- VmbRegistersWrite()
-
- # Vimba C API DLL
-
- _vimbaDLL = dll_loader.LoadLibrary(vimbaC_path)
-
- # version query
- versionQuery = _vimbaDLL.VmbVersionQuery
- versionQuery.restype = c_int32 # returned error code
- versionQuery.argtypes = (POINTER(structs.VimbaVersion), # pointer to version structure
- c_uint32) # version structure size
-
- # startup
- startup = _vimbaDLL.VmbStartup
- startup.restype = c_int32 # returned error code
-
- # shutdown
- shutdown = _vimbaDLL.VmbShutdown
-
- # list cameras
- camerasList = _vimbaDLL.VmbCamerasList
- camerasList.restype = c_int32 # returned error code
- camerasList.argtypes = (POINTER(structs.VimbaCameraInfo), # pointer to camera info structure
- c_uint32, # length of list
- POINTER(c_uint32), # pointer to number of cameras
- c_uint32) # camera info structure size
-
- # camera info query
- cameraInfoQuery = _vimbaDLL.VmbCameraInfoQuery
- cameraInfoQuery.restype = c_int32
- cameraInfoQuery.argtypes = (c_char_p, # camera unique id
- POINTER(structs.VimbaCameraInfo), # pointer to camera info structure
- c_uint32) # size of structure
-
- # camera open
- cameraOpen = _vimbaDLL.VmbCameraOpen
- cameraOpen.restype = c_int32 # returned error code
- cameraOpen.argtypes = (c_char_p, # camera unique id
- c_uint32, # access mode
- c_void_p) # camera handle, pointer to a pointer
-
- # camera close
- cameraClose = _vimbaDLL.VmbCameraClose
- cameraClose.restype = c_int32 # returned error code
- cameraClose.argtypes = (c_void_p,) # camera handle
-
- # list features
- featuresList = _vimbaDLL.VmbFeaturesList
- featuresList.restype = c_int32
- featuresList.argtypes = (c_void_p, # handle, in this case camera handle
- POINTER(structs.VimbaFeatureInfo), # pointer to feature info structure
- c_uint32, # list length
- POINTER(c_uint32), # pointer to num features found
- c_uint32) # feature info size
-
- # feature info query
- featureInfoQuery = _vimbaDLL.VmbFeatureInfoQuery
- featureInfoQuery.restype = c_int32
- featureInfoQuery.argtypes = (c_void_p, # handle, in this case camera handle
- c_char_p, # name of feature
- POINTER(structs.VimbaFeatureInfo), # pointer to feature info structure
- c_uint32) # size of structure
-
- # get the int value of a feature
- featureIntGet = _vimbaDLL.VmbFeatureIntGet
- featureIntGet.restype = c_int32
- featureIntGet.argtypes = (c_void_p, # handle, in this case camera handle
- c_char_p, # name of the feature
- POINTER(c_int64)) # value to get
-
- # set the int value of a feature
- featureIntSet = _vimbaDLL.VmbFeatureIntSet
- featureIntSet.restype = c_int32
- featureIntSet.argtypes = (c_void_p, # handle, in this case camera handle
- c_char_p, # name of the feature
- c_int64) # value to set # get the value of an integer feature
-
- # query the range of values of the feature
- featureIntRangeQuery = _vimbaDLL.VmbFeatureIntRangeQuery
- featureIntRangeQuery.restype = c_int32
- featureIntRangeQuery.argtypes = (c_void_p, # handle
- c_char_p, # name of the feature
- POINTER(c_int64), # min range
- POINTER(c_int64)) # max range
-
- # get the float value of a feature
- featureFloatGet = _vimbaDLL.VmbFeatureFloatGet
- featureFloatGet.restype = c_int32
- featureFloatGet.argtypes = (c_void_p, # handle, in this case camera handle
- c_char_p, # name of the feature
- POINTER(c_double)) # value to get
-
- # set the float value of a feature
- featureFloatSet = _vimbaDLL.VmbFeatureFloatSet
- featureFloatSet.restype = c_int32
- featureFloatSet.argtypes = (c_void_p, # handle, in this case camera handle
- c_char_p, # name of the feature
- c_double) # value to set
-
- # query the range of values of the feature
- featureFloatRangeQuery = _vimbaDLL.VmbFeatureFloatRangeQuery
- featureFloatRangeQuery.restype = c_int32
- featureFloatRangeQuery.argtypes = (c_void_p, # handle
- c_char_p, # name of the feature
- POINTER(c_double), # min range
- POINTER(c_double)) # max range
-
- # get the enum value of a feature
- featureEnumGet = _vimbaDLL.VmbFeatureEnumGet
- featureEnumGet.restype = c_int32
- featureEnumGet.argtypes = (c_void_p, # handle, in this case camera handle
- c_char_p, # name of the feature
- POINTER(c_char_p)) # value to get
-
- # set the enum value of a feature
- featureEnumSet = _vimbaDLL.VmbFeatureEnumSet
- featureEnumSet.restype = c_int32
- featureEnumSet.argtypes = (c_void_p, # handle, in this case camera handle
- c_char_p, # name of the feature
- c_char_p) # value to set
-
- # get the string value of a feature
- featureStringGet = _vimbaDLL.VmbFeatureStringGet
- featureStringGet.restype = c_int32
- featureStringGet.argtypes = (c_void_p, # handle, in this case camera handle
- c_char_p, # name of the feature
- c_char_p, # string buffer to fill
- c_uint32, # size of the input buffer
- POINTER(c_uint32)) # string buffer to fill
-
- # set the string value of a feature
- featureStringSet = _vimbaDLL.VmbFeatureStringSet
- featureStringSet.restype = c_int32
- featureStringSet.argtypes = (c_void_p, # handle, in this case camera handle
- c_char_p, # name of the feature
- c_char_p) # value to set
-
- # get the boolean value of a feature
- featureBoolGet = _vimbaDLL.VmbFeatureBoolGet
- featureBoolGet.restype = c_int32
- featureBoolGet.argtypes = (c_void_p, # handle, in this case camera handle
- c_char_p, # name of the feature
- POINTER(c_bool)) # value to get
-
- # set the boolean value of a feature
- featureBoolSet = _vimbaDLL.VmbFeatureBoolSet
- featureBoolSet.restype = c_int32
- featureBoolSet.argtypes = (c_void_p, # handle, in this case camera handle
- c_char_p, # name of the feature
- c_bool) # value to set
-
- # run a feature command
- featureCommandRun = _vimbaDLL.VmbFeatureCommandRun
- featureCommandRun.restype = c_int32
- featureCommandRun.argtypes = (c_void_p, # handle for a module that exposes features
- c_char_p) # name of the command feature
-
- # announce frames to the API that may be queued for frame capturing later
- frameAnnounce = _vimbaDLL.VmbFrameAnnounce
- frameAnnounce.restype = c_int32
- frameAnnounce.argtypes = (c_void_p, # camera handle
- POINTER(structs.VimbaFrame), # pointer to frame
- c_uint32) # size of frame
-
- # revoke a frame from the API
- frameRevoke = _vimbaDLL.VmbFrameRevoke
- frameRevoke.restype = c_int32
- frameRevoke.argtypes = (c_void_p, # camera handle
- POINTER(structs.VimbaFrame)) # pointer to frame
-
- # revoke all frames assigned to a certain camera
- frameRevokeAll = _vimbaDLL.VmbFrameRevokeAll
- frameRevokeAll.restype = c_int32
- frameRevokeAll.argtypes = (c_void_p,) # camera handle
-
- # prepare the API for incoming frames
- captureStart = _vimbaDLL.VmbCaptureStart
- captureStart.restype = c_int32
- captureStart.argtypes = (c_void_p,) # camera handle
-
- # stop the API from being able to receive frames
- captureEnd = _vimbaDLL.VmbCaptureEnd
- captureEnd.restype = c_int32
- captureEnd.argtypes = (c_void_p,) # camera handle
-
- # queue frames that may be filled during frame capturing
- captureFrameQueue = _vimbaDLL.VmbCaptureFrameQueue
- captureFrameQueue.restype = c_int32
- captureFrameQueue.argtypes = (c_void_p,
- POINTER(structs.VimbaFrame),
- c_void_p) # callback
-
- # wait for a queued frame to be filled (or dequeued)
- captureFrameWait = _vimbaDLL.VmbCaptureFrameWait
- captureFrameWait.restype = c_int32
- captureFrameWait.argtypes = (c_void_p, # camera handle
- POINTER(structs.VimbaFrame),
- c_uint32) # timeout
-
- # flush the capture queue
- captureQueueFlush = _vimbaDLL.VmbCaptureQueueFlush
- captureQueueFlush.restype = c_int32
- captureQueueFlush.argtypes = (c_void_p,) # camera handle
-
- # list interfaces
- interfacesList = _vimbaDLL.VmbInterfacesList
- interfacesList.restype = c_int32
- interfacesList.argtypes = (POINTER(structs.VimbaInterfaceInfo), # pointer to interface info structure
- c_uint32, # length of list
- POINTER(c_uint32), # pointer to number of interfaces
- c_uint32)
-
- # open interface
- interfaceOpen = _vimbaDLL.VmbInterfaceOpen
- interfaceOpen.restype = c_int32
- interfaceOpen.argtypes = (c_char_p, # unique id
- c_void_p) # handle
-
- # close interface
- interfaceClose = _vimbaDLL.VmbInterfaceClose
- interfaceClose.restype = c_int32
- interfaceClose.argtypes = (c_void_p,) # handle
-
- # read from register
- registersRead = _vimbaDLL.VmbRegistersRead
- registersRead.restype = c_int32
- registersRead.argtypes = (c_void_p, # handle
- c_uint32, # read count
- POINTER(c_uint64), # pointer to address array
- POINTER(c_uint64), # pointer to data array
- POINTER(c_uint32)) # pointer to num complete reads
-
- # write to register
- registersWrite = _vimbaDLL.VmbRegistersWrite
- registersWrite.restype = c_int32
- registersWrite.argtypes = (c_void_p, # handle
- c_uint32, # write count
- POINTER(c_uint64), # pointer to address array
- POINTER(c_uint64), # pointer to data array
- POINTER(c_uint32)) # pointer to num complete write
-
-
+
+ """
+ ctypes directives to make the wrapper class work cleanly,
+ talks to VimbaC.dll
+ """
+ # a full list of Vimba API methods
+ # (only double dashed methods have been implemented so far)
+ #
+ # -- VmbVersionQuery()
+ #
+ # -- VmbStartup()
+ # -- VmbShutdown()
+ #
+ # -- VmbCamerasList()
+ # -- VmbCameraInfoQuery()
+ # -- VmbCameraOpen()
+ # -- VmbCameraClose()
+ #
+ # -- VmbFeaturesList()
+ # -- VmbFeatureInfoQuery()
+ # VmbFeatureListAffected()
+ # VmbFeatureListSelected()
+ # VmbFeatureAccessQuery()
+ #
+ # -- VmbFeatureIntGet()
+ # -- VmbFeatureIntSet()
+ # -- VmbFeatureIntRangeQuery()
+ # VmbFeatureIntIncrementQuery()
+ #
+ # -- VmbFeatureFloatGet()
+ # -- VmbFeatureFloatSet()
+ # -- VmbFeatureFloatRangeQuery()
+ #
+ # -- VmbFeatureEnumGet()
+ # -- VmbFeatureEnumSet()
+ # VmbFeatureEnumRangeQuery()
+ # VmbFeatureEnumIsAvailable()
+ # VmbFeatureEnumAsInt()
+ # VmbFeatureEnumAsString()
+ # VmbFeatureEnumEntryGet()
+ #
+ # -- VmbFeatureStringGet()
+ # -- VmbFeatureStringSet()
+ # VmbFeatureStringMaxlengthQuery()
+ #
+ # -- VmbFeatureBoolGet()
+ # -- VmbFeatureBoolSet()
+ #
+ # -- VmbFeatureCommandRun()
+ # VmbFeatureCommandIsDone()
+ #
+ # VmbFeatureRawGet()
+ # VmbFeatureRawSet()
+ # VmbFeatureRawLengthQuery()
+ #
+ # VmbFeatureInvalidationRegister()
+ # VmbFeatureInvalidationUnregister()
+ #
+ # -- VmbFrameAnnounce()
+ # -- VmbFrameRevoke()
+ # -- VmbFrameRevokeAll()
+ # -- VmbCaptureStart()
+ # -- VmbCaptureEnd()
+ # -- VmbCaptureFrameQueue()
+ # -- VmbCaptureFrameWait()
+ # -- VmbCaptureQueueFlush()
+ #
+ # -- VmbInterfacesList()
+ # -- VmbInterfaceOpen()
+ # -- VmbInterfaceClose()
+ #
+ # VmbAncillaryDataOpen()
+ # VmbAncillaryDataClose()
+ #
+ # VmbMemoryRead()
+ # VmbMemoryWrite()
+ # -- VmbRegistersRead()
+ # -- VmbRegistersWrite()
+
+ # Vimba C API DLL
+
+ _vimbaDLL = dll_loader.LoadLibrary(vimbaC_path)
+
+ # version query
+ versionQuery = _vimbaDLL.VmbVersionQuery
+ # returned error code
+ versionQuery.restype = c_int32
+ versionQuery.argtypes = (POINTER(structs.VimbaVersion), # pointer to version structure
+ c_uint32) # version structure size
+
+ # startup
+ startup = _vimbaDLL.VmbStartup
+ # returned error code
+ startup.restype = c_int32
+
+ # shutdown
+ shutdown = _vimbaDLL.VmbShutdown
+
+ # list cameras
+ camerasList = _vimbaDLL.VmbCamerasList
+ # returned error code
+ camerasList.restype = c_int32
+ camerasList.argtypes = (POINTER(structs.VimbaCameraInfo), # pointer to camera info structure
+ # length of list
+ c_uint32,
+ # pointer to number of cameras
+ POINTER(c_uint32),
+ c_uint32) # camera info structure size
+
+ # camera info query
+ cameraInfoQuery = _vimbaDLL.VmbCameraInfoQuery
+ cameraInfoQuery.restype = c_int32
+ cameraInfoQuery.argtypes = (c_char_p, # camera unique id
+ # pointer to camera info structure
+ POINTER(structs.VimbaCameraInfo),
+ c_uint32) # size of structure
+
+ # camera open
+ cameraOpen = _vimbaDLL.VmbCameraOpen
+ # returned error code
+ cameraOpen.restype = c_int32
+ cameraOpen.argtypes = (c_char_p, # camera unique id
+ # access mode
+ c_uint32,
+ c_void_p) # camera handle, pointer to a pointer
+
+ # camera close
+ cameraClose = _vimbaDLL.VmbCameraClose
+ # returned error code
+ cameraClose.restype = c_int32
+ # camera handle
+ cameraClose.argtypes = (c_void_p,)
+
+ # list features
+ featuresList = _vimbaDLL.VmbFeaturesList
+ featuresList.restype = c_int32
+ featuresList.argtypes = (c_void_p, # handle, in this case camera handle
+ # pointer to feature info structure
+ POINTER(structs.VimbaFeatureInfo),
+ # list length
+ c_uint32,
+ # pointer to num features found
+ POINTER(c_uint32),
+ c_uint32) # feature info size
+
+ # feature info query
+ featureInfoQuery = _vimbaDLL.VmbFeatureInfoQuery
+ featureInfoQuery.restype = c_int32
+ featureInfoQuery.argtypes = (c_void_p, # handle, in this case camera handle
+ # name of feature
+ c_char_p,
+ # pointer to feature info structure
+ POINTER(structs.VimbaFeatureInfo),
+ c_uint32) # size of structure
+
+ # get the int value of a feature
+ featureIntGet = _vimbaDLL.VmbFeatureIntGet
+ featureIntGet.restype = c_int32
+ featureIntGet.argtypes = (c_void_p, # handle, in this case camera handle
+ # name of the feature
+ c_char_p,
+ POINTER(c_int64)) # value to get
+
+ # set the int value of a feature
+ featureIntSet = _vimbaDLL.VmbFeatureIntSet
+ featureIntSet.restype = c_int32
+ featureIntSet.argtypes = (c_void_p, # handle, in this case camera handle
+ # name of the feature
+ c_char_p,
+ c_int64) # value to set # get the value of an integer feature
+
+ # query the range of values of the feature
+ featureIntRangeQuery = _vimbaDLL.VmbFeatureIntRangeQuery
+ featureIntRangeQuery.restype = c_int32
+ featureIntRangeQuery.argtypes = (c_void_p, # handle
+ # name of the feature
+ c_char_p,
+ # min range
+ POINTER(c_int64),
+ POINTER(c_int64)) # max range
+
+ # get the float value of a feature
+ featureFloatGet = _vimbaDLL.VmbFeatureFloatGet
+ featureFloatGet.restype = c_int32
+ featureFloatGet.argtypes = (c_void_p, # handle, in this case camera handle
+ # name of the feature
+ c_char_p,
+ POINTER(c_double)) # value to get
+
+ # set the float value of a feature
+ featureFloatSet = _vimbaDLL.VmbFeatureFloatSet
+ featureFloatSet.restype = c_int32
+ featureFloatSet.argtypes = (c_void_p, # handle, in this case camera handle
+ # name of the feature
+ c_char_p,
+ c_double) # value to set
+
+ # query the range of values of the feature
+ featureFloatRangeQuery = _vimbaDLL.VmbFeatureFloatRangeQuery
+ featureFloatRangeQuery.restype = c_int32
+ featureFloatRangeQuery.argtypes = (c_void_p, # handle
+ # name of the feature
+ c_char_p,
+ # min range
+ POINTER(c_double),
+ POINTER(c_double)) # max range
+
+ # get the enum value of a feature
+ featureEnumGet = _vimbaDLL.VmbFeatureEnumGet
+ featureEnumGet.restype = c_int32
+ featureEnumGet.argtypes = (c_void_p, # handle, in this case camera handle
+ # name of the feature
+ c_char_p,
+ POINTER(c_char_p)) # value to get
+
+ # set the enum value of a feature
+ featureEnumSet = _vimbaDLL.VmbFeatureEnumSet
+ featureEnumSet.restype = c_int32
+ featureEnumSet.argtypes = (c_void_p, # handle, in this case camera handle
+ # name of the feature
+ c_char_p,
+ c_char_p) # value to set
+
+ # get the string value of a feature
+ featureStringGet = _vimbaDLL.VmbFeatureStringGet
+ featureStringGet.restype = c_int32
+ featureStringGet.argtypes = (c_void_p, # handle, in this case camera handle
+ # name of the feature
+ c_char_p,
+ # string buffer to fill
+ c_char_p,
+ # size of the input buffer
+ c_uint32,
+ POINTER(c_uint32)) # string buffer to fill
+
+ # set the string value of a feature
+ featureStringSet = _vimbaDLL.VmbFeatureStringSet
+ featureStringSet.restype = c_int32
+ featureStringSet.argtypes = (c_void_p, # handle, in this case camera handle
+ # name of the feature
+ c_char_p,
+ c_char_p) # value to set
+
+ # get the boolean value of a feature
+ featureBoolGet = _vimbaDLL.VmbFeatureBoolGet
+ featureBoolGet.restype = c_int32
+ featureBoolGet.argtypes = (c_void_p, # handle, in this case camera handle
+ # name of the feature
+ c_char_p,
+ POINTER(c_bool)) # value to get
+
+ # set the boolean value of a feature
+ featureBoolSet = _vimbaDLL.VmbFeatureBoolSet
+ featureBoolSet.restype = c_int32
+ featureBoolSet.argtypes = (c_void_p, # handle, in this case camera handle
+ # name of the feature
+ c_char_p,
+ c_bool) # value to set
+
+ # run a feature command
+ featureCommandRun = _vimbaDLL.VmbFeatureCommandRun
+ featureCommandRun.restype = c_int32
+ featureCommandRun.argtypes = (c_void_p, # handle for a module that exposes features
+ c_char_p) # name of the command feature
+
+ # announce frames to the API that may be queued for frame capturing later
+ frameAnnounce = _vimbaDLL.VmbFrameAnnounce
+ frameAnnounce.restype = c_int32
+ frameAnnounce.argtypes = (c_void_p, # camera handle
+ # pointer to frame
+ POINTER(structs.VimbaFrame),
+ c_uint32) # size of frame
+
+ # revoke a frame from the API
+ frameRevoke = _vimbaDLL.VmbFrameRevoke
+ frameRevoke.restype = c_int32
+ frameRevoke.argtypes = (c_void_p, # camera handle
+ POINTER(structs.VimbaFrame)) # pointer to frame
+
+ # revoke all frames assigned to a certain camera
+ frameRevokeAll = _vimbaDLL.VmbFrameRevokeAll
+ frameRevokeAll.restype = c_int32
+ # camera handle
+ frameRevokeAll.argtypes = (c_void_p,)
+
+ # prepare the API for incoming frames
+ captureStart = _vimbaDLL.VmbCaptureStart
+ captureStart.restype = c_int32
+ # camera handle
+ captureStart.argtypes = (c_void_p,)
+
+ # stop the API from being able to receive frames
+ captureEnd = _vimbaDLL.VmbCaptureEnd
+ captureEnd.restype = c_int32
+ # camera handle
+ captureEnd.argtypes = (c_void_p,)
+
+ # queue frames that may be filled during frame capturing
+ captureFrameQueue = _vimbaDLL.VmbCaptureFrameQueue
+ captureFrameQueue.restype = c_int32
+ captureFrameQueue.argtypes = (c_void_p,
+ POINTER(structs.VimbaFrame),
+ c_void_p) # callback
+
+ # wait for a queued frame to be filled (or dequeued)
+ captureFrameWait = _vimbaDLL.VmbCaptureFrameWait
+ captureFrameWait.restype = c_int32
+ captureFrameWait.argtypes = (c_void_p, # camera handle
+ POINTER(structs.VimbaFrame),
+ c_uint32) # timeout
+
+ # flush the capture queue
+ captureQueueFlush = _vimbaDLL.VmbCaptureQueueFlush
+ captureQueueFlush.restype = c_int32
+ # camera handle
+ captureQueueFlush.argtypes = (c_void_p,)
+
+ # list interfaces
+ interfacesList = _vimbaDLL.VmbInterfacesList
+ interfacesList.restype = c_int32
+ interfacesList.argtypes = (POINTER(structs.VimbaInterfaceInfo), # pointer to interface info structure
+ # length of list
+ c_uint32,
+ # pointer to number of interfaces
+ POINTER(c_uint32),
+ c_uint32)
+
+ # open interface
+ interfaceOpen = _vimbaDLL.VmbInterfaceOpen
+ interfaceOpen.restype = c_int32
+ interfaceOpen.argtypes = (c_char_p, # unique id
+ c_void_p) # handle
+
+ # close interface
+ interfaceClose = _vimbaDLL.VmbInterfaceClose
+ interfaceClose.restype = c_int32
+ interfaceClose.argtypes = (c_void_p,) # handle
+
+ # read from register
+ registersRead = _vimbaDLL.VmbRegistersRead
+ registersRead.restype = c_int32
+ registersRead.argtypes = (c_void_p, # handle
+ # read count
+ c_uint32,
+ # pointer to address array
+ POINTER(c_uint64),
+ # pointer to data array
+ POINTER(c_uint64),
+ POINTER(c_uint32)) # pointer to num complete reads
+
+ # write to register
+ registersWrite = _vimbaDLL.VmbRegistersWrite
+ registersWrite.restype = c_int32
+ registersWrite.argtypes = (c_void_p, # handle
+ # write count
+ c_uint32,
+ # pointer to address array
+ POINTER(c_uint64),
+ # pointer to data array
+ POINTER(c_uint64),
+ POINTER(c_uint32)) # pointer to num complete write
+
+
class VimbaC_MemoryBlock(object):
- """
- Just a memory block object for dealing
- neatly with C memory allocations.
- """
-
- # C runtime DLL
- _crtDLL = _cruntime
-
- @property
- def block(self):
- return self._block
-
- def __init__(self, blockSize):
-
- # assign memory block
- malloc = self._crtDLL.malloc
- malloc.argtypes = (c_size_t,)
- malloc.restype = c_void_p
- self._block = malloc(blockSize) # todo check for NULL on failure
-
- # this seems to be None if too much memory is requested
- if self._block is None:
- raise VimbaException(-51)
-
- def __del__(self):
-
- # free memory block
- free = self._crtDLL.free
- free.argtypes = (c_void_p,)
- free.restype = None
- free(self._block)
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+ """
+ Just a memory block object for dealing
+ neatly with C memory allocations.
+ """
+
+ # C runtime DLL
+ _crtDLL = _cruntime
+
+ @property
+ def block(self):
+ return self._block
+
+ def __init__(self, blockSize):
+
+ # assign memory block
+ malloc = self._crtDLL.malloc
+ malloc.argtypes = (c_size_t,)
+ malloc.restype = c_void_p
+ self._block = malloc(blockSize) # todo check for NULL on failure
+
+ # this seems to be None if too much memory is requested
+ if self._block is None:
+ raise VimbaException(-51)
+
+ def __del__(self):
+
+ # free memory block
+ free = self._crtDLL.free
+ free.argtypes = (c_void_p,)
+ free.restype = None
+ free(self._block)
diff --git a/pymba/vimbaexception.py b/pymba/vimbaexception.py
index 034f194..510479b 100644
--- a/pymba/vimbaexception.py
+++ b/pymba/vimbaexception.py
@@ -1,63 +1,60 @@
# -*- coding: utf-8 -*-
import exceptions
+
class VimbaException(Exception):
- """
- An exception for the AVT Vimba API. It contains a message
- property which is a string indicating what went wrong.
-
- :param errorCode: Error code to be used to look up error message.
- """
-
- @property
- def message(self):
- return self._errorCodes[self.errorCode]
-
- @property
- def errorCode(self):
- return self._errorCode
-
- _errorCodes = { # Vimba C API specific errors
- 0: 'No error.',
- -1: 'Unexpected fault in VimbaC or driver.',
- -2: 'VmbStartup() was not called before the current command.',
- -3: 'The designated instance (camera, feature etc.) cannot be found.',
- -4: 'The given handle is not valid, ensure device open.',
- -5: 'Device was not opened for usage.',
- -6: 'Operation is invalid with the current access mode.',
- -7: 'One of the parameters was invalid (usually an illegal pointer).',
- -8: 'The given struct size is not valid for this version of the API.',
- -9: 'More data was returned in a string/list than space was provided.',
- -10: 'The feature type for this access function was wrong.',
- -11: 'The value was not valid; either out of bounds or not an increment of the minimum.',
- -12: 'Timeout during wait.',
- -13: 'Other error.',
- -14: 'Resources not available (e.g. memory).',
- -15: 'Call is invalid in the current context (e.g. callback).',
- -16: 'No transport layers were found.',
- -17: 'API feature is not implemented.',
- -18: 'API feature is not supported.',
- -19: 'A multiple registers read or write was partially completed.',
-
- # Custom errors
- -50: 'Could not find the specified camera.',
- -51: 'Not enough memory to assign frame buffer.',
- -52: 'Invalid input.',
- -53: 'Could not find the specified feature.',
- -54: 'Could not find the specified interface.',
-
- # Miscellaneous errors
- -1000: 'Oops, unknown internal error code!',
- -1001: 'Oops, this VimbaFeature function is not yet implemented in pymba!'}
-
- def __init__(self, errorCode):
- # if error code does not match expected codes then assign invalid code
- if errorCode in self._errorCodes:
- self._errorCode = errorCode
- else:
- self._errorCode = -1000
-
-
+ """
+ An exception for the AVT Vimba API. It contains a message
+ property which is a string indicating what went wrong.
+
+ :param errorCode: Error code to be used to look up error message.
+ """
+
+ @property
+ def message(self):
+ return self._errorCodes[self.errorCode]
+
+ @property
+ def errorCode(self):
+ return self._errorCode
+
+ _errorCodes = { # Vimba C API specific errors
+ 0: 'No error.',
+ -1: 'Unexpected fault in VimbaC or driver.',
+ -2: 'VmbStartup() was not called before the current command.',
+ -3: 'The designated instance (camera, feature etc.) cannot be found.',
+ -4: 'The given handle is not valid, ensure device open.',
+ -5: 'Device was not opened for usage.',
+ -6: 'Operation is invalid with the current access mode.',
+ -7: 'One of the parameters was invalid (usually an illegal pointer).',
+ -8: 'The given struct size is not valid for this version of the API.',
+ -9: 'More data was returned in a string/list than space was provided.',
+ -10: 'The feature type for this access function was wrong.',
+ -11: 'The value was not valid; either out of bounds or not an increment of the minimum.',
+ -12: 'Timeout during wait.',
+ -13: 'Other error.',
+ -14: 'Resources not available (e.g. memory).',
+ -15: 'Call is invalid in the current context (e.g. callback).',
+ -16: 'No transport layers were found.',
+ -17: 'API feature is not implemented.',
+ -18: 'API feature is not supported.',
+ -19: 'A multiple registers read or write was partially completed.',
+
+ # Custom errors
+ -50: 'Could not find the specified camera.',
+ -51: 'Not enough memory to assign frame buffer.',
+ -52: 'Invalid input.',
+ -53: 'Could not find the specified feature.',
+ -54: 'Could not find the specified interface.',
+ # Miscellaneous errors
+ -1000: 'Oops, unknown internal error code!',
+ -1001: 'Oops, this VimbaFeature function is not yet implemented in pymba!'}
+ def __init__(self, errorCode):
+ # if error code does not match expected codes then assign invalid code
+ if errorCode in self._errorCodes:
+ self._errorCode = errorCode
+ else:
+ self._errorCode = -1000
diff --git a/pymba/vimbafeature.py b/pymba/vimbafeature.py
index c1d7e60..540044d 100644
--- a/pymba/vimbafeature.py
+++ b/pymba/vimbafeature.py
@@ -5,317 +5,322 @@ from vimbadll import VimbaDLL
from ctypes import *
# class may extend a generic Vimba entity class one day...
+
+
class VimbaFeature(object):
- """
- A feature of a Vimba object.
- """
-
- @property
- def name(self):
- return self._name
-
- @property
- def handle(self):
- return self._handle
-
- # lookup relevant function for feature type and pass to that function
- @property
- def value(self):
- return self._getSetTypeFuncs[self._info.featureDataType][0]()
- @value.setter
- def value(self, val):
- self._getSetTypeFuncs[self._info.featureDataType][1](val)
-
- @property
- def range(self):
- return self._rangeQueryTypeFuncs[self._info.featureDataType]()
-
- def __init__(self, name, handle):
-
- # set name and handle
- self._name = name
- self._handle = handle
-
- # set own info
- self._info = self._getInfo()
-
- # type functions dict for looking up correct get/set function to use
- self._getSetTypeFuncs = {0 : (self._notYetImplemented, self._notYetImplemented), # todo
- 1 : (self._getIntFeature, self._setIntFeature),
- 2 : (self._getFloatFeature, self._setFloatFeature),
- 3 : (self._getEnumFeature, self._setEnumFeature),
- 4 : (self._getStringFeature, self._setStringFeature),
- 5 : (self._getBoolFeature, self._setBoolFeature),
- 6 : (self._notYetImplemented, self._notYetImplemented), # todo
- 7 : (self._notYetImplemented, self._notYetImplemented), # todo
- 8 : (self._notYetImplemented, self._notYetImplemented)} # todo
-
- # type functions dict for looking up correct range function to use
- self._rangeQueryTypeFuncs = {0 : self._unknownRange,
- 1 : self._rangeQueryIntFeature,
- 2 : self._rangeQueryFloatFeature,
- 3 : self._unknownRange,
- 4 : self._unknownRange,
- 5 : self._unknownRange,
- 6 : self._unknownRange,
- 7 : self._unknownRange,
- 8 : self._unknownRange}
-
- def getInfo(self):
- """
- Get info of the feature.
-
- :returns: VimbaFeatureInfo object -- feature information..
- """
- return self._info
-
- def _getInfo(self):
- """
- Get info of the feature.
-
- :returns: VimbaFeatureInfo object -- feature information..
- """
- # args for Vimba call
- featureInfo = structs.VimbaFeatureInfo()
-
- # Vimba DLL will return an error code
- errorCode = VimbaDLL.featureInfoQuery(self._handle,
- self._name,
- byref(featureInfo),
- sizeof(featureInfo))
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- return featureInfo
-
- def _notYetImplemented(self, val = None):
- """
- Raises exception if feature value type is not yet defined.
- """
- raise VimbaException(-1001)
-
- def _getIntFeature(self):
- """
- Get the value of an integer feature.
-
- :returns: int -- value of the specified feature.
- """
-
- # create args
- valueToGet = c_int64()
-
- errorCode = VimbaDLL.featureIntGet(self._handle,
- self._name,
- byref(valueToGet))
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- return valueToGet.value
-
- def _setIntFeature(self, valueToSet):
- """
- Set the value of an integer feature.
-
- :param valueToSet: the int value to set for the feature.
- """
-
- errorCode = VimbaDLL.featureIntSet(self._handle,
- self._name,
- valueToSet)
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- def _getFloatFeature(self):
- """
- Get the value of a float feature.
-
- :returns: float -- value of the specified feature.
- """
-
- # create args
- valueToGet = c_double()
-
- errorCode = VimbaDLL.featureFloatGet(self._handle,
- self._name,
- byref(valueToGet))
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- return valueToGet.value
-
- def _setFloatFeature(self, valueToSet):
- """
- Set the value of a float feature.
-
- :param valueToSet: the float value to set for the feature.
- """
-
- errorCode = VimbaDLL.featureFloatSet(self._handle,
- self._name,
- valueToSet)
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- def _getEnumFeature(self):
- """
- Get the value of an enum feature.
-
- :returns: enum -- value of the specified feature.
- """
-
- # create args
- valueToGet = c_char_p()
-
- errorCode = VimbaDLL.featureEnumGet(self._handle,
- self._name,
- byref(valueToGet))
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- return valueToGet.value
-
- def _setEnumFeature(self, valueToSet):
- """
- Set the value of an enum feature.
-
- :param valueToSet: the enum value to set for the feature.
- """
-
- errorCode = VimbaDLL.featureEnumSet(self._handle,
- self._name,
- valueToSet)
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- def _getStringFeature(self):
- """
- Get the value of a string feature.
-
- :returns: string -- value of the specified feature.
- """
-
- # create args
- bufferSize = 256
- valueToGet = create_string_buffer('\000' * bufferSize)
- sizeFilled = c_uint32()
-
- errorCode = VimbaDLL.featureStringGet(self._handle,
- self._name,
- valueToGet,
- bufferSize,
- byref(sizeFilled))
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- return valueToGet.value
-
- def _setStringFeature(self, valueToSet):
- """
- Set the value of a string feature.
-
- :param valueToSet: the string value to set for the feature.
- """
-
- errorCode = VimbaDLL.featureStringSet(self._handle,
- self._name,
- valueToSet)
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- def _getBoolFeature(self):
- """
- Get the value of a bool feature.
-
- :returns: bool -- value of the specified feature.
- """
-
- # create args
- valueToGet = c_bool()
-
- errorCode = VimbaDLL.featureBoolGet(self._handle,
- self._name,
- byref(valueToGet))
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- return valueToGet.value
-
- def _setBoolFeature(self, valueToSet):
- """
- Set the value of a bool feature.
-
- :param valueToSet: the bool value to set for the feature.
- """
-
- errorCode = VimbaDLL.featureBoolSet(self._handle,
- self._name,
- valueToSet)
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- def _unknownRange(self):
- """
- Returns empty for ranges that have not been implemented.
- """
- return ''
-
- def _rangeQueryIntFeature(self):
- """
- Get the range of an int feature.
-
- :returns: tuple -- min and max range.
- """
-
- # create args
- minToGet = c_int64()
- maxToGet = c_int64()
-
- errorCode = VimbaDLL.featureIntRangeQuery(self._handle,
- self._name,
- byref(minToGet),
- byref(maxToGet))
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- return (int(str(minToGet.value)), int(str(maxToGet.value)))
-
- def _rangeQueryFloatFeature(self):
- """
- Get the range of a float feature.
-
- :returns: tuple -- min and max range.
- """
-
- # create args
- minToGet = c_double()
- maxToGet = c_double()
-
- errorCode = VimbaDLL.featureFloatRangeQuery(self._handle,
- self._name,
- byref(minToGet),
- byref(maxToGet))
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- return (minToGet.value, maxToGet.value)
-
- #def _rangeQueryEnumFeature(self):
- # """
- # Get the range of an enum feature.
- #
- # :returns: tuple -- min and max range.
- # """
- #
- # # create args
- # minToGet = c_uint32()
- # maxToGet = c_uint32()
- #
- # errorCode = VimbaDLL.featureEnumRangeQuery(self._handle,
- # self._name,
- # byref(minToGet),
- # byref(maxToGet))
- # if errorCode != 0:
- # raise VimbaException(errorCode)
- #
- # return (minToGet.value, maxToGet.value)
-
+
+ """
+ A feature of a Vimba object.
+ """
+
+ @property
+ def name(self):
+ return self._name
+
+ @property
+ def handle(self):
+ return self._handle
+
+ # lookup relevant function for feature type and pass to that function
+ @property
+ def value(self):
+ return self._getSetTypeFuncs[self._info.featureDataType][0]()
+
+ @value.setter
+ def value(self, val):
+ self._getSetTypeFuncs[self._info.featureDataType][1](val)
+
+ @property
+ def range(self):
+ return self._rangeQueryTypeFuncs[self._info.featureDataType]()
+
+ def __init__(self, name, handle):
+
+ # set name and handle
+ self._name = name
+ self._handle = handle
+
+ # set own info
+ self._info = self._getInfo()
+
+ # type functions dict for looking up correct get/set function to use
+ self._getSetTypeFuncs = {0: (self._notYetImplemented, self._notYetImplemented), # todo
+ 1: (self._getIntFeature, self._setIntFeature),
+ 2: (self._getFloatFeature, self._setFloatFeature),
+ 3: (self._getEnumFeature, self._setEnumFeature),
+ 4: (self._getStringFeature, self._setStringFeature),
+ 5: (self._getBoolFeature, self._setBoolFeature),
+ # todo
+ 6: (self._notYetImplemented, self._notYetImplemented),
+ # todo
+ 7: (self._notYetImplemented, self._notYetImplemented),
+ 8: (self._notYetImplemented, self._notYetImplemented)} # todo
+
+ # type functions dict for looking up correct range function to use
+ self._rangeQueryTypeFuncs = {0: self._unknownRange,
+ 1: self._rangeQueryIntFeature,
+ 2: self._rangeQueryFloatFeature,
+ 3: self._unknownRange,
+ 4: self._unknownRange,
+ 5: self._unknownRange,
+ 6: self._unknownRange,
+ 7: self._unknownRange,
+ 8: self._unknownRange}
+
+ def getInfo(self):
+ """
+ Get info of the feature.
+
+ :returns: VimbaFeatureInfo object -- feature information..
+ """
+ return self._info
+
+ def _getInfo(self):
+ """
+ Get info of the feature.
+
+ :returns: VimbaFeatureInfo object -- feature information..
+ """
+ # args for Vimba call
+ featureInfo = structs.VimbaFeatureInfo()
+
+ # Vimba DLL will return an error code
+ errorCode = VimbaDLL.featureInfoQuery(self._handle,
+ self._name,
+ byref(featureInfo),
+ sizeof(featureInfo))
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ return featureInfo
+
+ def _notYetImplemented(self, val=None):
+ """
+ Raises exception if feature value type is not yet defined.
+ """
+ raise VimbaException(-1001)
+
+ def _getIntFeature(self):
+ """
+ Get the value of an integer feature.
+
+ :returns: int -- value of the specified feature.
+ """
+
+ # create args
+ valueToGet = c_int64()
+
+ errorCode = VimbaDLL.featureIntGet(self._handle,
+ self._name,
+ byref(valueToGet))
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ return valueToGet.value
+
+ def _setIntFeature(self, valueToSet):
+ """
+ Set the value of an integer feature.
+
+ :param valueToSet: the int value to set for the feature.
+ """
+
+ errorCode = VimbaDLL.featureIntSet(self._handle,
+ self._name,
+ valueToSet)
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ def _getFloatFeature(self):
+ """
+ Get the value of a float feature.
+
+ :returns: float -- value of the specified feature.
+ """
+
+ # create args
+ valueToGet = c_double()
+
+ errorCode = VimbaDLL.featureFloatGet(self._handle,
+ self._name,
+ byref(valueToGet))
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ return valueToGet.value
+
+ def _setFloatFeature(self, valueToSet):
+ """
+ Set the value of a float feature.
+
+ :param valueToSet: the float value to set for the feature.
+ """
+
+ errorCode = VimbaDLL.featureFloatSet(self._handle,
+ self._name,
+ valueToSet)
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ def _getEnumFeature(self):
+ """
+ Get the value of an enum feature.
+
+ :returns: enum -- value of the specified feature.
+ """
+
+ # create args
+ valueToGet = c_char_p()
+
+ errorCode = VimbaDLL.featureEnumGet(self._handle,
+ self._name,
+ byref(valueToGet))
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ return valueToGet.value
+
+ def _setEnumFeature(self, valueToSet):
+ """
+ Set the value of an enum feature.
+
+ :param valueToSet: the enum value to set for the feature.
+ """
+
+ errorCode = VimbaDLL.featureEnumSet(self._handle,
+ self._name,
+ valueToSet)
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ def _getStringFeature(self):
+ """
+ Get the value of a string feature.
+
+ :returns: string -- value of the specified feature.
+ """
+
+ # create args
+ bufferSize = 256
+ valueToGet = create_string_buffer('\000' * bufferSize)
+ sizeFilled = c_uint32()
+
+ errorCode = VimbaDLL.featureStringGet(self._handle,
+ self._name,
+ valueToGet,
+ bufferSize,
+ byref(sizeFilled))
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ return valueToGet.value
+
+ def _setStringFeature(self, valueToSet):
+ """
+ Set the value of a string feature.
+
+ :param valueToSet: the string value to set for the feature.
+ """
+
+ errorCode = VimbaDLL.featureStringSet(self._handle,
+ self._name,
+ valueToSet)
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ def _getBoolFeature(self):
+ """
+ Get the value of a bool feature.
+
+ :returns: bool -- value of the specified feature.
+ """
+
+ # create args
+ valueToGet = c_bool()
+
+ errorCode = VimbaDLL.featureBoolGet(self._handle,
+ self._name,
+ byref(valueToGet))
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ return valueToGet.value
+
+ def _setBoolFeature(self, valueToSet):
+ """
+ Set the value of a bool feature.
+
+ :param valueToSet: the bool value to set for the feature.
+ """
+
+ errorCode = VimbaDLL.featureBoolSet(self._handle,
+ self._name,
+ valueToSet)
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ def _unknownRange(self):
+ """
+ Returns empty for ranges that have not been implemented.
+ """
+ return ''
+
+ def _rangeQueryIntFeature(self):
+ """
+ Get the range of an int feature.
+
+ :returns: tuple -- min and max range.
+ """
+
+ # create args
+ minToGet = c_int64()
+ maxToGet = c_int64()
+
+ errorCode = VimbaDLL.featureIntRangeQuery(self._handle,
+ self._name,
+ byref(minToGet),
+ byref(maxToGet))
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ return (int(str(minToGet.value)), int(str(maxToGet.value)))
+
+ def _rangeQueryFloatFeature(self):
+ """
+ Get the range of a float feature.
+
+ :returns: tuple -- min and max range.
+ """
+
+ # create args
+ minToGet = c_double()
+ maxToGet = c_double()
+
+ errorCode = VimbaDLL.featureFloatRangeQuery(self._handle,
+ self._name,
+ byref(minToGet),
+ byref(maxToGet))
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ return (minToGet.value, maxToGet.value)
+
+ # def _rangeQueryEnumFeature(self):
+ # """
+ # Get the range of an enum feature.
+ #
+ # :returns: tuple -- min and max range.
+ # """
+ #
+ # create args
+ # minToGet = c_uint32()
+ # maxToGet = c_uint32()
+ #
+ # errorCode = VimbaDLL.featureEnumRangeQuery(self._handle,
+ # self._name,
+ # byref(minToGet),
+ # byref(maxToGet))
+ # if errorCode != 0:
+ # raise VimbaException(errorCode)
+ #
+ # return (minToGet.value, maxToGet.value)
diff --git a/pymba/vimbainterface.py b/pymba/vimbainterface.py
index 03a5f80..63963ba 100644
--- a/pymba/vimbainterface.py
+++ b/pymba/vimbainterface.py
@@ -6,39 +6,41 @@ from vimbadll import VimbaDLL
from ctypes import *
# interface features are automatically readable as object attributes.
+
+
class VimbaInterface(VimbaObject):
- """
- A Vimba interface object. This class provides the minimal access
- to Vimba functions required to control the interface.
- """
-
- @property
- def interfaceIdString(self):
- return self._interfaceIdString
-
- # own handle is inherited as self._handle
- def __init__(self, interfaceIdString):
-
- # call super constructor
- super(VimbaInterface, self).__init__()
-
- # set ID
- self._interfaceIdString = interfaceIdString
-
- def openInterface(self):
- """
- Open the interface.
- """
- errorCode = VimbaDLL.interfaceOpen(self._interfaceIdString,
- byref(self._handle))
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- def closeInterface(self):
- """
- Close the interface.
- """
- errorCode = VimbaDLL.interfaceClose(self._handle)
- if errorCode != 0:
- raise VimbaException(errorCode)
- \ No newline at end of file
+
+ """
+ A Vimba interface object. This class provides the minimal access
+ to Vimba functions required to control the interface.
+ """
+
+ @property
+ def interfaceIdString(self):
+ return self._interfaceIdString
+
+ # own handle is inherited as self._handle
+ def __init__(self, interfaceIdString):
+
+ # call super constructor
+ super(VimbaInterface, self).__init__()
+
+ # set ID
+ self._interfaceIdString = interfaceIdString
+
+ def openInterface(self):
+ """
+ Open the interface.
+ """
+ errorCode = VimbaDLL.interfaceOpen(self._interfaceIdString,
+ byref(self._handle))
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ def closeInterface(self):
+ """
+ Close the interface.
+ """
+ errorCode = VimbaDLL.interfaceClose(self._handle)
+ if errorCode != 0:
+ raise VimbaException(errorCode)
diff --git a/pymba/vimbaobject.py b/pymba/vimbaobject.py
index 8e2f812..964f811 100644
--- a/pymba/vimbaobject.py
+++ b/pymba/vimbaobject.py
@@ -5,209 +5,214 @@ from vimbafeature import VimbaFeature
from vimbadll import VimbaDLL
from ctypes import *
+
class VimbaObject(object):
- """
- A Vimba object has a handle and features associated with it.
- Objects include System, Camera, Interface and AncillaryData.
- """
-
- @property
- def handle(self):
- return self._handle
-
- def __init__(self):
- # create own handle
- self._handle = c_void_p()
-
- # list of VimbaFeatureInfo objects
- # can't set yet as the object (e.g. a camera) won't be
- # opened yet, therefore no event for object opening
- # so will have it populate by user interaction
- # and blame them if the object is not opened then
- self._featureInfos = None
-
- # override getattr for undefined attributes
- def __getattr__(self, attr):
-
- # if a feature value requested (requires object (camera) open)
- if attr in self.getFeatureNames():
- return VimbaFeature(attr, self._handle).value
-
- # otherwise don't know about it
- raise AttributeError(''.join(["'VimbaObject' has no attribute '",
- attr,
- "'"]))
-
- # override setattr for undefined attributes
- def __setattr__(self, attr, val):
-
- # set privates as normal
- # check this first to allow all privates to set normally
- # and avoid recursion errors
- if attr.startswith('_'):
- super(VimbaObject, self).__setattr__(attr, val)
-
- # if it's an actual camera feature (requires camera open)
- elif attr in self.getFeatureNames():
- VimbaFeature(attr, self._handle).value = val
-
- # otherwise just set the attribute value as normal
- else:
- super(VimbaObject, self).__setattr__(attr, val)
-
- def _getFeatureInfos(self):
- """
- Gets feature info of all available features. Will
- cause error if object/camera is not opened.
-
- :returns: list -- feature info for available features.
- """
- # check it's populated as can't populate it in __init__
- if self._featureInfos is None:
- # args
- dummyFeatureInfo = structs.VimbaFeatureInfo()
- numFound = c_uint32(-1)
-
- # call once to get number of available features
- # Vimba DLL will return an error code
- errorCode = VimbaDLL.featuresList(self._handle,
- byref(dummyFeatureInfo),
- 0,
- byref(numFound),
- sizeof(dummyFeatureInfo))
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- # number of features specified by Vimba
- numFeatures = numFound.value
-
- # args
- featureInfoArray = (structs.VimbaFeatureInfo * numFeatures)()
-
- # call again to get the features
- # Vimba DLL will return an error code
- errorCode = VimbaDLL.featuresList(self._handle,
- featureInfoArray,
- numFeatures,
- byref(numFound),
- sizeof(dummyFeatureInfo))
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- self._featureInfos = list(featInfo for featInfo in featureInfoArray)
- return self._featureInfos
-
- def getFeatureNames(self):
- """
- Get names of all available features.
-
- :returns: list -- feature names for available features.
- """
- return list(featInfo.name for featInfo in self._getFeatureInfos())
-
- def getFeatureInfo(self, featureName):
- """
- Gets feature info object of specified feature.
-
- :param featureName: the name of the feature.
-
- :returns: VimbaFeatureInfo object -- the feature info object specified.
- """
- # don't do this live as we already have this info
- # return info object, if it exists
- for featInfo in self._getFeatureInfos():
- if featInfo.name == featureName:
- return featInfo
- # otherwise raise error
- raise VimbaException(-53)
-
- # don't think we ever need to return a feature object...
- #def getFeature(self, featureName):
-
- def getFeatureRange(self, featureName):
- """
- Get valid range of feature values.
-
- :param featureName: name of the feature to query.
-
- :returns: tuple -- range as (feature min value, feature max value).
- """
- # can't cache this, need to look it up live
- return VimbaFeature(featureName, self._handle).range
-
- def runFeatureCommand(self, featureName):
- """
- Run a feature command.
-
- :param featureName: the name of the feature.
- """
- # run a command
- errorCode = VimbaDLL.featureCommandRun(self._handle,
- featureName)
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- def readRegister(self, address):
- # note that the underlying Vimba function allows reading of an array
- # of registers, but only one address/value at a time is implemented here
- """
- Read from a register of the module (camera).
-
- :param address: the address of the register to read.
-
- :returns: int -- value of register.
- """
- readCount = 1
-
- # check address validity
- try:
- regAddress = c_uint64(int(address, 16))
- except:
- raise VimbaException(-52)
-
- regData = c_uint64()
- numCompleteReads = c_uint32()
-
- errorCode = VimbaDLL.registersRead(self.handle,
- readCount,
- byref(regAddress),
- byref(regData),
- byref(numCompleteReads))
-
- if errorCode != 0:
- raise VimbaException(errorCode)
-
- return regData.value
-
- def writeRegister(self, address, value):
- # note that the underlying Vimba function allows writing of an array
- # of registers, but only one address/value at a time is implemented here
- """
- Read from a register of the module (camera).
-
- :param address: the address of the register to read.
- :param value: the value to set in hex.
- """
- writeCount = 1
-
- # check address validity
- try:
- regAddress = c_uint64(int(address, 16))
- except:
- raise VimbaException(-52)
-
- # check value validity
- try:
- regData = c_uint64(int(value, 16))
- except:
- raise VimbaException(-52)
-
- numCompleteWrites = c_uint32()
-
- errorCode = VimbaDLL.registersWrite(self.handle,
- writeCount,
- byref(regAddress),
- byref(regData),
- byref(numCompleteWrites))
- if errorCode != 0:
- raise VimbaException(errorCode)
+
+ """
+ A Vimba object has a handle and features associated with it.
+ Objects include System, Camera, Interface and AncillaryData.
+ """
+
+ @property
+ def handle(self):
+ return self._handle
+
+ def __init__(self):
+ # create own handle
+ self._handle = c_void_p()
+
+ # list of VimbaFeatureInfo objects
+ # can't set yet as the object (e.g. a camera) won't be
+ # opened yet, therefore no event for object opening
+ # so will have it populate by user interaction
+ # and blame them if the object is not opened then
+ self._featureInfos = None
+
+ # override getattr for undefined attributes
+ def __getattr__(self, attr):
+
+ # if a feature value requested (requires object (camera) open)
+ if attr in self.getFeatureNames():
+ return VimbaFeature(attr, self._handle).value
+
+ # otherwise don't know about it
+ raise AttributeError(''.join(["'VimbaObject' has no attribute '",
+ attr,
+ "'"]))
+
+ # override setattr for undefined attributes
+ def __setattr__(self, attr, val):
+
+ # set privates as normal
+ # check this first to allow all privates to set normally
+ # and avoid recursion errors
+ if attr.startswith('_'):
+ super(VimbaObject, self).__setattr__(attr, val)
+
+ # if it's an actual camera feature (requires camera open)
+ elif attr in self.getFeatureNames():
+ VimbaFeature(attr, self._handle).value = val
+
+ # otherwise just set the attribute value as normal
+ else:
+ super(VimbaObject, self).__setattr__(attr, val)
+
+ def _getFeatureInfos(self):
+ """
+ Gets feature info of all available features. Will
+ cause error if object/camera is not opened.
+
+ :returns: list -- feature info for available features.
+ """
+ # check it's populated as can't populate it in __init__
+ if self._featureInfos is None:
+ # args
+ dummyFeatureInfo = structs.VimbaFeatureInfo()
+ numFound = c_uint32(-1)
+
+ # call once to get number of available features
+ # Vimba DLL will return an error code
+ errorCode = VimbaDLL.featuresList(self._handle,
+ byref(dummyFeatureInfo),
+ 0,
+ byref(numFound),
+ sizeof(dummyFeatureInfo))
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ # number of features specified by Vimba
+ numFeatures = numFound.value
+
+ # args
+ featureInfoArray = (structs.VimbaFeatureInfo * numFeatures)()
+
+ # call again to get the features
+ # Vimba DLL will return an error code
+ errorCode = VimbaDLL.featuresList(self._handle,
+ featureInfoArray,
+ numFeatures,
+ byref(numFound),
+ sizeof(dummyFeatureInfo))
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ self._featureInfos = list(
+ featInfo for featInfo in featureInfoArray)
+ return self._featureInfos
+
+ def getFeatureNames(self):
+ """
+ Get names of all available features.
+
+ :returns: list -- feature names for available features.
+ """
+ return list(featInfo.name for featInfo in self._getFeatureInfos())
+
+ def getFeatureInfo(self, featureName):
+ """
+ Gets feature info object of specified feature.
+
+ :param featureName: the name of the feature.
+
+ :returns: VimbaFeatureInfo object -- the feature info object specified.
+ """
+ # don't do this live as we already have this info
+ # return info object, if it exists
+ for featInfo in self._getFeatureInfos():
+ if featInfo.name == featureName:
+ return featInfo
+ # otherwise raise error
+ raise VimbaException(-53)
+
+ # don't think we ever need to return a feature object...
+ # def getFeature(self, featureName):
+
+ def getFeatureRange(self, featureName):
+ """
+ Get valid range of feature values.
+
+ :param featureName: name of the feature to query.
+
+ :returns: tuple -- range as (feature min value, feature max value).
+ """
+ # can't cache this, need to look it up live
+ return VimbaFeature(featureName, self._handle).range
+
+ def runFeatureCommand(self, featureName):
+ """
+ Run a feature command.
+
+ :param featureName: the name of the feature.
+ """
+ # run a command
+ errorCode = VimbaDLL.featureCommandRun(self._handle,
+ featureName)
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ def readRegister(self, address):
+ # note that the underlying Vimba function allows reading of an array
+ # of registers, but only one address/value at a time is implemented
+ # here
+ """
+ Read from a register of the module (camera).
+
+ :param address: the address of the register to read.
+
+ :returns: int -- value of register.
+ """
+ readCount = 1
+
+ # check address validity
+ try:
+ regAddress = c_uint64(int(address, 16))
+ except:
+ raise VimbaException(-52)
+
+ regData = c_uint64()
+ numCompleteReads = c_uint32()
+
+ errorCode = VimbaDLL.registersRead(self.handle,
+ readCount,
+ byref(regAddress),
+ byref(regData),
+ byref(numCompleteReads))
+
+ if errorCode != 0:
+ raise VimbaException(errorCode)
+
+ return regData.value
+
+ def writeRegister(self, address, value):
+ # note that the underlying Vimba function allows writing of an array
+ # of registers, but only one address/value at a time is implemented
+ # here
+ """
+ Read from a register of the module (camera).
+
+ :param address: the address of the register to read.
+ :param value: the value to set in hex.
+ """
+ writeCount = 1
+
+ # check address validity
+ try:
+ regAddress = c_uint64(int(address, 16))
+ except:
+ raise VimbaException(-52)
+
+ # check value validity
+ try:
+ regData = c_uint64(int(value, 16))
+ except:
+ raise VimbaException(-52)
+
+ numCompleteWrites = c_uint32()
+
+ errorCode = VimbaDLL.registersWrite(self.handle,
+ writeCount,
+ byref(regAddress),
+ byref(regData),
+ byref(numCompleteWrites))
+ if errorCode != 0:
+ raise VimbaException(errorCode)
diff --git a/pymba/vimbastructure.py b/pymba/vimbastructure.py
index 7b1e65c..73c4e96 100644
--- a/pymba/vimbastructure.py
+++ b/pymba/vimbastructure.py
@@ -1,99 +1,106 @@
# -*- coding: utf-8 -*-
from ctypes import *
-
+
class VimbaVersion(Structure):
- _fields_ = [('major', c_uint32),
- ('minor', c_uint32),
- ('patch', c_uint32)]
+ _fields_ = [('major', c_uint32),
+ ('minor', c_uint32),
+ ('patch', c_uint32)]
class VimbaInterfaceInfo(Structure):
- _fields_ = [('interfaceIdString', c_char_p), # Unique identifier for each interface
- ('interfaceType', c_uint32), # Interface type, see VmbInterfaceType
- ('interfaceName', c_char_p), # Interface name, given by the transport layer
- ('serialString', c_char_p), # Serial number
- ('permittedAccess', c_uint32)] # Used access mode, see VmbAccessModeType
-
- def getFieldNames(self):
- """
- Get field names.
- """
- return [field[0] for field in self._fields_]
+ _fields_ = [('interfaceIdString', c_char_p), # Unique identifier for each interface
+ # Interface type, see VmbInterfaceType
+ ('interfaceType', c_uint32),
+ # Interface name, given by the transport layer
+ ('interfaceName', c_char_p),
+ ('serialString', c_char_p), # Serial number
+ ('permittedAccess', c_uint32)] # Used access mode, see VmbAccessModeType
+
+ def getFieldNames(self):
+ """
+ Get field names.
+ """
+ return [field[0] for field in self._fields_]
class VimbaCameraInfo(Structure):
- _fields_ = [('cameraIdString', c_char_p), # Unique identifier for each camera
- ('cameraName', c_char_p), # Name of the camera
- ('modelName', c_char_p), # Model name
- ('serialString', c_char_p), # Serial number
- ('permittedAccess', c_uint32), # Used access mode, see VmbAccessModeType
- ('interfaceIdString', c_char_p)] # Unique value for each interface or bus
-
- def getFieldNames(self):
- """
- Get field names.
- """
- return [field[0] for field in self._fields_]
-
+ _fields_ = [('cameraIdString', c_char_p), # Unique identifier for each camera
+ ('cameraName', c_char_p), # Name of the camera
+ ('modelName', c_char_p), # Model name
+ ('serialString', c_char_p), # Serial number
+ # Used access mode, see VmbAccessModeType
+ ('permittedAccess', c_uint32),
+ ('interfaceIdString', c_char_p)] # Unique value for each interface or bus
+
+ def getFieldNames(self):
+ """
+ Get field names.
+ """
+ return [field[0] for field in self._fields_]
+
class VimbaFeatureInfo(Structure):
- _fields_ = [('name', c_char_p),
- ('featureDataType', c_uint32),
- ('featureFlags', c_uint32),
- ('category', c_char_p),
- ('displayName', c_char_p),
- ('pollingTime', c_uint32),
- ('unit', c_char_p),
- ('representation', c_char_p),
- ('visibility', c_uint32),
- ('tooltip', c_char_p),
- ('description', c_char_p),
- ('sfncNamespace', c_char_p),
- ('isStreamable', c_bool),
- ('hasAffectedFeatures', c_bool),
- ('hasSelectedFeatures', c_bool)]
-
- def getFieldNames(self):
- """
- Get field names.
- """
- return [field[0] for field in self._fields_]
+ _fields_ = [('name', c_char_p),
+ ('featureDataType', c_uint32),
+ ('featureFlags', c_uint32),
+ ('category', c_char_p),
+ ('displayName', c_char_p),
+ ('pollingTime', c_uint32),
+ ('unit', c_char_p),
+ ('representation', c_char_p),
+ ('visibility', c_uint32),
+ ('tooltip', c_char_p),
+ ('description', c_char_p),
+ ('sfncNamespace', c_char_p),
+ ('isStreamable', c_bool),
+ ('hasAffectedFeatures', c_bool),
+ ('hasSelectedFeatures', c_bool)]
+
+ def getFieldNames(self):
+ """
+ Get field names.
+ """
+ return [field[0] for field in self._fields_]
class VimbaFrame(Structure):
-
- # IN
- _fields_ = [('buffer', c_void_p), # Comprises image and ancillary data
- ('bufferSize', c_uint32), # Size of the data buffer
-
- ('context', c_void_p * 4), # User context filled during queuing
-
- # OUT
- ('receiveStatus', c_int32), # Resulting status of the receive operation
- ('receiveFlags', c_uint32), # Resulting flags of the receive operation
-
- ('imageSize', c_uint32), # Size of the image data inside the data buffer
- ('ancillarySize', c_uint32), # Size of the ancillary data inside the data buffer
-
- ('pixelFormat', c_uint32), # Pixel format of the image
-
- ('width', c_uint32), # Width of an image
- ('height', c_uint32), # Height of an image
- ('offsetX', c_uint32), # Horizontal offset of an image
- ('offsetY', c_uint32), # Vertical offset of an image
-
- ('frameID', c_uint64), # Unique ID of this frame in this stream
- ('timestamp', c_uint64)] # Timestamp of the data transfer
-
- def getFieldNames(self):
- """
- Get field names.
- """
- return [field[0] for field in self._fields_]
-
-
-
-
-
+
+ # IN
+ _fields_ = [('buffer', c_void_p), # Comprises image and ancillary data
+ ('bufferSize', c_uint32), # Size of the data buffer
+
+ # User context filled during queuing
+ ('context', c_void_p * 4),
+
+ # OUT
+ # Resulting status of the receive operation
+ ('receiveStatus', c_int32),
+ # Resulting flags of the receive operation
+ ('receiveFlags', c_uint32),
+
+ # Size of the image data inside the data buffer
+ ('imageSize', c_uint32),
+ # Size of the ancillary data inside the data buffer
+ ('ancillarySize', c_uint32),
+
+ # Pixel format of the image
+ ('pixelFormat', c_uint32),
+
+ ('width', c_uint32), # Width of an image
+ ('height', c_uint32), # Height of an image
+ # Horizontal offset of an image
+ ('offsetX', c_uint32),
+ # Vertical offset of an image
+ ('offsetY', c_uint32),
+
+ # Unique ID of this frame in this stream
+ ('frameID', c_uint64),
+ ('timestamp', c_uint64)] # Timestamp of the data transfer
+
+ def getFieldNames(self):
+ """
+ Get field names.
+ """
+ return [field[0] for field in self._fields_]
diff --git a/pymba/vimbasystem.py b/pymba/vimbasystem.py
index 1e04755..94cc49e 100644
--- a/pymba/vimbasystem.py
+++ b/pymba/vimbasystem.py
@@ -3,17 +3,21 @@ from vimbaobject import VimbaObject
from ctypes import *
# system features are automatically readable as attributes.
+
+
class VimbaSystem(VimbaObject):
- """
- A Vimba system object. This class provides the minimal access
- to Vimba functions required to control the system.
- """
-
- # own handle is inherited as self._handle
- def __init__(self):
-
- # call super constructor
- super(VimbaSystem, self).__init__()
-
- # set own handle manually
- self._handle = c_void_p(1)
+
+ """
+ A Vimba system object. This class provides the minimal access
+ to Vimba functions required to control the system.
+ """
+
+ # own handle is inherited as self._handle
+
+ def __init__(self):
+
+ # call super constructor
+ super(VimbaSystem, self).__init__()
+
+ # set own handle manually
+ self._handle = c_void_p(1)