MainCode/adalm1000_logger.py aktualisiert

Graceful Shutdown Sequence:

        Stop all measurement threads first

        Wait for them to complete

        Then cleanup the USB session

    Error Handling:

        Add more specific exception handling for USB operations

        Consider adding retries for non-critical operations

    Logging:

        Replace print statements with proper logging

        Consider logging to a file for debugging purposes
This commit is contained in:
Jan 2025-06-28 00:59:54 +02:00
parent 1f4b742604
commit 35bea6bdd1

View File

@ -75,7 +75,9 @@ class MeasurementThread(QThread):
self._running = False self._running = False
if self.isRunning(): if self.isRunning():
self.quit() self.quit()
self.wait(500) if not self.wait(500): # Wait up to 500ms for clean exit
print("Warning: Thread didn't exit cleanly, terminating")
self.terminate()
class BatteryTester(QMainWindow): class BatteryTester(QMainWindow):
def __init__(self): def __init__(self):
@ -352,6 +354,8 @@ class BatteryTester(QMainWindow):
def init_device(self): def init_device(self):
"""Initialisiert das ADALM1000-Gerät""" """Initialisiert das ADALM1000-Gerät"""
# Temporarily enable USB debugging
os.environ['LIBUSB_DEBUG'] = '3' # Set to 0 in production
self.cleanup_device() self.cleanup_device()
try: try:
@ -389,6 +393,9 @@ class BatteryTester(QMainWindow):
if self.measurement_thread is not None: if self.measurement_thread is not None:
try: try:
self.measurement_thread.stop() self.measurement_thread.stop()
# Wait for thread to finish
if not self.measurement_thread.wait(1000): # 1 second timeout
print("Warning: Measurement thread didn't stop cleanly")
self.measurement_thread = None self.measurement_thread = None
except Exception as e: except Exception as e:
print(f"Fehler beim Stoppen des Mess-Threads: {e}") print(f"Fehler beim Stoppen des Mess-Threads: {e}")
@ -397,7 +404,10 @@ class BatteryTester(QMainWindow):
if hasattr(self, 'session'): if hasattr(self, 'session'):
try: try:
if self.session_active: if self.session_active:
# Add small delay before ending session
time.sleep(0.1)
self.session.end() self.session.end()
self.session_active = False
del self.session del self.session
except Exception as e: except Exception as e:
print(f"Fehler beim Bereinigen der Sitzung: {e}") print(f"Fehler beim Bereinigen der Sitzung: {e}")