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:
parent
882f19945c
commit
0b3177ead4
@ -13,7 +13,7 @@ os.environ['QT_LOGGING_RULES'] = 'qt.qpa.*=false'
|
|||||||
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
|
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
|
||||||
QGridLayout, QLabel, QPushButton, QLineEdit, QFrame,
|
QGridLayout, QLabel, QPushButton, QLineEdit, QFrame,
|
||||||
QCheckBox, QMessageBox, QFileDialog)
|
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
|
from PyQt5.QtGui import QColor, QPalette
|
||||||
|
|
||||||
import pysmu
|
import pysmu
|
||||||
@ -80,6 +80,12 @@ class BatteryTester(QMainWindow):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
# Initialize data structures first
|
||||||
|
self.time_data = deque()
|
||||||
|
self.voltage_data = deque()
|
||||||
|
self.current_data = deque()
|
||||||
|
self.phase_data = deque()
|
||||||
|
|
||||||
# Color scheme
|
# Color scheme
|
||||||
self.bg_color = QColor(46, 52, 64)
|
self.bg_color = QColor(46, 52, 64)
|
||||||
self.fg_color = QColor(216, 222, 233)
|
self.fg_color = QColor(216, 222, 233)
|
||||||
@ -99,7 +105,6 @@ class BatteryTester(QMainWindow):
|
|||||||
|
|
||||||
# Initialize UI
|
# Initialize UI
|
||||||
self.setup_ui()
|
self.setup_ui()
|
||||||
self.init_device()
|
|
||||||
|
|
||||||
# Track measurement thread
|
# Track measurement thread
|
||||||
self.measurement_thread = None
|
self.measurement_thread = None
|
||||||
@ -108,11 +113,15 @@ class BatteryTester(QMainWindow):
|
|||||||
# Track test thread
|
# Track test thread
|
||||||
self.test_thread = None
|
self.test_thread = None
|
||||||
|
|
||||||
# Data buffers
|
# Initialize test phase and values
|
||||||
self.time_data = deque()
|
self.test_phase = "Idle"
|
||||||
self.voltage_data = deque()
|
self.capacity_ah = 0.0
|
||||||
self.current_data = deque()
|
self.charge_capacity = 0.0
|
||||||
self.phase_data = deque()
|
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):
|
def setup_ui(self):
|
||||||
"""Configure the user interface"""
|
"""Configure the user interface"""
|
||||||
@ -264,6 +273,7 @@ class BatteryTester(QMainWindow):
|
|||||||
self.start_button = QPushButton("START TEST")
|
self.start_button = QPushButton("START TEST")
|
||||||
self.start_button.clicked.connect(self.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.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)
|
button_layout.addWidget(self.start_button)
|
||||||
|
|
||||||
self.stop_button = QPushButton("STOP TEST")
|
self.stop_button = QPushButton("STOP TEST")
|
||||||
@ -289,15 +299,8 @@ class BatteryTester(QMainWindow):
|
|||||||
self.status_bar.setStyleSheet("font-size: 10px; padding: 5px;")
|
self.status_bar.setStyleSheet("font-size: 10px; padding: 5px;")
|
||||||
self.main_layout.addWidget(self.status_bar)
|
self.main_layout.addWidget(self.status_bar)
|
||||||
|
|
||||||
# Initialize test phase
|
# Initialize test phase display
|
||||||
self.test_phase = "Idle"
|
|
||||||
self.phase_label.setText(self.test_phase)
|
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):
|
def setup_plot(self):
|
||||||
"""Configure the matplotlib plot"""
|
"""Configure the matplotlib plot"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user