gui working with real data
All checks were successful
Publish Python 🐍 distribution 📦 to PyPI and TestPyPI / Build distribution 📦 (push) Successful in 17s
Publish Python 🐍 distribution 📦 to PyPI and TestPyPI / Publish Python 🐍 distribution 📦 to PyPI (push) Has been skipped

This commit is contained in:
Brendan Haines 2025-01-16 21:50:35 -07:00
parent 18a1b2faa3
commit 0202163f08
2 changed files with 34 additions and 5 deletions

View File

@ -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())

View File

@ -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