From 0202163f0807ad7d2192bec554e5aac198dc1f71 Mon Sep 17 00:00:00 2001 From: Brendan Haines Date: Thu, 16 Jan 2025 21:50:35 -0700 Subject: [PATCH] gui working with real data --- charon_vna/gui.py | 27 ++++++++++++++++++++++++++- charon_vna/vna.py | 12 ++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/charon_vna/gui.py b/charon_vna/gui.py index a7c5d8c..8225e6a 100644 --- a/charon_vna/gui.py +++ b/charon_vna/gui.py @@ -162,7 +162,7 @@ class MainWindow(QMainWindow): self.config_path = None self._frequency = np.linspace(1e9, 2e9, 101) # TODO: read frequency from config - # self.device = Charon("ip:192.168.3.1", frequency=DEFAULT_CONFIG["frequency"]) + self.vna = Charon("ip:192.168.3.1", frequency=DEFAULT_CONFIG["frequency"]) mpl.use("QtAgg") @@ -194,6 +194,10 @@ class MainWindow(QMainWindow): action_set_power = QAction("&Power", self) menu_stimulus.addAction(action_set_power) # action_set_power.triggered.connect(self.set_power) + action_trigger = QAction("&Trigger", self) + action_trigger.triggered.connect(self.capture) + action_trigger.setShortcut("Ctrl+T") + menu_stimulus.addAction(action_trigger) menu_calibration = QMenu("&Calibration") menubar.addMenu(menu_calibration) @@ -215,6 +219,7 @@ class MainWindow(QMainWindow): # prog_sweep.setTextVisible(False) prog_sweep.setValue(50) window_layout.addWidget(prog_sweep) + self.prog_sweep = prog_sweep # window_widget.se plot_layout = QVBoxLayout() @@ -277,6 +282,26 @@ class MainWindow(QMainWindow): print(f"Loading config from {path}...") # TODO: load config + def capture(self) -> None: + def callback(done: int, total: int): + self.prog_sweep.setMaximum(total) + self.prog_sweep.setValue(done) + + s = self.vna.vna_capture(self._frequency, callback) + + data = xr.DataArray( + [[s]], + dims=["m", "n", "frequency"], + coords=dict( + frequency=s.coords["frequency"], + m=[1], + n=[1], + ), + ) + + for plot in self.plots: + plot.update_plot(data) + def generate_sim_data(self) -> None: coords = {"frequency": self._frequency, "m": [1], "n": [1]} shape = tuple(len(v) for v in coords.values()) diff --git a/charon_vna/vna.py b/charon_vna/vna.py index 82c8dc0..5cdfebe 100644 --- a/charon_vna/vna.py +++ b/charon_vna/vna.py @@ -1,7 +1,7 @@ # %% imports import copy from pathlib import Path -from typing import Any, Dict, Tuple +from typing import Any, Callable, Dict, Tuple import adi @@ -38,7 +38,7 @@ class Charon: def __init__( self, - uri: str, + uri: str = "192.168.2.1", frequency: npt.ArrayLike = np.linspace(1e9, 2e9, 3), ports: Tuple[int] = (1,), ): @@ -207,7 +207,7 @@ class Charon: s.loc[dict(frequency=frequency)] = self.get_b_over_a(frequency=frequency) return s - def vna_capture(self, frequency: npt.ArrayLike): + def vna_capture(self, frequency: npt.ArrayLike, callback: Callable[int, int] | None): s = xr.DataArray( np.empty(len(frequency), dtype=np.complex128), dims=["frequency"], @@ -215,7 +215,9 @@ class Charon: frequency=frequency, ), ) - for freq in s.frequency.data: + for ff, freq in enumerate(s.frequency.data): + if callback is not None: + callback(ff, len(s.frequency)) self.set_output(frequency=freq, power=-5) self.sdr.rx_destroy_buffer() self.sdr.rx_lo = int(freq) @@ -226,6 +228,8 @@ class Charon: self.sdr.rx_hardwaregain_chan1 = 40 rx = self.sdr.rx() s.loc[dict(frequency=freq)] = np.mean(rx[1] / rx[0]) + if callback is not None: + callback(len(s.frequency), len(s.frequency)) return s