diff --git a/MainCode/adalm1000_logger.py b/MainCode/adalm1000_logger.py index 5116d4d..4c6bf82 100644 --- a/MainCode/adalm1000_logger.py +++ b/MainCode/adalm1000_logger.py @@ -420,22 +420,19 @@ class BatteryTester: def stop_test(self): """Stop the current test""" self.test_running = False - self.continuous_mode = False # Always stop continuous mode when stop is pressed + self.continuous_mode = False self.measuring = False if hasattr(self, 'dev'): - self.dev.channels['A'].constant(0) # Set zero current + self.dev.channels['A'].constant(0) - # Write final summary if we have a filename + # Update status message if hasattr(self, 'filename'): - self.write_cycle_summary() - - self.start_button.config(state=tk.NORMAL) - self.stop_button.config(state=tk.DISABLED) - - if hasattr(self, 'filename'): - self.status_var.set(f"Test completed in {self.format_time(self.time_data[-1])} | Results saved to: {os.path.basename(self.filename)}") + self.status_var.set( + f"Test interrupted after cycle {self.cycle_count.get()} | " + f"Results saved to: {os.path.basename(self.filename)}" + ) else: - self.status_var.set("Test stopped | No data saved") + self.status_var.set("Test interrupted - no data saved") def center_window(self, window): """Center a window on screen""" @@ -456,60 +453,18 @@ class BatteryTester: # Increment cycle count self.cycle_count.set(self.cycle_count.get() + 1) self.root.after(0, lambda: self.cycle_label.config(text=str(self.cycle_count.get()))) - - # 1. Initial Discharge (to known state) - self.test_phase.set("Initial Discharge") - self.status_var.set(f"Discharging to {self.discharge_cutoff.get()}V @ {test_current:.3f}A") - - self.measuring = True - self.dev.channels['A'].mode = pysmu.Mode.SIMV - self.dev.channels['A'].constant(-test_current) - self.dev.channels['B'].mode = pysmu.Mode.HI_Z - - while self.test_running: - if not self.voltage_data: - time.sleep(0.1) - continue - - current_voltage = self.voltage_data[-1] - current_current = abs(self.current_data[-1]) - self.status_var.set( - f"Discharging: {current_voltage:.3f}V / {self.discharge_cutoff.get()}V | " - f"Current: {current_current:.3f}A | " - f"Time: {self.format_time(self.time_data[-1])}" - ) - - if current_voltage <= self.discharge_cutoff.get(): - break - time.sleep(0.5) - + + # Check for Interrupt if not self.test_running: - return + self.status_var.set("Test interrupted - finishing current cycle") + break - # 2. Rest period after initial discharge - self.test_phase.set("Resting (Post-Discharge)") - self.measuring = False - self.dev.channels['A'].mode = pysmu.Mode.HI_Z - self.dev.channels['A'].constant(0) - - rest_end_time = time.time() + (self.rest_time.get() * 3600) - while time.time() < rest_end_time and self.test_running: - time_left = max(0, rest_end_time - time.time()) - self.status_var.set( - f"Resting after discharge | " - f"Time left: {self.format_time(time_left)} | " - f"Next: Charging to {self.charge_cutoff.get()}V" - ) - time.sleep(1) - - if not self.test_running: - return - - # 3. Charge (constant current) + # 1. Charge (constant current) self.test_phase.set("Charge") self.status_var.set(f"Charging to {self.charge_cutoff.get()}V @ {test_current:.3f}A") self.measuring = True + self.dev.channels['B'].mode = pysmu.Mode.HI_Z self.dev.channels['A'].mode = pysmu.Mode.SIMV self.dev.channels['A'].constant(test_current) self.charge_capacity.set(0.0) @@ -546,7 +501,7 @@ class BatteryTester: if not self.test_running: return - # 4. Rest period after charge + # 2. Rest period after charge self.test_phase.set("Resting (Post-Charge)") self.measuring = False self.dev.channels['A'].mode = pysmu.Mode.HI_Z @@ -565,7 +520,7 @@ class BatteryTester: if not self.test_running: return - # 5. Final Discharge (capacity measurement) + # 3. Final Discharge (capacity measurement) self.test_phase.set("Final Discharge") self.status_var.set(f"Final discharge to {self.discharge_cutoff.get()}V @ {test_current:.3f}A") @@ -602,6 +557,32 @@ class BatteryTester: time.sleep(0.5) + # 4. Rest period after charge + self.test_phase.set("Resting (Post-Discharge)") + self.measuring = False + self.dev.channels['A'].mode = pysmu.Mode.HI_Z + self.dev.channels['A'].constant(0) + + rest_end_time = time.time() + (self.rest_time.get() * 3600) + while time.time() < rest_end_time and self.test_running: + time_left = max(0, rest_end_time - time.time()) + + # Angepasste Statusmeldung mit Interrupt-Info + if self.test_running and self.continuous_mode: + next_action = f"Next: Charge to {self.charge_cutoff.get()}V" + else: + next_action = "Waiting for interrupt or completion" + + self.status_var.set( + f"Resting after discharge | " + f"Time left: {time_left/60:.1f} min | " + f"{next_action}" + ) + time.sleep(1) + + if not self.test_running: + return + # Calculate Coulomb efficiency if self.charge_capacity.get() > 0: efficiency = (self.capacity_ah.get() / self.charge_capacity.get()) * 100