fix
This commit is contained in:
parent
72df5f7691
commit
e2b8a4afcb
@ -1,4 +1,5 @@
|
|||||||
import os, sys, time, csv, statistics, threading, queue
|
import os, sys, time, csv, statistics, threading, queue
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
scriptDir = os.path.dirname(os.path.realpath(__file__))
|
scriptDir = os.path.dirname(os.path.realpath(__file__))
|
||||||
DEFAULT_OUTDIR = os.path.join(scriptDir, "logs")
|
DEFAULT_OUTDIR = os.path.join(scriptDir, "logs")
|
||||||
@ -41,10 +42,10 @@ class DeviceWorker:
|
|||||||
def _reader_loop(self):
|
def _reader_loop(self):
|
||||||
print(f"[{self.serial}] Reader gestartet (interval={self.interval}, n={self.filter_window_size})")
|
print(f"[{self.serial}] Reader gestartet (interval={self.interval}, n={self.filter_window_size})")
|
||||||
filter_window_size = 10
|
filter_window_size = 10
|
||||||
interval = 0.1
|
interval = self.interval
|
||||||
last_log = 0.0
|
last_log = -999.0
|
||||||
current_direction = 1 # falls du das brauchst wie im Single-Logger
|
current_direction = 1 # falls du das brauchst wie im Single-Logger
|
||||||
last_log = 0.0
|
|
||||||
while not self._stop_evt.is_set():
|
while not self._stop_evt.is_set():
|
||||||
if not self._running:
|
if not self._running:
|
||||||
time.sleep(0.05); continue
|
time.sleep(0.05); continue
|
||||||
@ -57,12 +58,14 @@ class DeviceWorker:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# WICHTIG: gleiche Indizes wie in deinem Logger!
|
# WICHTIG: gleiche Indizes wie in deinem Logger!
|
||||||
raw_voltage = float(np.mean([s[1][0] for s in samples])) # VB
|
vb = float(np.mean([s[1][0] for s in samples])) # Spannung B
|
||||||
raw_current = float(np.mean([s[0][1] for s in samples])) * current_direction # IA
|
ia = float(np.mean([s[0][1] for s in samples]))
|
||||||
|
|
||||||
|
print(f"[{self.serial}] got {len(samples)} samples; vb={vb:.3f}, ia={ia:.3f}")
|
||||||
|
|
||||||
now = time.time()
|
now = time.time()
|
||||||
if now - last_log >= 1.0: # 1 Hz loggen
|
if now - last_log >= 1.0: # 1 Hz loggen
|
||||||
self._writer_q.put((now, raw_voltage, raw_current))
|
self._writer_q.put((now, vb, ia))
|
||||||
last_log = now
|
last_log = now
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -81,18 +84,18 @@ class DeviceWorker:
|
|||||||
self._log_path = os.path.join(self.outdir, f"{time.strftime('%Y%m%d_%H%M%S')}_{self.serial}.csv")
|
self._log_path = os.path.join(self.outdir, f"{time.strftime('%Y%m%d_%H%M%S')}_{self.serial}.csv")
|
||||||
print(f"[{self.serial}] Writer startet → {self._log_path}")
|
print(f"[{self.serial}] Writer startet → {self._log_path}")
|
||||||
|
|
||||||
try:
|
written = 0
|
||||||
with open(self._log_path, "w", newline="") as f:
|
with open(self._log_path, "w", newline="") as f:
|
||||||
w = csv.writer(f)
|
w = csv.writer(f)
|
||||||
w.writerow(["timestamp", "A", "B"]) # Datei wird JETZT angelegt
|
w.writerow(["timestamp", "VB", "IA"]) # Datei JETZT sichtbar
|
||||||
while not (self._stop_evt.is_set() and self._writer_q.empty()):
|
while not (self._stop_evt.is_set() and self._writer_q.empty()):
|
||||||
try:
|
try:
|
||||||
ts, vA, vB = self._writer_q.get(timeout=0.5)
|
ts, vb, ia = self._writer_q.get(timeout=0.5)
|
||||||
except queue.Empty:
|
except queue.Empty:
|
||||||
continue
|
continue
|
||||||
w.writerow([ts, vA, vB])
|
w.writerow([ts, vb, ia])
|
||||||
|
written += 1
|
||||||
|
if written % 5 == 0:
|
||||||
f.flush()
|
f.flush()
|
||||||
except Exception as e:
|
print(f"[{self.serial}] rows written: {written}")
|
||||||
print(f"[{self.serial}] Writer-Fehler ({self._log_path}): {e}")
|
print(f"[{self.serial}] Writer beendet: {self._log_path}")
|
||||||
finally:
|
|
||||||
print(f"[{self.serial}] Writer beendet: {self._log_path}")
|
|
||||||
Loading…
x
Reference in New Issue
Block a user