diff --git a/MainCode/adalm1000_logger.py b/MainCode/adalm1000_logger.py index 9db43a8..ae11f60 100644 --- a/MainCode/adalm1000_logger.py +++ b/MainCode/adalm1000_logger.py @@ -489,35 +489,50 @@ class BatteryTester: return f"{hours:02d}:{minutes:02d}:{seconds:02d}" def stop_test(self): - """Request immediate stop of the test""" + """Request immediate stop of the test and clean up all test data""" if not self.test_running: return self.request_stop = True - self.test_running = False # This will break out of all test loops + self.test_running = False self.measuring = False # Immediately set device to safe state if hasattr(self, 'dev'): - self.dev.channels['A'].mode = pysmu.Mode.HI_Z - self.dev.channels['A'].constant(0) + try: + self.dev.channels['A'].mode = pysmu.Mode.HI_Z + self.dev.channels['A'].constant(0) + except Exception as e: + print(f"Error resetting device: {e}") - # Clear plot data + # Clear all data buffers self.time_data.clear() self.voltage_data.clear() self.current_data.clear() + self.phase_data.clear() + + # Reset test values + self.test_phase.set("Idle") + self.capacity_ah.set(0.0) + self.charge_capacity.set(0.0) + self.coulomb_efficiency.set(0.0) + + # Reset plot if it exists if hasattr(self, 'line_voltage') and hasattr(self, 'line_current'): self.line_voltage.set_data([], []) self.line_current.set_data([], []) - self.ax.set_xlim(0, 1) - self.ax2.set_xlim(0, 1) + # Reset to reasonable default ranges + self.ax.set_xlim(0, 10) # Small range instead of 0-1 + self.ax.set_ylim(0, 2) # Typical battery voltage range + self.ax2.set_ylim(-0.2, 0.2) # Typical current range self.canvas.draw() - self.status_var.set("Test stopped immediately") + # Update UI + self.status_var.set("Test stopped - Ready for new test") self.stop_button.config(state=tk.DISABLED) self.start_button.config(state=tk.NORMAL) - # Finalize test data + # Finalize test data (logs, etc.) self.safe_after(100, self.finalize_test) def center_window(self, window):