fix(allied_vision_camera): fix looping logic
CI for csaxs_bec / test (pull_request) Successful in 1m58s
CI for csaxs_bec / test (push) Successful in 1m57s

This commit was merged in pull request #157.
This commit is contained in:
2026-03-11 16:48:33 +01:00
parent 7b882653ad
commit 058dbf5e5b
@@ -73,7 +73,13 @@ class AlliedVisionCamera(PSIDeviceBase, DetectorBase):
)
self._poll_thread_kill_event = threading.Event()
self._poll_start_event = threading.Event()
if poll_rate > 10:
if poll_rate <= 0:
logger.warning(
f"Poll rate must be positive for Camera {self.name} and non-zero, setting to 1 Hz."
)
poll_rate = 1
self.stop_live_mode()
elif poll_rate > 10:
logger.warning(f"Poll rate too high for Camera {self.name}, setting to 10 Hz max.")
poll_rate = 10
self._poll_rate = poll_rate
@@ -84,6 +90,7 @@ class AlliedVisionCamera(PSIDeviceBase, DetectorBase):
self.preview.transpose = transpose
self._live_mode_lock = threading.RLock()
self.live_mode_enabled.subscribe(self._on_live_mode_enabled_changed, run=False)
self.cam.acquire.subscribe(self._on_live_mode_enabled_changed, run=False)
def start_live_mode(self) -> None:
"""Start live mode."""
@@ -120,8 +127,8 @@ class AlliedVisionCamera(PSIDeviceBase, DetectorBase):
def _poll_array_data(self):
"""Poll the array data for preview updates."""
while not self._poll_thread_kill_event.wait(1 / self._poll_rate):
while self._poll_start_event.wait():
while self._poll_start_event.wait():
while not self._poll_thread_kill_event.wait(1 / self._poll_rate):
try:
# First check if there is a new image
if self.image.unique_id.get() != self._unique_array_id:
@@ -148,7 +155,7 @@ class AlliedVisionCamera(PSIDeviceBase, DetectorBase):
def on_destroy(self):
"""Stop the polling thread on destruction."""
self._poll_thread_kill_event.set()
self._poll_start_event.set()
self._poll_thread_kill_event.set()
if self._poll_thread.is_alive():
self._poll_thread.join(timeout=2)