dev rev
This commit is contained in:
parent
7989f6c166
commit
9ab537f9fb
|
|
@ -238,99 +238,6 @@ class HikrobotSmartCamera(Component):
|
|||
|
||||
except Exception as e:
|
||||
self.log.error(f"Error getting debug camera state: {e}")
|
||||
|
||||
def is_camera_busy(self, handle=None):
|
||||
"""
|
||||
Check if the camera is currently busy.
|
||||
|
||||
This method checks the camera's device status and acquisition status to determine
|
||||
if it's currently busy with operations that would prevent scheme switching.
|
||||
|
||||
Args:
|
||||
handle: Camera handle. If None, uses the first camera handle.
|
||||
|
||||
Returns:
|
||||
bool: True if the camera is busy, False otherwise
|
||||
"""
|
||||
# Check if camera is connected
|
||||
if not self.connected:
|
||||
self.log.warning("Cannot check if camera is busy: Camera not connected")
|
||||
return True # Assume busy if not connected
|
||||
|
||||
# Get camera handle if not provided
|
||||
if handle is None:
|
||||
if len(self.cam_list) == 0:
|
||||
self.log.warning("Cannot check if camera is busy: No camera handles available")
|
||||
return True # Assume busy if no handles
|
||||
|
||||
handle = self.cam_list[0]["handle"]
|
||||
|
||||
# Check if an operation is already in progress
|
||||
if self.current_operation is not None:
|
||||
self.log.info(f"Camera is busy with operation: {self.current_operation}")
|
||||
return True
|
||||
|
||||
try:
|
||||
self.log.info("Checking if camera is busy...")
|
||||
|
||||
# Try to get the device status
|
||||
device_status = c_uint()
|
||||
nRet = mv_lib.MV_VS_GetEnumValue(handle, b"DeviceStatus", byref(device_status))
|
||||
|
||||
# If we get the 0x80030100 error, the camera is busy
|
||||
if nRet != MV_VS_OK:
|
||||
error_code = nRet & 0xFFFFFFFF
|
||||
if error_code == 0x80030100: # MV_VS_E_GC_GENERIC
|
||||
self.log.warning("Camera is busy: Detected MV_VS_E_GC_GENERIC error (0x80030100) when checking device status")
|
||||
return True
|
||||
else:
|
||||
self.log.warning(f"Error checking device status, error code: 0x{error_code:x}")
|
||||
else:
|
||||
# Log device status value
|
||||
self.log.info(f"Device status: {device_status.value}")
|
||||
|
||||
# Device status values (based on documentation and testing):
|
||||
# 0: Device is idle
|
||||
# 1: Device is busy with acquisition
|
||||
# 2: Device is busy with processing
|
||||
# 3: Device is busy with transfer
|
||||
if device_status.value > 0:
|
||||
self.log.warning(f"Camera appears busy: Device status is {device_status.value}")
|
||||
return True
|
||||
|
||||
# Try to get the acquisition status
|
||||
acquisition_status = c_uint()
|
||||
nRet = mv_lib.MV_VS_GetEnumValue(handle, b"AcquisitionStatus", byref(acquisition_status))
|
||||
|
||||
# If we get the 0x80030100 error, the camera is busy
|
||||
if nRet != MV_VS_OK:
|
||||
error_code = nRet & 0xFFFFFFFF
|
||||
if error_code == 0x80030100: # MV_VS_E_GC_GENERIC
|
||||
self.log.warning("Camera is busy: Detected MV_VS_E_GC_GENERIC error (0x80030100) when checking acquisition status")
|
||||
return True
|
||||
else:
|
||||
self.log.warning(f"Error checking acquisition status, error code: 0x{error_code:x}")
|
||||
else:
|
||||
# Log acquisition status value
|
||||
self.log.info(f"Acquisition status: {acquisition_status.value}")
|
||||
|
||||
# Acquisition status values (based on documentation and testing):
|
||||
# 0: Acquisition is idle
|
||||
# 1: Acquisition is active
|
||||
if acquisition_status.value > 0:
|
||||
self.log.warning(f"Camera appears busy: Acquisition status is {acquisition_status.value}")
|
||||
return True
|
||||
|
||||
# If we've reached this point, the camera is not busy
|
||||
self.log.info("Camera is not busy, safe to proceed with operations")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
self.log.error(f"Error checking if camera is busy: {e}")
|
||||
# Log the full exception traceback for debugging
|
||||
import traceback
|
||||
self.log.error(f"Exception traceback: {traceback.format_exc()}")
|
||||
return True # Assume busy if there's an error
|
||||
|
||||
def refresh_module_list(self):
|
||||
"""
|
||||
|
|
@ -375,7 +282,7 @@ class HikrobotSmartCamera(Component):
|
|||
self.log.error(f"Exception traceback: {traceback.format_exc()}")
|
||||
return False
|
||||
|
||||
def switch_scheme(self, solution_name, retry_count=0, max_retries=2, force=False, wait_timeout=30):
|
||||
def switch_scheme(self, solution_name, retry_count=0, max_retries=2):
|
||||
"""
|
||||
Switch to a different scheme/solution using the API as described in the documentation.
|
||||
|
||||
|
|
@ -383,8 +290,6 @@ class HikrobotSmartCamera(Component):
|
|||
solution_name: The name of the solution to switch to
|
||||
retry_count: Current retry attempt (used internally for recursion)
|
||||
max_retries: Maximum number of retry attempts for error recovery
|
||||
force: If True, attempt to switch scheme even if camera appears busy
|
||||
wait_timeout: Maximum time in seconds to wait for camera to become available
|
||||
|
||||
Returns:
|
||||
bool: True if the scheme switching process was successfully initiated, False otherwise
|
||||
|
|
@ -409,43 +314,6 @@ class HikrobotSmartCamera(Component):
|
|||
|
||||
handle = self.cam_list[0]["handle"]
|
||||
|
||||
# Check if camera is busy before proceeding
|
||||
if not force:
|
||||
is_busy = self.is_camera_busy(handle)
|
||||
if is_busy:
|
||||
self.log.warning(f"Camera is busy. Waiting for it to become available before switching to scheme: {solution_name}")
|
||||
|
||||
# Wait for the camera to become available with timeout
|
||||
start_time = time.time()
|
||||
wait_interval = 1.0 # Start with 1 second interval
|
||||
|
||||
while is_busy and (time.time() - start_time) < wait_timeout:
|
||||
# Wait with increasing interval (up to 3 seconds)
|
||||
self.log.info(f"Waiting {wait_interval:.1f} seconds before checking camera status again...")
|
||||
time.sleep(wait_interval)
|
||||
|
||||
# Increase wait interval for next iteration (up to 3 seconds)
|
||||
wait_interval = min(wait_interval * 1.5, 3.0)
|
||||
|
||||
# Check if camera is still busy
|
||||
is_busy = self.is_camera_busy(handle)
|
||||
if not is_busy:
|
||||
self.log.info("Camera is now available, proceeding with scheme switch")
|
||||
break
|
||||
|
||||
# If still busy after timeout, either retry or fail
|
||||
if is_busy:
|
||||
elapsed = time.time() - start_time
|
||||
self.log.warning(f"Camera still busy after waiting {elapsed:.1f} seconds")
|
||||
|
||||
if retry_count < max_retries:
|
||||
self.log.info(f"Retrying scheme switch (attempt {retry_count+1}/{max_retries})")
|
||||
return self.switch_scheme(solution_name, retry_count + 1, max_retries, force, wait_timeout)
|
||||
else:
|
||||
self.log.warning("Maximum retries reached, forcing scheme switch")
|
||||
# Continue with force=True on the last attempt
|
||||
force = True
|
||||
|
||||
# Get current camera state for debugging
|
||||
self.log.info("Getting camera state before scheme switch:")
|
||||
self._debug_camera_state(handle)
|
||||
|
|
|
|||
|
|
@ -171,15 +171,7 @@ class Test_Vision(Test_Test):
|
|||
# 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}")
|
||||
|
||||
# Update the progress dialog to show we're checking camera status
|
||||
progress_dialog.status_label.setText("Status: Checking camera availability...")
|
||||
progress_dialog.debug_label.setText("Debug info: Checking if camera is busy before switching scheme")
|
||||
|
||||
# Start the scheme switching process with wait_timeout parameter
|
||||
# This will automatically wait if the camera is busy
|
||||
self.log.info("Starting scheme switch with automatic busy detection and waiting")
|
||||
self.components[cam_type].switch_scheme(target_scheme, wait_timeout=25) # 25 seconds timeout to leave 5 seconds for the dialog timeout
|
||||
self.components[cam_type].switch_scheme(target_scheme)
|
||||
|
||||
# Show the dialog and wait for it to complete
|
||||
result = progress_dialog.exec_()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user