From c995d622fe29bc6080709cfe8e68075f0e3d8a54 Mon Sep 17 00:00:00 2001 From: adam-urbanczyk Date: Sat, 19 Oct 2019 11:11:00 +0200 Subject: [PATCH 1/3] Implemented VmbFeatureEnumIsAvailable check when reporting possible enum values --- pymba/feature.py | 17 +++++++++++++++-- pymba/vimba_c.py | 8 +++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/pymba/feature.py b/pymba/feature.py index 9f04666..0fe9824 100644 --- a/pymba/feature.py +++ b/pymba/feature.py @@ -241,5 +241,18 @@ def _range_query_enum(self) -> List[str]: byref(num_found)) if error: raise VimbaException(error) - - return list(enum_name.decode() for enum_name in enum_names) + + # check which enum names are actually allowed for the given camera + rv = [] + found = c_bool(False) + for enum_name in enum_names: + error = vimba_c.vmb_feature_enum_is_available(self._handle, + self._name, + enum_name, + byref(found)) + if error: + raise VimbaException(error) + elif found: + rv.append(enum_name.decode()) + + return rv diff --git a/pymba/vimba_c.py b/pymba/vimba_c.py index 7f84421..15bbb30 100644 --- a/pymba/vimba_c.py +++ b/pymba/vimba_c.py @@ -325,7 +325,13 @@ class VmbFrame(Structure): c_uint32, POINTER(c_uint32)) -# todo VmbFeatureEnumIsAvailable +vmb_feature_enum_is_available = _vimba_lib.VmbFeatureEnumIsAvailable +vmb_feature_enum_is_available.restype = c_int32 +vmb_feature_enum_is_available.argtypes = (c_void_p, + c_char_p, + c_char_p, + POINTER(c_bool)) + # todo VmbFeatureEnumAsInt # todo VmbFeatureEnumAsString # todo VmbFeatureEnumEntryGet From fc0986726fe43d99c4ec800d54b94cc3cbd07d3b Mon Sep 17 00:00:00 2001 From: adam-urbanczyk Date: Sat, 19 Oct 2019 17:52:21 +0200 Subject: [PATCH 2/3] Wrapped more functions related to features --- pymba/vimba_c.py | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/pymba/vimba_c.py b/pymba/vimba_c.py index 15bbb30..b1a19a3 100644 --- a/pymba/vimba_c.py +++ b/pymba/vimba_c.py @@ -259,9 +259,31 @@ class VmbFrame(Structure): POINTER(VmbFeatureInfo), c_uint32) -# todo VmbFeatureListAffected -# todo VmbFeatureListSelected -# todo VmbFeatureAccessQuery + +vmb_features_list_affected = _vimba_lib.VmbFeatureListAffected +vmb_features_list_affected.restype = c_int32 +vmb_features_list_affected.argtypes = (c_void_p, + c_char_p, + POINTER(VmbFeatureInfo), + c_uint32, + POINTER(c_uint32), + c_uint32) + +vmb_features_list_selected = _vimba_lib.VmbFeatureListSelected +vmb_features_list_selected.restype = c_int32 +vmb_features_list_selected.argtypes = (c_void_p, + c_char_p, + POINTER(VmbFeatureInfo), + c_uint32, + POINTER(c_uint32), + c_uint32) + +vmb_features_access_query = _vimba_lib.VmbFeatureAccessQuery +vmb_features_access_query.restype = c_int32 +vmb_features_access_query.argtypes = (c_void_p, + c_char_p, + POINTER(c_bool), + POINTER(c_bool)) vmb_feature_int_get = _vimba_lib.VmbFeatureIntGet vmb_feature_int_get.restype = c_int32 @@ -282,7 +304,11 @@ class VmbFrame(Structure): POINTER(c_int64), POINTER(c_int64)) -# todo VmbFeatureIntIncrementQuery +vmb_feature_int_increment_query = _vimba_lib.VmbFeatureIntIncrementQuery +vmb_feature_int_increment_query.restype = c_int32 +vmb_feature_int_increment_query.argtypes = (c_void_p, + c_char_p, + POINTER(c_int64)) vmb_feature_float_get = _vimba_lib.VmbFeatureFloatGet vmb_feature_float_get.restype = c_int32 @@ -303,7 +329,11 @@ class VmbFrame(Structure): POINTER(c_double), POINTER(c_double)) -# todo VmbFeatureFloatIncrementQuery +vmb_feature_float_increment_query = _vimba_lib.VmbFeatureFloatIncrementQuery +vmb_feature_float_increment_query.restype = c_int32 +vmb_feature_float_increment_query.argtypes = (c_void_p, + c_char_p, + POINTER(c_double)) vmb_feature_enum_get = _vimba_lib.VmbFeatureEnumGet vmb_feature_enum_get.restype = c_int32 From 5ced680c56ac0f6a9ff697017187e6acfe06653e Mon Sep 17 00:00:00 2001 From: adam-urbanczyk Date: Sun, 20 Oct 2019 11:35:19 +0200 Subject: [PATCH 3/3] Exposed more vimba functions in the feature class - increment - affected - selected - access --- pymba/feature.py | 118 +++++++++++++++++++++++++++++++++++++++++++++-- pymba/vimba_c.py | 19 ++++---- 2 files changed, 125 insertions(+), 12 deletions(-) diff --git a/pymba/feature.py b/pymba/feature.py index 0fe9824..36f9ee6 100644 --- a/pymba/feature.py +++ b/pymba/feature.py @@ -47,7 +47,27 @@ def range(self) -> Union[None, Tuple[int, int], Tuple[float, float], Tuple[str, _FEATURE_DATA_ENUM): return self._access_func('range', self.info.featureDataType)() return None - + + @property + def increment(self) -> Union[None, int, float]: + # only some types actually have an increment + if self.info.featureDataType in (_FEATURE_DATA_INT, + _FEATURE_DATA_FLOAT): + return self._access_func('increment', self.info.featureDataType)() + return None + + @property + def affected(self) -> List[str]: + return self._affected_query() + + @property + def selected(self) -> List[str]: + return self._selected_query() + + @property + def access(self) -> Tuple[bool,bool]: + return self._access_query() + def __init__(self, name, handle): self._name = name.encode() self._handle = handle @@ -64,10 +84,12 @@ def _access_func(self, func_type: str, data_type: int) -> Callable: _FEATURE_DATA_UNKNOWN: (), _FEATURE_DATA_INT: (self._get_int, self._set_int, - self._range_query_int), + self._range_query_int, + self._increment_query_int), _FEATURE_DATA_FLOAT: (self._get_float, self._set_float, - self._range_query_float), + self._range_query_float, + self._increment_query_float), _FEATURE_DATA_ENUM: (self._get_enum, self._set_enum, self._range_query_enum), @@ -84,6 +106,7 @@ def _access_func(self, func_type: str, data_type: int) -> Callable: 'get': 0, 'set': 1, 'range': 2, + 'increment' : 3 } # doesn't make sense to get / set a command data type @@ -256,3 +279,92 @@ def _range_query_enum(self) -> List[str]: rv.append(enum_name.decode()) return rv + + def _increment_query_int(self) -> int: + increment = c_int64() + error = vimba_c.vmb_feature_int_increment_query(self._handle, + self._name, + byref(increment)) + if error: + raise VimbaException(error) + + return int(increment.value) + + def _increment_query_float(self) -> Tuple[bool,float]: + increment = c_double(-1) + has_increment = c_bool(True) + error = vimba_c.vmb_feature_float_increment_query(self._handle, + self._name, + byref(has_increment), + byref(increment)) + if error: + raise VimbaException(error) + + return has_increment.value,float(increment.value) + + def _affected_query(self) -> List[str]: + # call once to get number of available features + vmb_feature_info = vimba_c.VmbFeatureInfo() + num_found = c_uint32(-1) + error = vimba_c.vmb_feature_list_affected(self._handle, + self._name, + None, + 0, + byref(num_found), + sizeof(vmb_feature_info)) + if error: + raise VimbaException(error) + + # call again to get the features + num_features = num_found.value + vmb_feature_infos = (vimba_c.VmbFeatureInfo * num_features)() + error = vimba_c.vmb_feature_list_affected(self._handle, + self._name, + vmb_feature_infos, + num_features, + byref(num_found), + sizeof(vmb_feature_info)) + if error: + raise VimbaException(error) + + return list(vmb_feature_info.name.decode() for vmb_feature_info in vmb_feature_infos) + + def _selected_query(self) -> List[str]: + # call once to get number of available features + vmb_feature_info = vimba_c.VmbFeatureInfo() + num_found = c_uint32(-1) + error = vimba_c.vmb_feature_list_selected(self._handle, + self._name, + None, + 0, + byref(num_found), + sizeof(vmb_feature_info)) + if error: + raise VimbaException(error) + + # call again to get the features + num_features = num_found.value + vmb_feature_infos = (vimba_c.VmbFeatureInfo * num_features)() + error = vimba_c.vmb_feature_list_selected(self._handle, + self._name, + vmb_feature_infos, + num_features, + byref(num_found), + sizeof(vmb_feature_info)) + if error: + raise VimbaException(error) + + return list(vmb_feature_info.name.decode() for vmb_feature_info in vmb_feature_infos) + + + def _access_query(self) -> Tuple[bool,bool]: + readable = c_bool() + writable = c_bool() + error = vimba_c.vmb_feature_access_query(self._handle, + self._name, + byref(readable), + byref(writable)) + if error: + raise VimbaException(error) + + return readable.value,writable.value \ No newline at end of file diff --git a/pymba/vimba_c.py b/pymba/vimba_c.py index b1a19a3..4ac9292 100644 --- a/pymba/vimba_c.py +++ b/pymba/vimba_c.py @@ -260,27 +260,27 @@ class VmbFrame(Structure): c_uint32) -vmb_features_list_affected = _vimba_lib.VmbFeatureListAffected -vmb_features_list_affected.restype = c_int32 -vmb_features_list_affected.argtypes = (c_void_p, +vmb_feature_list_affected = _vimba_lib.VmbFeatureListAffected +vmb_feature_list_affected.restype = c_int32 +vmb_feature_list_affected.argtypes = (c_void_p, c_char_p, POINTER(VmbFeatureInfo), c_uint32, POINTER(c_uint32), c_uint32) -vmb_features_list_selected = _vimba_lib.VmbFeatureListSelected -vmb_features_list_selected.restype = c_int32 -vmb_features_list_selected.argtypes = (c_void_p, +vmb_feature_list_selected = _vimba_lib.VmbFeatureListSelected +vmb_feature_list_selected.restype = c_int32 +vmb_feature_list_selected.argtypes = (c_void_p, c_char_p, POINTER(VmbFeatureInfo), c_uint32, POINTER(c_uint32), c_uint32) -vmb_features_access_query = _vimba_lib.VmbFeatureAccessQuery -vmb_features_access_query.restype = c_int32 -vmb_features_access_query.argtypes = (c_void_p, +vmb_feature_access_query = _vimba_lib.VmbFeatureAccessQuery +vmb_feature_access_query.restype = c_int32 +vmb_feature_access_query.argtypes = (c_void_p, c_char_p, POINTER(c_bool), POINTER(c_bool)) @@ -333,6 +333,7 @@ class VmbFrame(Structure): vmb_feature_float_increment_query.restype = c_int32 vmb_feature_float_increment_query.argtypes = (c_void_p, c_char_p, + POINTER(c_bool), POINTER(c_double)) vmb_feature_enum_get = _vimba_lib.VmbFeatureEnumGet