dev
This commit is contained in:
parent
93063eba51
commit
c69b3930a9
|
|
@ -57,7 +57,12 @@ class HikrobotSmartCamera(Component):
|
|||
push_rate = c_uint()
|
||||
|
||||
try:
|
||||
self.log.debug("Getting push status information")
|
||||
self.log.info("Getting push status information for operation: " + str(self.current_operation))
|
||||
|
||||
# Get additional camera status information for debugging
|
||||
self.log.info("Current camera state before getting push status:")
|
||||
self._debug_camera_state(handle)
|
||||
|
||||
nRet1 = mv_lib.MV_VS_GetEnumValue(handle, b"ScPushType", byref(push_type))
|
||||
nRet2 = mv_lib.MV_VS_GetEnumValue(handle, b"ScPushState", byref(push_state))
|
||||
nRet3 = mv_lib.MV_VS_GetIntValue(handle, b"ScPushRate", byref(push_rate))
|
||||
|
|
@ -70,15 +75,18 @@ class HikrobotSmartCamera(Component):
|
|||
self.log.error(f"Failed to get ScPushRate, error code: 0x{nRet3&0xFFFFFFFF:x}")
|
||||
|
||||
if nRet1 == MV_VS_OK and nRet2 == MV_VS_OK and nRet3 == MV_VS_OK:
|
||||
self.log.debug(f"Push status - Type: {push_type.value}, State: {push_state.value}, Rate: {push_rate.value}")
|
||||
self.log.info(f"Push status - Type: {push_type.value}, State: {push_state.value}, Rate: {push_rate.value}")
|
||||
|
||||
# Check which operation we're monitoring
|
||||
if self.current_operation == "switch_scheme":
|
||||
# For scheme switching, we expect push_type.value == 2
|
||||
if push_type.value == 2: # LPRP 2 protocol loading progress
|
||||
progress = push_rate.value
|
||||
status = "Success" if push_state.value == 0 else "Failed"
|
||||
|
||||
self.log.info(f"Scheme switching progress: {progress}%, Status: {status}")
|
||||
|
||||
# Always emit progress updates, even if no progress is made
|
||||
self.progress_signal.emit(progress, status)
|
||||
|
||||
# If progress is complete or failed, stop the timer
|
||||
|
|
@ -93,7 +101,12 @@ class HikrobotSmartCamera(Component):
|
|||
else: # Failed
|
||||
self.log.error("Scheme switching failed")
|
||||
else:
|
||||
self.log.debug(f"Waiting for push type 2 (protocol loading), current type: {push_type.value}")
|
||||
# If we're not getting the expected push type, log it and still update the UI
|
||||
self.log.info(f"Waiting for push type 2 (protocol loading), current type: {push_type.value}")
|
||||
|
||||
# Send a progress update with the current status
|
||||
status_message = f"Initializing (Type: {push_type.value})"
|
||||
self.progress_signal.emit(10, status_message) # Use 10% as a placeholder for initialization
|
||||
|
||||
elif self.current_operation == "ntp_settings":
|
||||
if push_type.value == 16: # NTPS 16 NTP Time Check Status
|
||||
|
|
@ -113,18 +126,30 @@ class HikrobotSmartCamera(Component):
|
|||
else: # Failed
|
||||
self.log.error("NTP settings failed")
|
||||
else:
|
||||
self.log.debug(f"Waiting for push type 16 (NTP settings), current type: {push_type.value}")
|
||||
self.log.info(f"Waiting for push type 16 (NTP settings), current type: {push_type.value}")
|
||||
# Send a progress update with the current status
|
||||
status_message = f"Initializing (Type: {push_type.value})"
|
||||
self.progress_signal.emit(10, status_message)
|
||||
else:
|
||||
self.log.warning(f"Unknown operation type: {self.current_operation}")
|
||||
else:
|
||||
# If we can't get the push status after multiple attempts, try to proceed anyway
|
||||
self.log.warning("Could not get push status information, continuing with operation")
|
||||
# If we can't get the push status, log detailed error information
|
||||
self.log.warning(f"Could not get push status information, error codes: 0x{nRet1&0xFFFFFFFF:x}, 0x{nRet2&0xFFFFFFFF:x}, 0x{nRet3&0xFFFFFFFF:x}")
|
||||
|
||||
# Try to get additional camera status for debugging
|
||||
self._debug_camera_state(handle)
|
||||
|
||||
# Send a progress update to the UI
|
||||
status_message = "Initializing (Status retrieval failed)"
|
||||
self.progress_signal.emit(5, status_message)
|
||||
|
||||
# After 10 seconds (20 checks at 500ms), force completion if we're still waiting
|
||||
if not hasattr(self, '_progress_check_count'):
|
||||
self._progress_check_count = 0
|
||||
|
||||
self._progress_check_count += 1
|
||||
self.log.info(f"Progress check count: {self._progress_check_count}/20")
|
||||
|
||||
if self._progress_check_count >= 20:
|
||||
current_op = self.current_operation
|
||||
self.log.warning(f"Force completing operation after timeout: {current_op}")
|
||||
|
|
@ -141,6 +166,41 @@ class HikrobotSmartCamera(Component):
|
|||
self.log.error(f"Error checking progress: {e}")
|
||||
self.progress_timer.stop()
|
||||
self.current_operation = None
|
||||
|
||||
def _debug_camera_state(self, handle):
|
||||
"""
|
||||
Get additional camera state information for debugging purposes.
|
||||
|
||||
Args:
|
||||
handle: Camera handle
|
||||
"""
|
||||
try:
|
||||
# Try to get the current solution name
|
||||
solution_name = create_string_buffer(256)
|
||||
nRet = mv_lib.MV_VS_GetStringValue(handle, b"SrcOperateSolutionName", solution_name, 256)
|
||||
if nRet == MV_VS_OK:
|
||||
self.log.info(f"Current solution name: {solution_name.value.decode('utf-8')}")
|
||||
else:
|
||||
self.log.info(f"Failed to get solution name, error code: 0x{nRet&0xFFFFFFFF:x}")
|
||||
|
||||
# Try to get the device status
|
||||
device_status = c_uint()
|
||||
nRet = mv_lib.MV_VS_GetEnumValue(handle, b"DeviceStatus", byref(device_status))
|
||||
if nRet == MV_VS_OK:
|
||||
self.log.info(f"Device status: {device_status.value}")
|
||||
else:
|
||||
self.log.info(f"Failed to get device status, error code: 0x{nRet&0xFFFFFFFF:x}")
|
||||
|
||||
# Try to get the acquisition status
|
||||
acquisition_status = c_uint()
|
||||
nRet = mv_lib.MV_VS_GetEnumValue(handle, b"AcquisitionStatus", byref(acquisition_status))
|
||||
if nRet == MV_VS_OK:
|
||||
self.log.info(f"Acquisition status: {acquisition_status.value}")
|
||||
else:
|
||||
self.log.info(f"Failed to get acquisition status, error code: 0x{nRet&0xFFFFFFFF:x}")
|
||||
|
||||
except Exception as e:
|
||||
self.log.error(f"Error getting debug camera state: {e}")
|
||||
|
||||
def refresh_module_list(self):
|
||||
"""
|
||||
|
|
@ -179,6 +239,9 @@ class HikrobotSmartCamera(Component):
|
|||
|
||||
Args:
|
||||
solution_name: The name of the solution to switch to
|
||||
|
||||
Returns:
|
||||
bool: True if the scheme switching process was successfully initiated, False otherwise
|
||||
"""
|
||||
if not self.connected:
|
||||
self.log.error("Cannot switch scheme: Camera not connected")
|
||||
|
|
@ -189,30 +252,55 @@ class HikrobotSmartCamera(Component):
|
|||
self.log.error("Cannot switch scheme: No camera handles available")
|
||||
return False
|
||||
|
||||
# Check if an operation is already in progress
|
||||
if self.current_operation is not None:
|
||||
self.log.warning(f"Cannot switch scheme: Another operation is already in progress: {self.current_operation}")
|
||||
# Try to stop the current operation
|
||||
if self.progress_timer.isActive():
|
||||
self.log.warning(f"Stopping ongoing operation: {self.current_operation}")
|
||||
self.progress_timer.stop()
|
||||
self.current_operation = None
|
||||
|
||||
handle = self.cam_list[0]["handle"]
|
||||
|
||||
# Get current camera state for debugging
|
||||
self.log.info("Getting camera state before scheme switch:")
|
||||
self._debug_camera_state(handle)
|
||||
|
||||
try:
|
||||
self.log.info(f"Starting scheme switch to: {solution_name}")
|
||||
|
||||
# Check if the solution name is valid (not empty)
|
||||
if not solution_name or solution_name.strip() == "":
|
||||
self.log.error("Cannot switch scheme: Solution name is empty")
|
||||
return False
|
||||
|
||||
# 1. Set the SrcOperateSolutionName node as the target schema name
|
||||
solution_name_bytes = solution_name.encode('utf-8')
|
||||
self.log.debug(f"Setting solution name: {solution_name} (bytes: {solution_name_bytes})")
|
||||
self.log.info(f"Setting solution name: {solution_name} (bytes: {solution_name_bytes})")
|
||||
nRet = mv_lib.MV_VS_SetStringValue(handle, b"SrcOperateSolutionName", solution_name_bytes)
|
||||
if nRet != MV_VS_OK:
|
||||
self.log.error(f"Failed to set solution name: {solution_name}, error code: 0x{nRet&0xFFFFFFFF:x}")
|
||||
# Try to get more information about the error
|
||||
self._debug_camera_state(handle)
|
||||
return False
|
||||
else:
|
||||
self.log.info(f"Successfully set solution name: {solution_name}")
|
||||
|
||||
# 2. Set the Load Scenario command
|
||||
self.log.debug("Sending CommandProjectLoad command")
|
||||
self.log.info("Sending CommandProjectLoad command")
|
||||
nRet = mv_lib.MV_VS_SetCommandValue(handle, b"CommandProjectLoad")
|
||||
if nRet != MV_VS_OK:
|
||||
self.log.error(f"Failed to load project, error code: 0x{nRet&0xFFFFFFFF:x}")
|
||||
# Try to get more information about the error
|
||||
self._debug_camera_state(handle)
|
||||
return False
|
||||
else:
|
||||
self.log.info("Successfully sent project load command")
|
||||
|
||||
# Reset progress check count
|
||||
self._progress_check_count = 0
|
||||
|
||||
# Start monitoring progress
|
||||
self.log.info("Starting progress monitoring for scheme switching")
|
||||
self.current_operation = "switch_scheme"
|
||||
|
|
@ -221,6 +309,9 @@ class HikrobotSmartCamera(Component):
|
|||
return True
|
||||
except Exception as e:
|
||||
self.log.error(f"Error switching scheme: {e}")
|
||||
# Log the full exception traceback for debugging
|
||||
import traceback
|
||||
self.log.error(f"Exception traceback: {traceback.format_exc()}")
|
||||
return False
|
||||
|
||||
def get_ntp_parameters(self):
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import sys
|
||||
import logging
|
||||
import time
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, QTimer
|
||||
from PyQt5.QtGui import QColor, QImage, QPalette, QPixmap
|
||||
|
|
@ -20,6 +21,9 @@ class SchemeProgressDialog(QDialog):
|
|||
self.setModal(True)
|
||||
self.setMinimumWidth(400)
|
||||
|
||||
# Add a logger
|
||||
self.log = logging.getLogger("SchemeProgressDialog")
|
||||
|
||||
layout = QVBoxLayout()
|
||||
self.setLayout(layout)
|
||||
|
||||
|
|
@ -34,18 +38,67 @@ class SchemeProgressDialog(QDialog):
|
|||
self.status_label = QLabel("Status: Initializing...")
|
||||
layout.addWidget(self.status_label)
|
||||
|
||||
# No timeout - wait indefinitely for the scheme switching to complete
|
||||
self.debug_label = QLabel("Debug info: Waiting for camera response...")
|
||||
layout.addWidget(self.debug_label)
|
||||
|
||||
# Add a timeout mechanism (30 seconds)
|
||||
self.timeout_timer = QTimer(self)
|
||||
self.timeout_timer.timeout.connect(self.check_timeout)
|
||||
self.timeout_timer.start(30000) # 30 seconds timeout
|
||||
|
||||
# Track the last progress update time
|
||||
self.last_update_time = time.time()
|
||||
|
||||
# Create a timer to update the waiting time display
|
||||
self.update_timer = QTimer(self)
|
||||
self.update_timer.timeout.connect(self.update_waiting_time)
|
||||
self.update_timer.start(1000) # Update every second
|
||||
|
||||
def update_waiting_time(self):
|
||||
"""
|
||||
Update the display of how long we've been waiting
|
||||
"""
|
||||
elapsed = int(time.time() - self.last_update_time)
|
||||
self.debug_label.setText(f"Debug info: Waiting for {elapsed} seconds since last update")
|
||||
|
||||
def check_timeout(self):
|
||||
"""
|
||||
Check if we've been waiting too long and close the dialog
|
||||
"""
|
||||
self.log.warning("Scheme switching timeout after 30 seconds")
|
||||
self.debug_label.setText("Debug info: Timeout after 30 seconds. Continuing anyway.")
|
||||
self.reject()
|
||||
|
||||
def update_progress(self, progress, status):
|
||||
"""
|
||||
Update the progress bar and status label based on the progress signal.
|
||||
"""
|
||||
self.progress_bar.setValue(progress)
|
||||
self.status_label.setText(f"Status: {status}")
|
||||
self.log.info(f"Progress update: {progress}%, Status: {status}")
|
||||
|
||||
# Reset the last update time
|
||||
self.last_update_time = time.time()
|
||||
|
||||
# Update the progress bar
|
||||
self.progress_bar.setValue(progress)
|
||||
|
||||
# Update the status label with more detailed information
|
||||
if "Initializing" in status:
|
||||
self.status_label.setText(f"Status: {status}")
|
||||
self.debug_label.setText(f"Debug info: Camera is initializing. This may take some time.")
|
||||
else:
|
||||
self.status_label.setText(f"Status: {status}")
|
||||
self.debug_label.setText(f"Debug info: Progress update received at {time.strftime('%H:%M:%S')}")
|
||||
|
||||
# Check for completion or failure
|
||||
if progress >= 100 and status == "Success":
|
||||
self.log.info("Scheme switching completed successfully")
|
||||
self.timeout_timer.stop()
|
||||
self.update_timer.stop()
|
||||
self.accept()
|
||||
elif status == "Failed":
|
||||
self.log.error("Scheme switching failed")
|
||||
self.timeout_timer.stop()
|
||||
self.update_timer.stop()
|
||||
self.reject()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user