diff options
| author | morefigs <morefigs@gmail.com> | 2019-02-09 15:02:34 +1100 |
|---|---|---|
| committer | morefigs <morefigs@gmail.com> | 2019-02-09 15:02:34 +1100 |
| commit | e9a094cadc47d8b4ba3ffbc80e64f17decdbc32b (patch) | |
| tree | 64cc668b5792f701758f72bba91aeb890c6617be | |
| parent | 95ce9c6e730b795d6d1bf83bb2fa56602fc985f9 (diff) | |
| parent | 0adf83d72c081f02cb21510035c7dda8ab07f796 (diff) | |
| download | pymba-e9a094cadc47d8b4ba3ffbc80e64f17decdbc32b.tar.gz pymba-e9a094cadc47d8b4ba3ffbc80e64f17decdbc32b.zip | |
Merge branch 'master' of github.com:morefigs/pymba
| -rw-r--r-- | examples/camera/opencv_capture_image.py | 4 | ||||
| -rw-r--r-- | examples/camera/opencv_capture_image_with_callback.py | 2 | ||||
| -rw-r--r-- | pymba/camera.py | 2 | ||||
| -rw-r--r-- | pymba/feature.py | 22 | ||||
| -rw-r--r-- | pymba/frame.py | 4 | ||||
| -rw-r--r-- | pymba/vimba.py | 1 | ||||
| -rw-r--r-- | pymba/vimba_c.py | 28 | ||||
| -rw-r--r-- | pymba/vimba_exception.py | 11 |
8 files changed, 47 insertions, 27 deletions
diff --git a/examples/camera/opencv_capture_image.py b/examples/camera/opencv_capture_image.py index e8bf3d5..cf5305f 100644 --- a/examples/camera/opencv_capture_image.py +++ b/examples/camera/opencv_capture_image.py @@ -10,13 +10,13 @@ if __name__ == '__main__': # setup camera and frame and capture a single image camera.AcquisitionMode = 'SingleFrame' - frame = camera.create_frame() + frame = camera.new_frame() frame.announce() camera.start_capture() frame.queue_for_capture() camera.run_feature_command('AcquisitionStart') - camera.run_feature_command('AcquisitionStop') frame.wait_for_capture() + camera.run_feature_command('AcquisitionStop') # get the image data as a numpy array image = frame.image_numpy_array() diff --git a/examples/camera/opencv_capture_image_with_callback.py b/examples/camera/opencv_capture_image_with_callback.py index 4d5fa28..b7bc7ff 100644 --- a/examples/camera/opencv_capture_image_with_callback.py +++ b/examples/camera/opencv_capture_image_with_callback.py @@ -24,7 +24,7 @@ if __name__ == '__main__': # setup camera and frame and capture a single image camera.AcquisitionMode = 'SingleFrame' - frame = camera.create_frame() + frame = camera.new_frame() frame.announce() camera.start_capture() frame.queue_for_capture(on_callback) diff --git a/pymba/camera.py b/pymba/camera.py index 3bdc16b..23ecd13 100644 --- a/pymba/camera.py +++ b/pymba/camera.py @@ -154,7 +154,7 @@ class Camera(VimbaObject): if error: raise VimbaException(error) - def create_frame(self) -> Frame: + def new_frame(self) -> Frame: """ Creates and returns a new frame object. Multiple frames per camera can therefore be returned. """ diff --git a/pymba/feature.py b/pymba/feature.py index 7ac403d..571f2b5 100644 --- a/pymba/feature.py +++ b/pymba/feature.py @@ -1,5 +1,5 @@ from ctypes import byref, sizeof, c_uint32, c_double, c_char_p, c_bool, c_int64, create_string_buffer -from typing import Tuple, List, Callable +from typing import Union, Tuple, List, Callable from .vimba_exception import VimbaException from . import vimba_c @@ -24,7 +24,7 @@ class Feature: """ @property - def name(self): + def name(self) -> str: return self._name.decode() @property @@ -32,16 +32,19 @@ class Feature: return self._feature_info() @property - def value(self): + def value(self) -> Union[str, int, float, bool]: return self._access_func('get', self.info.featureDataType)() @value.setter - def value(self, val): - self._access_func('set', self.info.featureDataType)(val) + def value(self, value: Union[str, int, float, bool]) -> None: + self._access_func('set', self.info.featureDataType)(value) @property - def range(self): - return self._access_func('range', self.info.featureDataType)() + def range(self) -> Union[None, Tuple[int, int], Tuple[float, float], Tuple[str, str]]: + # only some types actually have a range + if self.info.featureDataType in (_FEATURE_DATA_INT, _FEATURE_DATA_FLOAT, _FEATURE_DATA_ENUM): + return self._access_func('range', self.info.featureDataType)() + return None def __init__(self, name, handle): self._name = name.encode() @@ -80,6 +83,11 @@ class Feature: 'range': 2, } + # doesn't make sense to get / set a command data type + if data_type == _FEATURE_DATA_COMMAND: + raise VimbaException(VimbaException.ERR_COMMAND_MUST_BE_CALLED) + + # some data types aren't implemented try: return access_funcs[data_type][access_indices[func_type]] except IndexError: diff --git a/pymba/frame.py b/pymba/frame.py index 5f9bcda..ef3ec53 100644 --- a/pymba/frame.py +++ b/pymba/frame.py @@ -38,6 +38,10 @@ class Frame: self._frame_callback = None self._frame_callback_wrapper_c = None + @property + def data(self) -> vimba_c.VmbFrame: + return self._vmb_frame + def announce(self) -> None: """ Announce frames to the API that may be queued for frame capturing later. Should be called after the frame is diff --git a/pymba/vimba.py b/pymba/vimba.py index 02c29c7..66329ab 100644 --- a/pymba/vimba.py +++ b/pymba/vimba.py @@ -58,6 +58,7 @@ class Vimba: # automatically check for the presence of a GigE transport layer if self.system().GeVTLIsPresent: + self.system().GeVDiscoveryAllDuration = 250 self.system().run_feature_command('GeVDiscoveryAllOnce') @staticmethod diff --git a/pymba/vimba_c.py b/pymba/vimba_c.py index 034df6e..30b9d77 100644 --- a/pymba/vimba_c.py +++ b/pymba/vimba_c.py @@ -36,32 +36,36 @@ if sys_plat == "win32": else: dll_loader = cdll + + def find_so(platform, genicam_path): + vimbaC_found = False + for tlPath in [p for p in os.environ.get(genicam_path).split(":") if p]: + vimba_dir = "/".join(tlPath.split("/")[1:-3]) + vimbaC_path = "/" + vimba_dir + "/VimbaC/DynamicLib/" + platform + "/libVimbaC.so" + if os.path.isfile(vimbaC_path): + vimbaC_found = True + break + if not vimbaC_found: + raise OSError('No libVimbaC.so found') + return vimbaC_path if 'x86_64' in os.uname()[4]: 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" - tlPath = [p for p in os.environ.get("GENICAM_GENTL64_PATH").split(":") if p][0] - vimba_dir = "/".join(tlPath.split("/")[1:-3]) - vimbaC_path = "/" + vimba_dir + "/VimbaC/DynamicLib/x86_64bit/libVimbaC.so" + vimbaC_path = find_so('x86_64bit', "GENICAM_GENTL64_PATH") elif 'x86_32' in os.uname()[4]: print("Warning: x86_32 reached!") assert os.environ.get( "GENICAM_GENTL32_PATH"), "you need your GENICAM_GENTL32_PATH environment set. Make sure you have Vimba installed, and you have loaded the /etc/profile.d/ scripts" - tlPath = [p for p in os.environ.get("GENICAM_GENTL32_PATH").split(":") if p][0] - vimba_dir = "/".join(tlPath.split("/")[1:-3]) - vimbaC_path = "/" + vimba_dir + "/VimbaC/DynamicLib/x86_32bit/libVimbaC.so" + vimbaC_path = find_so('x86_32bit', 'GENICAM_GENTL32_PATH') elif 'arm' in os.uname()[4]: assert os.environ.get( "GENICAM_GENTL32_PATH"), "you need your GENICAM_GENTL32_PATH environment set. Make sure you have Vimba installed, and you have loaded the /etc/profile.d/ scripts" - tlPath = [p for p in os.environ.get("GENICAM_GENTL32_PATH").split(":") if p][0] - vimba_dir = "/".join(tlPath.split("/")[1:-3]) - vimbaC_path = "/" + vimba_dir + "/VimbaC/DynamicLib/arm_32bit/libVimbaC.so" + vimbaC_path = find_so('arm_32bit', 'GENICAM_GENTL32_PATH') elif 'aarch64' in os.uname()[4]: 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" - tlPath = [p for p in os.environ.get("GENICAM_GENTL64_PATH").split(":") if p][0] - vimba_dir = "/".join(tlPath.split("/")[1:-3]) - vimbaC_path = "/" + vimba_dir + "/VimbaC/DynamicLib/arm_64bit/libVimbaC.so" + vimbaC_path = find_so('arm_64bit', "GENICAM_GENTL64_PATH") else: raise ValueError("Pymba currently doesn't support %s" % os.uname()[4]) diff --git a/pymba/vimba_exception.py b/pymba/vimba_exception.py index 22f03c2..992e299 100644 --- a/pymba/vimba_exception.py +++ b/pymba/vimba_exception.py @@ -24,11 +24,13 @@ class VimbaException(Exception): ERR_FEATURE_NOT_SUPPORTED, ERR_PARTIAL_REGISTER_ACCESS, - # -50 to -56 + # -50 to -53 + ERR_UNDEFINED_ERROR_CODE, ERR_FRAME_BUFFER_MEMORY, ERR_NOT_IMPLEMENTED_IN_PYMBA, - ERR_UNDEFINED_ERROR_CODE, - ) = tuple(range(0, -20, -1)) + tuple(range(-50, -53, -1)) + ERR_COMMAND_MUST_BE_CALLED, + ) = tuple(range(0, -20, -1)) + \ + tuple(range(-50, -54, -1)) ERRORS = { # Vimba C API specific errors @@ -54,9 +56,10 @@ class VimbaException(Exception): ERR_PARTIAL_REGISTER_ACCESS: 'A multiple registers read or write was partially completed.', # Custom errors + ERR_UNDEFINED_ERROR_CODE: 'Undefined error code', ERR_FRAME_BUFFER_MEMORY: 'Not enough memory to assign frame buffer.', ERR_NOT_IMPLEMENTED_IN_PYMBA: 'This function is not yet implemented in Pymba', - ERR_UNDEFINED_ERROR_CODE: 'Undefined error code', + ERR_COMMAND_MUST_BE_CALLED: 'Cannot get or set the value of a command feature type, call the command instead.' } @property |
