From 712bc1657198e026479ad920d70899de1b9692f5 Mon Sep 17 00:00:00 2001 From: awe Date: Tue, 9 Jun 2026 17:53:04 +0300 Subject: [PATCH] 1 sweep per plot --- rfg_vna_viewer.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/rfg_vna_viewer.py b/rfg_vna_viewer.py index d6bf931..3b0e698 100644 --- a/rfg_vna_viewer.py +++ b/rfg_vna_viewer.py @@ -9,6 +9,7 @@ normalization and plots amplitude, phase, and FFT in real time. import os import signal import sys +from collections import deque import numpy as np import pyqtgraph as pg @@ -154,7 +155,8 @@ class SweepAccumulator: # Keep only points present in both channels valid = np.isfinite(main_ch1) & np.isfinite(ref_ch1) - if valid.sum() < 2: + nvalid = int(valid.sum()) + if nvalid < MIN_SWEEP_POINTS: return None return { @@ -162,7 +164,7 @@ class SweepAccumulator: "main_ch2": main_ch2[valid], "ref_ch1": ref_ch1[valid], "ref_ch2": ref_ch2[valid], - "num_points": int(valid.sum()), + "num_points": nvalid, } @@ -285,21 +287,23 @@ def build_gui(): def make_update(reader, accumulator, curves): c_main_amp, c_ref_amp, c_norm_ch1, c_norm_ch2, c_norm_amp, c_ph, c_fft = curves state = {"ref_phase_first": None} + queue = deque(maxlen=64) def update(): + # Read and parse — push completed sweeps into queue data = reader.read_available() - if not data: - return + if data: + for sw in accumulator.feed(data): + queue.append(sw) - sweeps = accumulator.feed(data) - if not sweeps: + # Draw exactly one sweep per tick + if not queue: return - - sweep = sweeps[-1] # latest complete sweep + sweep = queue.popleft() n = sweep["num_points"] - print(f"[VNA] sweeps_in_batch={len(sweeps)} points={n} " - f"main_ch1_range=[{sweep['main_ch1'].min():.0f}..{sweep['main_ch1'].max():.0f}] " - f"ref_ch1_range=[{sweep['ref_ch1'].min():.0f}..{sweep['ref_ch1'].max():.0f}]") + print(f"[VNA] queue={len(queue)} points={n} " + f"main=[{sweep['main_ch1'].min():.0f}..{sweep['main_ch1'].max():.0f}] " + f"ref=[{sweep['ref_ch1'].min():.0f}..{sweep['ref_ch1'].max():.0f}]") if n < 2: return