From 03db39bb41b2fa3b430834c50a53e3dddd6a17a9 Mon Sep 17 00:00:00 2001 From: edo-neo Date: Thu, 21 Aug 2025 10:31:27 +0200 Subject: [PATCH] dev --- src/components/hikrobot_sc/hikrobot_sc.py | 27 +++++++++-------------- src/ui/test_vision/test_vision.py | 25 ++++++++++++++++++--- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/components/hikrobot_sc/hikrobot_sc.py b/src/components/hikrobot_sc/hikrobot_sc.py index 62d7acd..b9f9107 100644 --- a/src/components/hikrobot_sc/hikrobot_sc.py +++ b/src/components/hikrobot_sc/hikrobot_sc.py @@ -349,29 +349,22 @@ class HikrobotSmartCamera(Component): except Exception as e: self.log.warning(f"Could not update rotations: {e}") - # Use the switch_scheme method to change the camera scheme - if self.connected: + # Store the solution name for later use, but don't switch schemes yet + # The actual scheme switching will be handled by the Test_Vision component + # when it calls start() and checks if a scheme switch is needed + if not self.connected: + self.log.info("Camera not connected, will switch scheme after connection") + self.reconfigure() # This will connect and then switch scheme + else: # Stop any ongoing operation if self.current_operation: self.log.warning(f"Stopping ongoing operation: {self.current_operation}") self.progress_timer.stop() self.current_operation = None - # Try to switch scheme - success = self.switch_scheme(recipe_name) - if not success: - self.log.error(f"Failed to switch scheme to {recipe_name}, trying to reconnect...") - # If switching failed, try to reconnect and then switch again - self.connected = False - self.config_changed() # This will reconnect - if self.connected: - self.log.info(f"Reconnected, trying to switch scheme again...") - self.switch_scheme(recipe_name) - else: - self.log.error("Failed to reconnect to camera") - else: - self.log.info("Camera not connected, will switch scheme after connection") - self.reconfigure() # This will connect and then switch scheme + # Start the scheme switching process (asynchronously) + # The Test_Vision component will wait for this to complete + self.switch_scheme(recipe_name) def config_changed(self): self.connected = False diff --git a/src/ui/test_vision/test_vision.py b/src/ui/test_vision/test_vision.py index 2e14879..9a4cd01 100644 --- a/src/ui/test_vision/test_vision.py +++ b/src/ui/test_vision/test_vision.py @@ -5,7 +5,6 @@ from PyQt5.QtCore import pyqtSignal, QTimer from PyQt5.QtGui import QColor, QImage, QPalette, QPixmap from PyQt5.QtWidgets import QHeaderView, QProgressBar, QTableWidgetItem, QDialog, QVBoxLayout, QLabel, QProgressBar -# Import relative to the project structure from src.lib.helpers.blocking_dialog import BlockingDialog from src.ui.helpers import calc_foreground_color from src.ui.test_test import Test_Test @@ -95,16 +94,34 @@ class Test_Vision(Test_Test): dialog = BlockingDialog(self.ui,wait_time=wait_time, message=f"COLLEGARE CAVO ETHERNET E ATTENDERE {wait_time} SECONDI PER IL CORRETTO AVVIO DELLE TELECAMERE") dialog.exec_() - # Wait for scheme switching to complete before proceeding - if self.components[cam_type].current_operation == "switch_scheme": + # Always check if we need to wait for scheme switching to complete + # This ensures we don't proceed until the camera is ready with the correct scheme + self.log.info("Checking if camera scheme needs to be switched...") + + # Get the current scheme name from the camera + current_scheme = self.components[cam_type].get_current_scheme() + target_scheme = self.step.spec.get("recipe", "").replace(".ini", "") + + self.log.info(f"Current camera scheme: {current_scheme}, Target scheme: {target_scheme}") + + # If schemes don't match or a scheme switch is already in progress, wait for it + if current_scheme != target_scheme or self.components[cam_type].current_operation == "switch_scheme": + self.log.info(f"Waiting for camera to switch to scheme: {target_scheme}") + # Create and show the progress dialog progress_dialog = SchemeProgressDialog(self) + progress_dialog.label.setText(f"Switching camera to scheme: {target_scheme}\nPlease wait...") # Connect to the progress signal progress_connection = self.components[cam_type].progress_signal.connect( progress_dialog.update_progress ) + # If a scheme switch is not already in progress, start one + if self.components[cam_type].current_operation != "switch_scheme": + self.log.info(f"Initiating scheme switch to: {target_scheme}") + self.components[cam_type].switch_scheme(target_scheme) + # Show the dialog and wait for it to complete result = progress_dialog.exec_() @@ -114,6 +131,8 @@ class Test_Vision(Test_Test): if result == QDialog.Rejected: # Scheme switching failed, but we'll continue anyway self.log.warning("Scheme switching failed, continuing with cycle") + else: + self.log.info(f"Camera already using correct scheme: {current_scheme}") self.components[cam_type].resume() else: