This commit is contained in:
edo 2025-08-21 14:38:04 +02:00
parent 9ab537f9fb
commit 7321aecd85
4 changed files with 7 additions and 52 deletions

View File

@ -16,7 +16,7 @@ vision: present
screwdriver: absent
digital_io: present
barcode_recipe_selection: present
fixture_id: present
fixture_id: absent
discard_box: absent
# enforce_piece_removal: yes

View File

@ -319,7 +319,7 @@ class HikrobotSmartCamera(Component):
self._debug_camera_state(handle)
try:
self.log.info(f"Starting scheme switch to: {solution_name} (Attempt {retry_count+1}/{max_retries+1})")
# Check if the solution name is valid (not empty)
if not solution_name or solution_name.strip() == "":
@ -337,13 +337,7 @@ class HikrobotSmartCamera(Component):
# Try to get more information about the error
self._debug_camera_state(handle)
# Check if this is the generic error and we can retry
if error_code == 0x80030100 and retry_count < max_retries: # MV_VS_E_GC_GENERIC
self.log.warning(f"Detected generic error (0x80030100). Waiting 2 seconds before retry {retry_count+1}/{max_retries}")
time.sleep(2) # Wait before retrying
return self.switch_scheme(solution_name, retry_count + 1, max_retries)
return False
else:
self.log.info(f"Successfully set solution name: {solution_name}")
@ -357,11 +351,7 @@ class HikrobotSmartCamera(Component):
# Try to get more information about the error
self._debug_camera_state(handle)
# Check if this is the generic error and we can retry
if error_code == 0x80030100 and retry_count < max_retries: # MV_VS_E_GC_GENERIC
self.log.warning(f"Detected generic error (0x80030100). Waiting 2 seconds before retry {retry_count+1}/{max_retries}")
time.sleep(2) # Wait before retrying
return self.switch_scheme(solution_name, retry_count + 1, max_retries)
return False
else:
@ -382,11 +372,7 @@ class HikrobotSmartCamera(Component):
import traceback
self.log.error(f"Exception traceback: {traceback.format_exc()}")
# Retry on exception if we haven't exceeded max retries
if retry_count < max_retries:
self.log.warning(f"Exception occurred. Waiting 2 seconds before retry {retry_count+1}/{max_retries}")
time.sleep(2) # Wait before retrying
return self.switch_scheme(solution_name, retry_count + 1, max_retries)
return False
@ -604,11 +590,7 @@ class HikrobotSmartCamera(Component):
self.log.error(f"CAM{cam_idx} Start run failed! [{nRet & 0xFFFFFFFF:#x}]")
self.connected = True
# Now that the camera is connected, switch to the solution if one is set
if self.solution_name is not None:
self.log.info(f"Switching to solution: {self.solution_name}")
self.switch_scheme(self.solution_name)
@Component.reconfig_on_error
def _get(self):
@ -885,31 +867,4 @@ class HikrobotSmartCamera(Component):
self.log.warning(f"Scheme switch verification failed. Expected: {solution_name}, Got: {new_scheme}")
return False
def test_scheme_switch(self, solution_name=None):
"""
Test method to manually trigger a scheme switch.
This can be used for debugging or testing the scheme switching functionality.
Args:
solution_name: The name of the solution to switch to. If None, uses the current solution_name.
Returns:
bool: True if successful, False otherwise
"""
if solution_name is None:
if self.solution_name is None:
self.log.error("No solution name provided and no current solution name set")
return False
solution_name = self.solution_name
self.log.info(f"Testing scheme switch to: {solution_name}")
if not self.connected:
self.log.info("Camera not connected, connecting first...")
self.config_changed()
if not self.connected:
self.log.error("Failed to connect to camera")
return False
# Use the synchronous scheme switching method
return self.switch_scheme_sync(solution_name)