MainCode/adalm1000_logger.py aktualisiert

Neue datei mit suffix per cycle
kurve wird nur während test gezeichnet
(D)
This commit is contained in:
Jan 2025-07-10 19:45:56 +02:00
parent 803c7086d4
commit bd76230e40

View File

@ -648,22 +648,26 @@ class BatteryTester(QMainWindow):
@pyqtSlot(float, float, float) @pyqtSlot(float, float, float)
def update_measurements(self, voltage, current, current_time): def update_measurements(self, voltage, current, current_time):
try: try:
# Nur Daten speichern, wenn der Test läuft
if not self.test_running:
return
with self.plot_mutex: with self.plot_mutex:
self.time_data.append(current_time) self.time_data.append(current_time)
self.voltage_data.append(voltage) self.voltage_data.append(voltage)
self.current_data.append(current) self.current_data.append(current)
# Update display labels (always) # Update display labels (immer)
self.voltage_label.setText(f"{voltage:.4f}") self.voltage_label.setText(f"{voltage:.4f}")
self.current_label.setText(f"{current:.4f}") self.current_label.setText(f"{current:.4f}")
self.time_label.setText(self.format_time(current_time)) self.time_label.setText(self.format_time(current_time))
# Throttle plot updates to 10Hz max # Plot-Updates drosseln (max. 10Hz)
now = time.time() now = time.time()
if not hasattr(self, '_last_plot_update'): if not hasattr(self, '_last_plot_update'):
self._last_plot_update = 0 self._last_plot_update = 0
if now - self._last_plot_update >= 0.1: # 100ms minimum between updates if now - self._last_plot_update >= 0.1: # 100ms minimum zwischen Updates
self._last_plot_update = now self._last_plot_update = now
QTimer.singleShot(0, self.update_plot) QTimer.singleShot(0, self.update_plot)
@ -753,10 +757,11 @@ class BatteryTester(QMainWindow):
raise ValueError("Current must be ≤200mA (0.2A) for ADALM1000") raise ValueError("Current must be ≤200mA (0.2A) for ADALM1000")
# Clear ALL previous data completely # Clear ALL previous data completely
self.time_data.clear() with self.plot_mutex:
self.voltage_data.clear() self.time_data.clear()
self.current_data.clear() self.voltage_data.clear()
self.phase_data.clear() self.current_data.clear()
self.phase_data.clear()
# Reset capacities and timing # Reset capacities and timing
self.start_time = time.time() self.start_time = time.time()
@ -773,11 +778,6 @@ class BatteryTester(QMainWindow):
self.measurement_thread.current_window.clear() self.measurement_thread.current_window.clear()
with self.measurement_thread.measurement_queue.mutex: with self.measurement_thread.measurement_queue.mutex:
self.measurement_thread.measurement_queue.queue.clear() self.measurement_thread.measurement_queue.queue.clear()
# Generate filename and create log file
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
self.base_filename = os.path.join(self.log_dir, f"battery_test_{timestamp}")
self.create_cycle_log_file()
# Reset plot completely # Reset plot completely
self.reset_plot() self.reset_plot()
@ -846,9 +846,17 @@ class BatteryTester(QMainWindow):
QMessageBox.critical(self, "Error", f"No write permissions in {self.log_dir}") QMessageBox.critical(self, "Error", f"No write permissions in {self.log_dir}")
return False return False
# Generate unique filename # Generate base filename on first cycle
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") if not hasattr(self, 'base_filename'):
self.filename = os.path.join(self.log_dir, f"battery_test_{timestamp}.csv") timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
self.base_filename = os.path.join(self.log_dir, f"battery_test_{timestamp}")
# Find next available cycle number
cycle_num = 1
while os.path.exists(f"{self.base_filename}_{cycle_num}.csv"):
cycle_num += 1
self.filename = f"{self.base_filename}_{cycle_num}.csv"
# Open new file # Open new file
try: try:
@ -858,10 +866,10 @@ class BatteryTester(QMainWindow):
test_current = self.c_rate * self.capacity test_current = self.c_rate * self.capacity
test_conditions = self.test_conditions_input.text() if hasattr(self, 'test_conditions_input') else "N/A" test_conditions = self.test_conditions_input.text() if hasattr(self, 'test_conditions_input') else "N/A"
self.current_cycle_file.write(f"# ADALM1000 Battery Test Log\n") self.current_cycle_file.write(f"# ADALM1000 Battery Test Log - Cycle {cycle_num}\n")
self.current_cycle_file.write(f"# Date: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n") self.current_cycle_file.write(f"# Date: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
self.current_cycle_file.write(f"# Battery Capacity: {self.capacity} Ah\n") self.current_cycle_file.write(f"# Battery Capacity: {self.capacity} Ah\n")
self.current_cycle_file.write(f"# Test Current: {test_current:.3f} A (C/{1/self.c_rate:.1f})\n") self.current_cycle_file.write(f"# Test Current: {test_current:.4f} A (C/{1/self.c_rate:.1f})\n")
self.current_cycle_file.write(f"# Charge Cutoff: {self.charge_cutoff} V\n") self.current_cycle_file.write(f"# Charge Cutoff: {self.charge_cutoff} V\n")
self.current_cycle_file.write(f"# Discharge Cutoff: {self.discharge_cutoff} V\n") self.current_cycle_file.write(f"# Discharge Cutoff: {self.discharge_cutoff} V\n")
self.current_cycle_file.write(f"# Rest Time: {self.rest_time} hours\n") self.current_cycle_file.write(f"# Rest Time: {self.rest_time} hours\n")
@ -1011,7 +1019,7 @@ class BatteryTester(QMainWindow):
self.current_cycle_file.write("\n# TEST SUMMARY\n") self.current_cycle_file.write("\n# TEST SUMMARY\n")
self.current_cycle_file.write(f"# Test Parameters:\n") self.current_cycle_file.write(f"# Test Parameters:\n")
self.current_cycle_file.write(f"# - Battery Capacity: {self.capacity} Ah\n") self.current_cycle_file.write(f"# - Battery Capacity: {self.capacity} Ah\n")
self.current_cycle_file.write(f"# - Test Current: {test_current:.3f} A (C/{1/self.c_rate:.1f})\n") self.current_cycle_file.write(f"# - Test Current: {test_current:.4f} A (C/{1/self.c_rate:.1f})\n")
self.current_cycle_file.write(f"# - Charge Cutoff: {self.charge_cutoff} V\n") self.current_cycle_file.write(f"# - Charge Cutoff: {self.charge_cutoff} V\n")
self.current_cycle_file.write(f"# - Discharge Cutoff: {self.discharge_cutoff} V\n") self.current_cycle_file.write(f"# - Discharge Cutoff: {self.discharge_cutoff} V\n")
self.current_cycle_file.write(f"# - Test Conditions: {test_conditions}\n") self.current_cycle_file.write(f"# - Test Conditions: {test_conditions}\n")