aboutsummaryrefslogtreecommitdiff
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
parentd9bf2770f2c9ea4ccc5cbefc766191d852f6b1e2 (diff)
downloadpymba-0b5baee69b57cd822c260f395fc881a8e110c5b1.tar.gz
pymba-0b5baee69b57cd822c260f395fc881a8e110c5b1.zip
Added Vimba system and Vimba interface support
-rw-r--r--vimba.py103
-rw-r--r--vimbacamera.py4
-rw-r--r--vimbadll.py25
-rw-r--r--vimbaexception.py3
-rw-r--r--vimbafeature.py2
-rw-r--r--vimbainterface.py44
-rw-r--r--vimbaobject.py6
-rw-r--r--vimbastructure.py17
-rw-r--r--vimbasystem.py19
9 files changed, 207 insertions, 16 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.
diff --git a/vimbacamera.py b/vimbacamera.py
index 3dc8643..747eb4c 100644
--- a/vimbacamera.py
+++ b/vimbacamera.py
@@ -6,7 +6,7 @@ from vimbaframe import VimbaFrame
from vimbadll import VimbaDLL
from ctypes import *
-# camera features are automatically set as attributes of camera.
+# camera features are automatically readable as object attributes.
class VimbaCamera(VimbaObject):
"""
A Vimba camera object. This class provides the minimal access
@@ -25,7 +25,7 @@ class VimbaCamera(VimbaObject):
# set ID
self._cameraIdString = cameraIdString
-
+
# set own info
self._info = self._getInfo()
diff --git a/vimbadll.py b/vimbadll.py
index e22ba49..ddfbb22 100644
--- a/vimbadll.py
+++ b/vimbadll.py
@@ -72,9 +72,9 @@ class VimbaDLL(object):
# -- VmbCaptureFrameWait()
# -- VmbCaptureQueueFlush()
#
- # VmbInterfacesList()
- # VmbInterfaceOpen()
- # VmbInterfaceClose()
+ # -- VmbInterfacesList()
+ # -- VmbInterfaceOpen()
+ # -- VmbInterfaceClose()
#
# VmbAncillaryDataOpen()
# VmbAncillaryDataClose()
@@ -288,6 +288,25 @@ class VimbaDLL(object):
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
diff --git a/vimbaexception.py b/vimbaexception.py
index 1c7627d..034f194 100644
--- a/vimbaexception.py
+++ b/vimbaexception.py
@@ -44,10 +44,11 @@ class VimbaException(Exception):
-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!'}
+ -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
diff --git a/vimbafeature.py b/vimbafeature.py
index b40b9cf..c1d7e60 100644
--- a/vimbafeature.py
+++ b/vimbafeature.py
@@ -77,7 +77,7 @@ class VimbaFeature(object):
"""
# args for Vimba call
featureInfo = structs.VimbaFeatureInfo()
-
+
# Vimba DLL will return an error code
errorCode = VimbaDLL.featureInfoQuery(self._handle,
self._name,
diff --git a/vimbainterface.py b/vimbainterface.py
new file mode 100644
index 0000000..03a5f80
--- /dev/null
+++ b/vimbainterface.py
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+import vimbastructure as structs
+from vimbaobject import VimbaObject
+from vimbaexception import VimbaException
+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
diff --git a/vimbaobject.py b/vimbaobject.py
index c1acb55..8e2f812 100644
--- a/vimbaobject.py
+++ b/vimbaobject.py
@@ -20,10 +20,10 @@ class VimbaObject(object):
self._handle = c_void_p()
# list of VimbaFeatureInfo objects
- # can't set yet as object (camera) won't be
- # opened yet, therefore no event for camera opening
+ # 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 camera is not opened then
+ # and blame them if the object is not opened then
self._featureInfos = None
# override getattr for undefined attributes
diff --git a/vimbastructure.py b/vimbastructure.py
index 9384d6b..7b1e65c 100644
--- a/vimbastructure.py
+++ b/vimbastructure.py
@@ -1,13 +1,27 @@
# -*- coding: utf-8 -*-
from ctypes import *
+
class VimbaVersion(Structure):
_fields_ = [('major', c_uint32),
('minor', c_uint32),
('patch', c_uint32)]
-# populated by calling VimbaDLL.cameraInfoQuery()
+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_]
+
+
class VimbaCameraInfo(Structure):
_fields_ = [('cameraIdString', c_char_p), # Unique identifier for each camera
('cameraName', c_char_p), # Name of the camera
@@ -23,7 +37,6 @@ class VimbaCameraInfo(Structure):
return [field[0] for field in self._fields_]
-# populated by calling VimbaDLL.featureInfoQuery()
class VimbaFeatureInfo(Structure):
_fields_ = [('name', c_char_p),
diff --git a/vimbasystem.py b/vimbasystem.py
new file mode 100644
index 0000000..1e04755
--- /dev/null
+++ b/vimbasystem.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+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)