From f4dc4506b3ff93a65394e6a48dabcac86ff7e687 Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 10 Jul 2025 19:15:14 +0200 Subject: [PATCH] MainCode/adalm1000_logger.py aktualisiert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- MainCode/adalm1000_logger.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/MainCode/adalm1000_logger.py b/MainCode/adalm1000_logger.py index a195842..a84acf0 100644 --- a/MainCode/adalm1000_logger.py +++ b/MainCode/adalm1000_logger.py @@ -670,13 +670,17 @@ class BatteryTester(QMainWindow): def update_status(self): """Update status information periodically""" + now = time.time() + if not hasattr(self, '_last_log_time'): + self._last_log_time = now + if self.test_running: # Update capacity calculations if in test mode if self.measuring and self.time_data: current_time = time.time() - self.start_time delta_t = current_time - self.last_update_time self.last_update_time = current_time - + if self.test_phase == "Discharge": current_current = abs(self.current_data[-1]) 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_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): """Start the full battery test cycle""" # Clean up any previous test