MainCode/adalm1000_logger.py aktualisiert
Working except of switching devices D
This commit is contained in:
parent
15e6856e76
commit
041bcc09a6
@ -256,6 +256,10 @@ class MeasurementThread(QThread):
|
|||||||
self.device.channels['A'].constant(0)
|
self.device.channels['A'].constant(0)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error stopping device: {e}")
|
print(f"Error stopping device: {e}")
|
||||||
|
self.wait(500) # Wait for thread to finish
|
||||||
|
|
||||||
|
def is_measuring(self):
|
||||||
|
return self.measurement_thread is not None and self.measurement_thread.isRunning()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Measurement loop with enhanced recovery"""
|
"""Measurement loop with enhanced recovery"""
|
||||||
@ -993,7 +997,6 @@ class BatteryTester(QMainWindow):
|
|||||||
padding: 4px 8px;
|
padding: 4px 8px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
min-height: 28px;
|
min-height: 28px;
|
||||||
background-color: {self.accent_color};
|
|
||||||
color: {self.fg_color};
|
color: {self.fg_color};
|
||||||
}}
|
}}
|
||||||
QPushButton:checked {{
|
QPushButton:checked {{
|
||||||
@ -1009,7 +1012,7 @@ class BatteryTester(QMainWindow):
|
|||||||
self.toggle_button = QPushButton("START")
|
self.toggle_button = QPushButton("START")
|
||||||
self.toggle_button.setCheckable(True)
|
self.toggle_button.setCheckable(True)
|
||||||
self.toggle_button.setStyleSheet(button_style + f"""
|
self.toggle_button.setStyleSheet(button_style + f"""
|
||||||
background-color: {self.accent_color};
|
background-color: {self.success_color};
|
||||||
min-width: 120px;
|
min-width: 120px;
|
||||||
""")
|
""")
|
||||||
self.toggle_button.clicked.connect(self.toggle_test)
|
self.toggle_button.clicked.connect(self.toggle_test)
|
||||||
@ -1026,8 +1029,8 @@ class BatteryTester(QMainWindow):
|
|||||||
self.record_button = QPushButton("● Start Recording")
|
self.record_button = QPushButton("● Start Recording")
|
||||||
self.record_button.setCheckable(True)
|
self.record_button.setCheckable(True)
|
||||||
self.record_button.setStyleSheet(button_style.replace(
|
self.record_button.setStyleSheet(button_style.replace(
|
||||||
self.accent_color, self.success_color
|
"background-color", "background-color", 1
|
||||||
))
|
) + f"background-color: {self.success_color};")
|
||||||
self.record_button.clicked.connect(self.toggle_global_recording)
|
self.record_button.clicked.connect(self.toggle_global_recording)
|
||||||
button_layout.addWidget(self.record_button)
|
button_layout.addWidget(self.record_button)
|
||||||
self.record_button.hide()
|
self.record_button.hide()
|
||||||
@ -1056,7 +1059,7 @@ class BatteryTester(QMainWindow):
|
|||||||
def apply_button_style(self):
|
def apply_button_style(self):
|
||||||
"""Apply consistent button styling based on current state"""
|
"""Apply consistent button styling based on current state"""
|
||||||
if self.toggle_button.isChecked():
|
if self.toggle_button.isChecked():
|
||||||
# Stop state
|
# Stop state - red
|
||||||
self.toggle_button.setStyleSheet(f"""
|
self.toggle_button.setStyleSheet(f"""
|
||||||
QPushButton {{
|
QPushButton {{
|
||||||
background-color: {self.warning_color};
|
background-color: {self.warning_color};
|
||||||
@ -1072,10 +1075,10 @@ class BatteryTester(QMainWindow):
|
|||||||
}}
|
}}
|
||||||
""")
|
""")
|
||||||
else:
|
else:
|
||||||
# Start state
|
# Start state - green
|
||||||
self.toggle_button.setStyleSheet(f"""
|
self.toggle_button.setStyleSheet(f"""
|
||||||
QPushButton {{
|
QPushButton {{
|
||||||
background-color: {self.accent_color};
|
background-color: {self.success_color};
|
||||||
color: {self.fg_color};
|
color: {self.fg_color};
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
border: none;
|
border: none;
|
||||||
@ -1084,7 +1087,33 @@ class BatteryTester(QMainWindow):
|
|||||||
min-height: 28px;
|
min-height: 28px;
|
||||||
}}
|
}}
|
||||||
QPushButton:hover {{
|
QPushButton:hover {{
|
||||||
background-color: #{self.darker_color(self.accent_color)};
|
background-color: #{self.darker_color(self.success_color)};
|
||||||
|
}}
|
||||||
|
""")
|
||||||
|
|
||||||
|
# Update record button separately
|
||||||
|
if self.record_button.isChecked():
|
||||||
|
self.record_button.setStyleSheet(f"""
|
||||||
|
QPushButton {{
|
||||||
|
background-color: {self.warning_color};
|
||||||
|
color: white;
|
||||||
|
font-weight: bold;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 4px 8px;
|
||||||
|
min-height: 28px;
|
||||||
|
}}
|
||||||
|
""")
|
||||||
|
else:
|
||||||
|
self.record_button.setStyleSheet(f"""
|
||||||
|
QPushButton {{
|
||||||
|
background-color: {self.success_color};
|
||||||
|
color: {self.fg_color};
|
||||||
|
font-weight: bold;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 4px 8px;
|
||||||
|
min-height: 28px;
|
||||||
}}
|
}}
|
||||||
""")
|
""")
|
||||||
|
|
||||||
@ -1114,7 +1143,7 @@ class BatteryTester(QMainWindow):
|
|||||||
|
|
||||||
if all_success:
|
if all_success:
|
||||||
self.record_button.setText("■ Stop Recording")
|
self.record_button.setText("■ Stop Recording")
|
||||||
self.record_button.setStyleSheet(f"background-color: {self.warning_color};")
|
self.apply_button_style() # Update style
|
||||||
self.status_bar.showMessage("Recording started for all connected devices")
|
self.status_bar.showMessage("Recording started for all connected devices")
|
||||||
else:
|
else:
|
||||||
self.global_recording = False
|
self.global_recording = False
|
||||||
@ -1126,7 +1155,7 @@ class BatteryTester(QMainWindow):
|
|||||||
self.finalize_device_log_file(device) # Changed from _stop_device_recording
|
self.finalize_device_log_file(device) # Changed from _stop_device_recording
|
||||||
|
|
||||||
self.record_button.setText("● Start Recording")
|
self.record_button.setText("● Start Recording")
|
||||||
self.record_button.setStyleSheet(f"background-color: {self.success_color};")
|
self.apply_button_style() # Update style
|
||||||
self.status_bar.showMessage("Recording stopped for all devices")
|
self.status_bar.showMessage("Recording stopped for all devices")
|
||||||
|
|
||||||
def safe_execute(func):
|
def safe_execute(func):
|
||||||
@ -1140,13 +1169,12 @@ class BatteryTester(QMainWindow):
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
@safe_execute
|
@safe_execute
|
||||||
def toggle_test(self):
|
def toggle_test(self, checked):
|
||||||
if self.toggle_button.isChecked():
|
if checked:
|
||||||
self.apply_button_style() # Add this line
|
|
||||||
self.start_test()
|
self.start_test()
|
||||||
else:
|
else:
|
||||||
self.apply_button_style() # Add this line
|
|
||||||
self.stop_test()
|
self.stop_test()
|
||||||
|
self.apply_button_style()
|
||||||
|
|
||||||
def change_mode(self, mode_name):
|
def change_mode(self, mode_name):
|
||||||
"""Change between different test modes"""
|
"""Change between different test modes"""
|
||||||
@ -1250,6 +1278,7 @@ class BatteryTester(QMainWindow):
|
|||||||
if self.create_cycle_log_file():
|
if self.create_cycle_log_file():
|
||||||
dev.is_recording = True # Set device's recording state
|
dev.is_recording = True # Set device's recording state
|
||||||
self.record_button.setText("Stop Recording")
|
self.record_button.setText("Stop Recording")
|
||||||
|
self.apply_button_style() # Update style
|
||||||
self.status_bar.showMessage("Live recording started")
|
self.status_bar.showMessage("Live recording started")
|
||||||
# Ensure monitoring is running
|
# Ensure monitoring is running
|
||||||
if not self.test_running:
|
if not self.test_running:
|
||||||
@ -1269,6 +1298,7 @@ class BatteryTester(QMainWindow):
|
|||||||
self.finalize_log_file()
|
self.finalize_log_file()
|
||||||
dev.is_recording = False # Clear device's recording state
|
dev.is_recording = False # Clear device's recording state
|
||||||
self.record_button.setText("Start Recording")
|
self.record_button.setText("Start Recording")
|
||||||
|
self.apply_button_style() # Update style
|
||||||
self.status_bar.showMessage("Live recording stopped")
|
self.status_bar.showMessage("Live recording stopped")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error stopping recording: {e}")
|
print(f"Error stopping recording: {e}")
|
||||||
@ -1413,6 +1443,10 @@ class BatteryTester(QMainWindow):
|
|||||||
self.status_light.setStyleSheet(f"""
|
self.status_light.setStyleSheet(f"""
|
||||||
background-color: {color};
|
background-color: {color};
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
|
min-width: 12px;
|
||||||
|
max-width: 12px;
|
||||||
|
min-height: 12px;
|
||||||
|
max-height: 12px;
|
||||||
""")
|
""")
|
||||||
QApplication.processEvents()
|
QApplication.processEvents()
|
||||||
|
|
||||||
@ -1509,9 +1543,8 @@ class BatteryTester(QMainWindow):
|
|||||||
if hasattr(self.active_device, 'measurement_thread'):
|
if hasattr(self.active_device, 'measurement_thread'):
|
||||||
thread = self.active_device.measurement_thread
|
thread = self.active_device.measurement_thread
|
||||||
try:
|
try:
|
||||||
if thread.isRunning():
|
thread.stop() # Properly stop the thread
|
||||||
thread.stop()
|
thread.wait(500) # Wait for clean shutdown
|
||||||
thread.wait(500)
|
|
||||||
thread.update_signal.disconnect()
|
thread.update_signal.disconnect()
|
||||||
thread.error_signal.disconnect()
|
thread.error_signal.disconnect()
|
||||||
except (RuntimeError, TypeError) as e:
|
except (RuntimeError, TypeError) as e:
|
||||||
@ -1524,20 +1557,30 @@ class BatteryTester(QMainWindow):
|
|||||||
# Activate new device
|
# Activate new device
|
||||||
self.active_device = self.devices[serial]
|
self.active_device = self.devices[serial]
|
||||||
|
|
||||||
|
# Ensure measurement thread exists and is properly configured
|
||||||
|
if not hasattr(self.active_device, 'measurement_thread') or not self.active_device.measurement_thread:
|
||||||
|
self.active_device.start_measurement(self.interval)
|
||||||
|
|
||||||
# Connect signals to new device
|
# Connect signals to new device
|
||||||
if hasattr(self.active_device, 'measurement_thread'):
|
|
||||||
try:
|
|
||||||
self.measurement_thread = self.active_device.measurement_thread
|
self.measurement_thread = self.active_device.measurement_thread
|
||||||
|
|
||||||
|
# Disconnect any existing connections first
|
||||||
|
try:
|
||||||
|
self.measurement_thread.update_signal.disconnect()
|
||||||
|
except (TypeError, RuntimeError):
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
self.measurement_thread.error_signal.disconnect()
|
||||||
|
except (TypeError, RuntimeError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Reconnect signals
|
||||||
self.measurement_thread.update_signal.connect(self.update_measurements)
|
self.measurement_thread.update_signal.connect(self.update_measurements)
|
||||||
self.measurement_thread.error_signal.connect(self.handle_device_error)
|
self.measurement_thread.error_signal.connect(self.handle_device_error)
|
||||||
|
|
||||||
# Start measurement only AFTER connecting signals
|
# Ensure thread is running
|
||||||
if not self.measurement_thread.isRunning():
|
if not self.measurement_thread.isRunning():
|
||||||
self.active_device.start_measurement(self.interval)
|
self.active_device.start_measurement(self.interval)
|
||||||
print("Measurement thread running?", self.measurement_thread.isRunning())
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error connecting to new device: {e}")
|
|
||||||
return
|
|
||||||
|
|
||||||
# Update UI with current device data
|
# Update UI with current device data
|
||||||
self.update_ui_from_active_device()
|
self.update_ui_from_active_device()
|
||||||
@ -1546,6 +1589,7 @@ class BatteryTester(QMainWindow):
|
|||||||
# Update recording button state
|
# Update recording button state
|
||||||
self.record_button.setChecked(self.global_recording)
|
self.record_button.setChecked(self.global_recording)
|
||||||
self.record_button.setText("Stop Recording" if self.global_recording else "Start Recording")
|
self.record_button.setText("Stop Recording" if self.global_recording else "Start Recording")
|
||||||
|
self.apply_button_style() # Ensure proper colors
|
||||||
|
|
||||||
def update_ui_from_active_device(self):
|
def update_ui_from_active_device(self):
|
||||||
dev = self.active_device
|
dev = self.active_device
|
||||||
@ -1700,6 +1744,7 @@ class BatteryTester(QMainWindow):
|
|||||||
if not self.active_device:
|
if not self.active_device:
|
||||||
QMessageBox.warning(self, "No Device", "No ADALM1000 device selected.")
|
QMessageBox.warning(self, "No Device", "No ADALM1000 device selected.")
|
||||||
self.toggle_button.setChecked(False)
|
self.toggle_button.setChecked(False)
|
||||||
|
self.apply_button_style()
|
||||||
return
|
return
|
||||||
|
|
||||||
dev_manager = self.active_device
|
dev_manager = self.active_device
|
||||||
@ -1739,6 +1784,7 @@ class BatteryTester(QMainWindow):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
QMessageBox.critical(self, "Device Error", f"Failed to reset device: {e}")
|
QMessageBox.critical(self, "Device Error", f"Failed to reset device: {e}")
|
||||||
self.toggle_button.setChecked(False)
|
self.toggle_button.setChecked(False)
|
||||||
|
self.apply_button_style()
|
||||||
return
|
return
|
||||||
|
|
||||||
# Reset test variables
|
# Reset test variables
|
||||||
@ -2398,12 +2444,12 @@ class BatteryTester(QMainWindow):
|
|||||||
self.apply_button_style()
|
self.apply_button_style()
|
||||||
self.toggle_button.setStyleSheet(f"""
|
self.toggle_button.setStyleSheet(f"""
|
||||||
QPushButton {{
|
QPushButton {{
|
||||||
background-color: {self.status_colors["active"]};
|
background-color: {self.success_color};
|
||||||
color: {self.fg_color};
|
color: {self.fg_color};
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}}
|
}}
|
||||||
QPushButton:checked {{
|
QPushButton:checked {{
|
||||||
background-color: {self.status_colors["warning"]};
|
background-color: {self.warning_color};
|
||||||
}}
|
}}
|
||||||
QPushButton:disabled {{
|
QPushButton:disabled {{
|
||||||
background-color: #4C566A;
|
background-color: #4C566A;
|
||||||
@ -2422,7 +2468,7 @@ class BatteryTester(QMainWindow):
|
|||||||
self.toggle_button.setText(text)
|
self.toggle_button.setText(text)
|
||||||
self.toggle_button.setStyleSheet(f"""
|
self.toggle_button.setStyleSheet(f"""
|
||||||
QPushButton {{
|
QPushButton {{
|
||||||
background-color: {self.accent_color};
|
background-color: {self.success_color};
|
||||||
color: {self.fg_color};
|
color: {self.fg_color};
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}}
|
}}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user