MainCode/adalm1000_logger.py aktualisiert

Logging funktioniert wieder zuverlässig wie früher ✅

Kein Datenverlust bei Crash, da flush() sofort schreibt ✅

Bei langen Tests bleibt die Datei schlank, falls du das Intervall auf 1s limitierst ✅
(C)
This commit is contained in:
Jan
2025-07-10 19:15:14 +02:00
parent 401f19d237
commit f4dc4506b3
+24 -1
View File
@@ -670,13 +670,17 @@ class BatteryTester(QMainWindow):
def update_status(self): def update_status(self):
"""Update status information periodically""" """Update status information periodically"""
now = time.time()
if not hasattr(self, '_last_log_time'):
self._last_log_time = now
if self.test_running: if self.test_running:
# Update capacity calculations if in test mode # Update capacity calculations if in test mode
if self.measuring and self.time_data: if self.measuring and self.time_data:
current_time = time.time() - self.start_time current_time = time.time() - self.start_time
delta_t = current_time - self.last_update_time delta_t = current_time - self.last_update_time
self.last_update_time = current_time self.last_update_time = current_time
if self.test_phase == "Discharge": if self.test_phase == "Discharge":
current_current = abs(self.current_data[-1]) current_current = abs(self.current_data[-1])
self.capacity_ah += current_current * delta_t / 3600 self.capacity_ah += current_current * delta_t / 3600
@@ -686,6 +690,25 @@ class BatteryTester(QMainWindow):
self.charge_capacity += current_current * delta_t / 3600 self.charge_capacity += current_current * delta_t / 3600
self.charge_capacity_label.setText(f"{self.charge_capacity:.4f}") self.charge_capacity_label.setText(f"{self.charge_capacity:.4f}")
# Logging (1x pro Sekunde)
if hasattr(self, 'log_writer') and (now - self._last_log_time >= 1.0):
if self.time_data:
current_time = self.time_data[-1]
voltage = self.voltage_data[-1]
current = self.current_data[-1]
self.log_writer.writerow([
f"{current_time:.3f}",
f"{voltage:.6f}",
f"{current:.6f}",
self.test_phase,
f"{self.capacity_ah:.4f}",
f"{self.charge_capacity:.4f}",
f"{self.coulomb_efficiency:.1f}",
f"{self.cycle_count}"
])
self.current_cycle_file.flush()
self._last_log_time = now
def start_test(self): def start_test(self):
"""Start the full battery test cycle""" """Start the full battery test cycle"""
# Clean up any previous test # Clean up any previous test