MainCode/adalm1000_logger.py aktualisiert

Initialization Order:

        Now initializes all data structures (time_data, voltage_data, etc.) in __init__ before they're used

        Initializes device after UI setup using QTimer.singleShot

    Error Handling:

        Properly handles the case when no ADALM1000 is detected

        Disables the start button until a device is connected

    Device Connection:

        Shows clear status messages about device connection state

        Provides a reconnect button for manual reconnection attempts

    Thread Safety:

        Ensures all data structures exist before any thread tries to access them
(D)
This commit is contained in:
Jan 2025-06-27 16:24:00 +02:00
parent 882f19945c
commit 0b3177ead4

View File

@ -13,7 +13,7 @@ os.environ['QT_LOGGING_RULES'] = 'qt.qpa.*=false'
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
QGridLayout, QLabel, QPushButton, QLineEdit, QFrame,
QCheckBox, QMessageBox, QFileDialog)
from PyQt5.QtCore import Qt, QTimer, pyqtSignal, pyqtSlot, QObject
from PyQt5.QtCore import Qt, QTimer, pyqtSignal, pyqtSlot, QObject, QThread
from PyQt5.QtGui import QColor, QPalette
import pysmu
@ -80,6 +80,12 @@ class BatteryTester(QMainWindow):
def __init__(self):
super().__init__()
# Initialize data structures first
self.time_data = deque()
self.voltage_data = deque()
self.current_data = deque()
self.phase_data = deque()
# Color scheme
self.bg_color = QColor(46, 52, 64)
self.fg_color = QColor(216, 222, 233)
@ -99,7 +105,6 @@ class BatteryTester(QMainWindow):
# Initialize UI
self.setup_ui()
self.init_device()
# Track measurement thread
self.measurement_thread = None
@ -108,11 +113,15 @@ class BatteryTester(QMainWindow):
# Track test thread
self.test_thread = None
# Data buffers
self.time_data = deque()
self.voltage_data = deque()
self.current_data = deque()
self.phase_data = deque()
# Initialize test phase and values
self.test_phase = "Idle"
self.capacity_ah = 0.0
self.charge_capacity = 0.0
self.coulomb_efficiency = 0.0
self.cycle_count = 0
# Initialize device after UI is set up
QTimer.singleShot(100, self.init_device)
def setup_ui(self):
"""Configure the user interface"""
@ -264,6 +273,7 @@ class BatteryTester(QMainWindow):
self.start_button = QPushButton("START TEST")
self.start_button.clicked.connect(self.start_test)
self.start_button.setStyleSheet(f"background-color: {self.accent_color.name()}; font-weight: bold;")
self.start_button.setEnabled(False) # Disabled until device is connected
button_layout.addWidget(self.start_button)
self.stop_button = QPushButton("STOP TEST")
@ -289,16 +299,9 @@ class BatteryTester(QMainWindow):
self.status_bar.setStyleSheet("font-size: 10px; padding: 5px;")
self.main_layout.addWidget(self.status_bar)
# Initialize test phase
self.test_phase = "Idle"
# Initialize test phase display
self.phase_label.setText(self.test_phase)
# Initialize capacity and efficiency
self.capacity_ah = 0.0
self.charge_capacity = 0.0
self.coulomb_efficiency = 0.0
self.cycle_count = 0
def setup_plot(self):
"""Configure the matplotlib plot"""
self.plot_widget = QWidget()