aboutsummaryrefslogtreecommitdiff
path: root/vimba.py
diff options
context:
space:
mode:
authormore figs <morefigs@gmail.com>2014-03-08 10:16:44 +1100
committermore figs <morefigs@gmail.com>2014-03-08 10:16:44 +1100
commit0b5baee69b57cd822c260f395fc881a8e110c5b1 (patch)
treec2770a46371c6d23f907e9b5cfc5e3207c9c5089 /vimba.py
parentd9bf2770f2c9ea4ccc5cbefc766191d852f6b1e2 (diff)
downloadpymba-0b5baee69b57cd822c260f395fc881a8e110c5b1.tar.gz
pymba-0b5baee69b57cd822c260f395fc881a8e110c5b1.zip
Added Vimba system and Vimba interface support
Diffstat (limited to 'vimba.py')
-rw-r--r--vimba.py103
1 files changed, 99 insertions, 4 deletions
diff --git a/vimba.py b/vimba.py
index 8c7d98d..0add297 100644
--- a/vimba.py
+++ b/vimba.py
@@ -2,7 +2,9 @@
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):
@@ -14,14 +16,58 @@ class Vimba(object):
# todo - assign camera info and feature info as own object proeprties
def __init__(self):
-
- # list of VimbaCameraInfo objects
+
+ # 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.
@@ -59,6 +105,22 @@ class Vimba(object):
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.
@@ -66,7 +128,23 @@ class Vimba(object):
: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.
@@ -82,10 +160,27 @@ class Vimba(object):
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 objects based on camera ID string. Will not recreate
+ Gets camera object based on camera ID string. Will not recreate
camera object if it already exists.
:param cameraId: the ID of the camera.