dev rev
This commit is contained in:
parent
1ee186eb34
commit
6cfcbbeb65
|
|
@ -238,101 +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 before scheme switching...")
|
||||
|
||||
# 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")
|
||||
self.log.info("This error indicates the camera is currently busy with another operation")
|
||||
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")
|
||||
self.log.info("This error indicates the camera is currently busy with acquisition")
|
||||
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 scheme switching")
|
||||
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):
|
||||
"""
|
||||
|
|
@ -377,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):
|
||||
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.
|
||||
|
||||
|
|
@ -385,7 +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
|
||||
|
||||
Returns:
|
||||
bool: True if the scheme switching process was successfully initiated, False otherwise
|
||||
|
|
@ -410,20 +314,6 @@ class HikrobotSmartCamera(Component):
|
|||
|
||||
handle = self.cam_list[0]["handle"]
|
||||
|
||||
# Check if camera is busy before proceeding
|
||||
if not force and self.is_camera_busy(handle):
|
||||
self.log.warning(f"Cannot switch scheme to {solution_name}: Camera is busy")
|
||||
self.log.info("Use force=True to override this check if necessary")
|
||||
|
||||
# If we're already retrying, wait and try again
|
||||
if retry_count < max_retries:
|
||||
wait_time = 3 # Wait longer when camera is busy
|
||||
self.log.info(f"Waiting {wait_time} seconds before retry {retry_count+1}/{max_retries}")
|
||||
time.sleep(wait_time)
|
||||
return self.switch_scheme(solution_name, retry_count + 1, max_retries, force)
|
||||
|
||||
return False
|
||||
|
||||
# Get current camera state for debugging
|
||||
self.log.info("Getting camera state before scheme switch:")
|
||||
self._debug_camera_state(handle)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user