From 9a514bc064cc9fba4b26e24eb13aab0ae056f31f Mon Sep 17 00:00:00 2001 From: edo-neo Date: Wed, 20 Aug 2025 13:14:54 +0200 Subject: [PATCH] dev --- src/components/hikrobot_sc/hikrobot_sc.py | 32 +++++++++++++++++++---- src/main.py | 2 +- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/components/hikrobot_sc/hikrobot_sc.py b/src/components/hikrobot_sc/hikrobot_sc.py index 522858f..fb8d786 100644 --- a/src/components/hikrobot_sc/hikrobot_sc.py +++ b/src/components/hikrobot_sc/hikrobot_sc.py @@ -8,7 +8,7 @@ import sys from PyQt5.QtCore import pyqtSignal, QMutex from PyQt5.QtWidgets import QMessageBox -from components.component import Component +from ..component import Component from .hikrobot_dll import * @@ -22,6 +22,29 @@ class HikrobotSmartCamera(Component): self.ok_memory = True self.ok_frames = [] self.ok_results =[] + self.solution_name = None + self.rotations = "0" # Default rotation value + + def update_solution_name(self, recipe_name): + """ + This method is called when the vision component's recipe changes. + It updates the solution_name attribute and triggers a reconfiguration. + + It also attempts to get the rotations value from the vision component if available. + """ + self.log.info(f"Updating solution name to: {recipe_name}") + self.solution_name = recipe_name + + # Try to get rotations from vision component if available + try: + if hasattr(self, "components") and "vision" in self.components and hasattr(self.components["vision"], "vision_config"): + if self.components["vision"].vision_config is not None and "rotations" in self.components["vision"].vision_config: + self.rotations = self.components["vision"].vision_config["rotations"] + self.log.info(f"Updated rotations to: {self.rotations}") + except Exception as e: + self.log.warning(f"Could not update rotations: {e}") + + self.reconfigure() def config_changed(self): self.connected = False @@ -85,9 +108,8 @@ class HikrobotSmartCamera(Component): return -2 # Set the camera recipe - if self.config.vision_config.get("solution_name",None) is not None: - solutionName = self.config.vision_config["solution_name"] - mv_lib.MV_VS_SetStringValue(pHandle, "SrcOperateSolutionName", solutionName) + if self.solution_name is not None: + mv_lib.MV_VS_SetStringValue(pHandle, "SrcOperateSolutionName", self.solution_name) mv_lib.MV_VS_SetCommandValue(pHandle, "CommandProjectLoad") time.sleep(5) @@ -105,7 +127,7 @@ class HikrobotSmartCamera(Component): return concat_frame = None concat_results = [] - rot = self.config.vision_config["rotations"].split(",") + rot = self.rotations.split(",") for cam_idx in range(self.num_cameras): cam = self.cam_list[cam_idx] self.log.info(f"GET FRAME CAMERA # {cam_idx}") diff --git a/src/main.py b/src/main.py index 21a662d..c2478ba 100644 --- a/src/main.py +++ b/src/main.py @@ -180,7 +180,7 @@ try: self.components["vision"].set_sources({"hikrobot_sc": self.components["hikrobot_sc"].out}) # Connect the recipe_changed_signal from Vision to HikrobotSmartCamera self.components["vision"].recipe_changed_signal.connect( - lambda recipe_name: self.components["hikrobot_sc"].config_changed() + self.components["hikrobot_sc"].update_solution_name ) # connect tecna to screwdriver