diff options
| author | Sven <sven.riede@alliedvision.com> | 2017-08-24 10:26:49 +0200 |
|---|---|---|
| committer | Sven <sven.riede@alliedvision.com> | 2017-08-24 10:26:49 +0200 |
| commit | e2fd8760222eaa31fd50b3f3547ef6012943944f (patch) | |
| tree | e2f71105c77eae9ba395d6ed3aebbfdce52645c0 | |
| parent | 3396cbf5a809635cbe56910cb5cf024b3493301d (diff) | |
| download | pymba-e2fd8760222eaa31fd50b3f3547ef6012943944f.tar.gz pymba-e2fd8760222eaa31fd50b3f3547ef6012943944f.zip | |
getCameraInfo and getCamera extended to enable getting a camera/camera info by other IDs than the cameraID e.g. like the serial number
| -rw-r--r-- | pymba/vimba.py | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/pymba/vimba.py b/pymba/vimba.py index 705838a..a1ffeaa 100644 --- a/pymba/vimba.py +++ b/pymba/vimba.py @@ -171,14 +171,19 @@ class Vimba(object): Gets camera info object of specified camera. :param cameraId: the ID of the camera object to get. + This might not only be a cameraId as returned by getCameraIds() + but also e.g. a serial number. Check the Vimba documentation for + other possible values. :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 + cameraInfo = structs.VimbaCameraInfo() + errorCode = VimbaDLL.cameraInfoQuery(cameraId.encode(), + cameraInfo, + sizeof(cameraInfo)) + if errorCode == 0: + return cameraInfo + # otherwise raise error raise VimbaException(-50) @@ -204,7 +209,10 @@ class Vimba(object): Gets camera object based on camera ID string. Will not recreate camera object if it already exists. - :param cameraId: the ID of the camera. + :param cameraId: the ID of the camera object to get. + This might not only be a cameraId as returned by getCameraIds() + but also e.g. a serial number. Check the Vimba documentation for + other possible values. :returns: VimbaCamera object -- the camera object specified. """ @@ -214,7 +222,20 @@ class Vimba(object): if cameraId not in self._cameras: self._cameras[cameraId] = VimbaCamera(cameraId) return self._cameras[cameraId] - raise VimbaException(-50) + else: + # the given string might not be a camera ID -> check for other IDs + cameraInfo = structs.VimbaCameraInfo() + errorCode = VimbaDLL.cameraInfoQuery(cameraId.encode(), + cameraInfo, + sizeof(cameraInfo)) + if errorCode != 0: + raise VimbaException(-50) # camera not found + + cameraIdString = cameraInfo.cameraIdString.decode() + if cameraIdString not in self._cameras: + self._cameras[cameraIdString] = VimbaCamera(cameraIdString) + return self._cameras[cameraIdString] + def getVersion(self): """ |
