diff options
| author | morefigs <morefigs@gmail.com> | 2019-02-21 12:10:55 +1100 |
|---|---|---|
| committer | morefigs <morefigs@gmail.com> | 2019-02-21 12:10:55 +1100 |
| commit | 712b3789a1d961661e4076846a2d33a2e830a41e (patch) | |
| tree | 2b1e7c309b7ed6b789fa0a5176a87f9ed82ee9a4 | |
| parent | edbbf80d3e8b981cc71cd61f85fd14d0effd3e88 (diff) | |
| download | pymba-712b3789a1d961661e4076846a2d33a2e830a41e.tar.gz pymba-712b3789a1d961661e4076846a2d33a2e830a41e.zip | |
calling an object command feature type as an attribute returns a callable
| -rw-r--r-- | CHANGELOG.md | 3 | ||||
| -rw-r--r-- | examples/camera/set_feature_value.py (renamed from examples/camera/write_feature_value.py) | 0 | ||||
| -rw-r--r-- | examples/interface/set_feature_value.py (renamed from examples/interface/write_feature_value.py) | 0 | ||||
| -rw-r--r-- | pymba/camera.py | 12 | ||||
| -rw-r--r-- | pymba/vimba.py | 8 | ||||
| -rw-r--r-- | pymba/vimba_object.py | 14 |
6 files changed, 28 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index ad0f512..3a9f1f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ ## [0.3.1] - 2019/02/21 ### Added - Auto adjust packet size upon opening camera. +- Command type features can now be called directly as an object attribute. +### Changed +- Increased default frame buffer size from 3 to 10. ## [0.3] - 2019/02/11 ### Added diff --git a/examples/camera/write_feature_value.py b/examples/camera/set_feature_value.py index 77f8ce5..77f8ce5 100644 --- a/examples/camera/write_feature_value.py +++ b/examples/camera/set_feature_value.py diff --git a/examples/interface/write_feature_value.py b/examples/interface/set_feature_value.py index 0c71da2..0c71da2 100644 --- a/examples/interface/write_feature_value.py +++ b/examples/interface/set_feature_value.py diff --git a/pymba/camera.py b/pymba/camera.py index 4cda105..5a8b75b 100644 --- a/pymba/camera.py +++ b/pymba/camera.py @@ -133,7 +133,7 @@ class Camera(VimbaObject): # may experience issues with camera comms if not called if adjust_packet_size: - self.run_feature_command('GVSPAdjustPacketSize') + self.GVSPAdjustPacketSize() def close(self): """ @@ -181,7 +181,7 @@ class Camera(VimbaObject): """ return Frame(self) - def arm(self, mode: str, callback: Optional[Callable] = None, frame_buffer_size: Optional[int] = 3) -> None: + def arm(self, mode: str, callback: Optional[Callable] = None, frame_buffer_size: Optional[int] = 10) -> None: """ Arm the camera by starting the capture engine and creating frames. :param mode: Either 'SingleFrame' to acquire a single frame or 'Continuous' for streaming frames. @@ -229,9 +229,9 @@ class Camera(VimbaObject): # capture a single frame self._single_frame.queue_for_capture() - self.run_feature_command('AcquisitionStart') + self.AcquisitionStart() self._single_frame.wait_for_capture() - self.run_feature_command('AcquisitionStop') + self.AcquisitionStop() return self._single_frame @@ -259,7 +259,7 @@ class Camera(VimbaObject): raise VimbaException(VimbaException.ERR_INVALID_CAMERA_MODE) # safe to call multiple times - self.run_feature_command('AcquisitionStart') + self.AcquisitionStart() self._is_acquiring = True def _streaming_callback(self, frame: Frame) -> None: @@ -279,7 +279,7 @@ class Camera(VimbaObject): # implies both is armed and in continuous mode if self._is_acquiring: self._is_acquiring = False - self.run_feature_command('AcquisitionStop') + self.AcquisitionStop() def disarm(self) -> None: """ diff --git a/pymba/vimba.py b/pymba/vimba.py index 66329ab..1079b12 100644 --- a/pymba/vimba.py +++ b/pymba/vimba.py @@ -59,7 +59,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') + self.system().GeVDiscoveryAllOnce() @staticmethod def shutdown(): @@ -89,8 +89,11 @@ class Vimba: if interface_id in self._interfaces: return self._interfaces[interface_id] + + # cache interface instances interface = Interface(interface_id) self._interfaces[interface_id] = interface + return interface @staticmethod @@ -109,6 +112,9 @@ class Vimba: if camera_id in self._cameras: return self._cameras[camera_id] + + # cache camera instance camera = Camera(camera_id) self._cameras[camera_id] = camera + return camera diff --git a/pymba/vimba_object.py b/pymba/vimba_object.py index 174fe9a..fbc6b05 100644 --- a/pymba/vimba_object.py +++ b/pymba/vimba_object.py @@ -2,7 +2,7 @@ from ctypes import byref, sizeof, c_void_p, c_uint32, c_uint64, c_bool from typing import List, Optional from .vimba_exception import VimbaException -from .feature import Feature +from .feature import Feature, _FEATURE_DATA_COMMAND from . import vimba_c @@ -25,7 +25,14 @@ class VimbaObject: def __getattr__(self, item: str): # allow direct access to feature values as an attribute if item in self.feature_names(): - return self.feature(item).value + feature = self.feature(item) + + # command feature types are a special case, return a callable + if feature.info.featureDataType == _FEATURE_DATA_COMMAND: + return lambda: self.run_feature_command(item) + + # otherwise attempt to get their value + return feature.value raise AttributeError(f'{self.__class__.__name__} object has no attribute {item}') @@ -94,8 +101,11 @@ class VimbaObject: """ if feature_name in self._features: return self._features[feature_name] + + # cache feature feature = Feature(feature_name, self._handle) self._features[feature_name] = feature + return feature def run_feature_command(self, feature_name: str) -> None: |
