diff options
| author | morefigs <morefigs@gmail.com> | 2013-12-24 20:15:12 -0800 |
|---|---|---|
| committer | morefigs <morefigs@gmail.com> | 2013-12-24 20:15:12 -0800 |
| commit | 91b643447d9a25b0c95d2da7fb0631197e8c59e9 (patch) | |
| tree | 0c074cdb4ba654f38cee75bb5699a099f5abe6f7 | |
| parent | a4890f84e2b0c32451ab3ce2267a576ff3c2f04c (diff) | |
| download | pymba-91b643447d9a25b0c95d2da7fb0631197e8c59e9.tar.gz pymba-91b643447d9a25b0c95d2da7fb0631197e8c59e9.zip | |
Create vimbacamera.py
| -rw-r--r-- | vimbacamera.py | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/vimbacamera.py b/vimbacamera.py new file mode 100644 index 0000000..3dc8643 --- /dev/null +++ b/vimbacamera.py @@ -0,0 +1,124 @@ +# -*- coding: utf-8 -*- +import vimbastructure as structs +from vimbaobject import VimbaObject +from vimbaexception import VimbaException +from vimbaframe import VimbaFrame +from vimbadll import VimbaDLL +from ctypes import * + +# camera features are automatically set as attributes of camera. +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) + + + |
