added k209 driver
This commit is contained in:
@@ -0,0 +1,261 @@
|
||||
"""VISA HiSLIP driver for Compact-M K209 / S2VNA analyzers."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
import numpy as np
|
||||
import pyvisa
|
||||
|
||||
from python_app.hardware_full.librevna_driver.models import SweepResult
|
||||
from python_app.models.run_config_model import RadarSweepModel
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class CompactMK209InterleavedSweep:
|
||||
"""Raw corrected K209 traces as interleaved REAL32 arrays."""
|
||||
|
||||
frequency_hz: np.ndarray
|
||||
s11_values: np.ndarray
|
||||
s21_values: np.ndarray
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class CompactMK209Service:
|
||||
"""Acquire corrected S11/S21 sweeps from a K209 analyzer through VISA HiSLIP."""
|
||||
|
||||
resource: str
|
||||
timeout_ms: int = 20_000
|
||||
preset_on_open: bool = True
|
||||
visa_library: str = "@ivi"
|
||||
_resource_manager: pyvisa.ResourceManager | None = field(init=False, default=None, repr=False)
|
||||
_instrument: Any | None = field(init=False, default=None, repr=False)
|
||||
_settings: RadarSweepModel | None = field(init=False, default=None, repr=False)
|
||||
_frequency_hz: np.ndarray | None = field(init=False, default=None, repr=False)
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
"""Normalize constructor values."""
|
||||
self.resource = str(self.resource).strip()
|
||||
if not self.resource:
|
||||
raise ValueError("K209 VISA resource must not be empty")
|
||||
self.timeout_ms = int(self.timeout_ms)
|
||||
if self.timeout_ms <= 0:
|
||||
raise ValueError("K209 timeout_ms must be > 0")
|
||||
self.visa_library = str(self.visa_library).strip() or "@ivi"
|
||||
if self.visa_library == "@py" or self.visa_library.endswith("@py"):
|
||||
raise ValueError("K209 requires an IVI/Vendor VISA backend, not pyvisa-py")
|
||||
|
||||
@property
|
||||
def is_open(self) -> bool:
|
||||
"""Return whether the VISA session is open."""
|
||||
return self._instrument is not None
|
||||
|
||||
def open(self) -> None:
|
||||
"""Open VISA resource and apply stored sweep settings when available."""
|
||||
if self._instrument is not None:
|
||||
return
|
||||
|
||||
try:
|
||||
self._resource_manager = pyvisa.ResourceManager(self.visa_library)
|
||||
self._instrument = self._resource_manager.open_resource(self.resource)
|
||||
self._instrument.timeout = self.timeout_ms
|
||||
self._instrument.write_termination = "\n"
|
||||
self._instrument.read_termination = None
|
||||
self._instrument.chunk_size = max(int(getattr(self._instrument, "chunk_size", 20_480)), 8 * 1024 * 1024)
|
||||
self._instrument.write("*CLS")
|
||||
|
||||
if self._settings is not None:
|
||||
self._apply_configuration(self._settings)
|
||||
except Exception:
|
||||
self.close()
|
||||
raise
|
||||
|
||||
def close(self) -> None:
|
||||
"""Close VISA sessions."""
|
||||
if self._instrument is not None:
|
||||
self._instrument.close()
|
||||
self._instrument = None
|
||||
if self._resource_manager is not None:
|
||||
self._resource_manager.close()
|
||||
self._resource_manager = None
|
||||
|
||||
def __enter__(self) -> CompactMK209Service:
|
||||
"""Open and return this service."""
|
||||
self.open()
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type: object, exc: object, traceback: object) -> None:
|
||||
"""Close VISA resources."""
|
||||
self.close()
|
||||
|
||||
def query_identity(self) -> str:
|
||||
"""Read analyzer identity string."""
|
||||
instrument = self._require_instrument()
|
||||
return str(instrument.query("*IDN?")).strip()
|
||||
|
||||
def query_system_error(self) -> str:
|
||||
"""Read one analyzer SCPI error queue entry."""
|
||||
instrument = self._require_instrument()
|
||||
return str(instrument.query("SYST:ERR?")).strip()
|
||||
|
||||
def configure(self, sweep: RadarSweepModel) -> None:
|
||||
"""Store and apply sweep settings."""
|
||||
self._validate_sweep(sweep)
|
||||
self._settings = sweep
|
||||
self._frequency_hz = None
|
||||
if self._instrument is None:
|
||||
return
|
||||
self._apply_configuration(sweep)
|
||||
|
||||
def read_device_limits(self) -> dict[str, float | int]:
|
||||
"""Read analyzer limits through SCPI capability/service queries."""
|
||||
instrument = self._require_instrument()
|
||||
return {
|
||||
"min_frequency_hz": float(instrument.query("SERV:SWE:FREQ:MIN?")),
|
||||
"max_frequency_hz": float(instrument.query("SERV:SWE:FREQ:MAX?")),
|
||||
"min_ifbw_hz": float(instrument.query("SYST:CAP:IFBW:MIN?")),
|
||||
"max_ifbw_hz": float(instrument.query("SYST:CAP:IFBW:MAX?")),
|
||||
"max_points": int(float(instrument.query("SERV:SWE:POIN?"))),
|
||||
"min_power_dbm": float(instrument.query("SERV:SWE:POW:MIN?")),
|
||||
"max_power_dbm": float(instrument.query("SERV:SWE:POW:MAX?")),
|
||||
}
|
||||
|
||||
def acquire_interleaved(self) -> CompactMK209InterleavedSweep:
|
||||
"""Acquire one corrected sweep without converting interleaved arrays."""
|
||||
if self._settings is None:
|
||||
raise RuntimeError("K209 service is not configured")
|
||||
if self._frequency_hz is None:
|
||||
raise RuntimeError("K209 frequency axis is not configured")
|
||||
points = int(self._settings.points)
|
||||
|
||||
s11_values, s21_values = self._query_sweep_trace_pair(points)
|
||||
return CompactMK209InterleavedSweep(
|
||||
frequency_hz=self._frequency_hz,
|
||||
s11_values=s11_values,
|
||||
s21_values=s21_values,
|
||||
)
|
||||
|
||||
def acquire(self) -> SweepResult:
|
||||
"""Acquire one corrected S11/S21 sweep."""
|
||||
raw = self.acquire_interleaved()
|
||||
|
||||
return SweepResult(
|
||||
x=raw.frequency_hz.copy(),
|
||||
traces={
|
||||
"s11": self._complex_from_interleaved(raw.s11_values),
|
||||
"s21": self._complex_from_interleaved(raw.s21_values),
|
||||
},
|
||||
)
|
||||
|
||||
def _apply_configuration(self, sweep: RadarSweepModel) -> None:
|
||||
instrument = self._require_instrument()
|
||||
if self.preset_on_open:
|
||||
instrument.write("SYST:PRES")
|
||||
self._expect_opc("*OPC?", context="K209 preset")
|
||||
|
||||
instrument.write(f"SENS:FREQ:STAR {float(sweep.start_hz):.9f}")
|
||||
instrument.write(f"SENS:FREQ:STOP {float(sweep.stop_hz):.9f}")
|
||||
instrument.write(f"SENS:SWE:POIN {int(sweep.points)}")
|
||||
instrument.write("SENS:SWE:POIN:TIME 0")
|
||||
instrument.write(f"SENS:BAND {float(sweep.if_bandwidth_hz):.9f}")
|
||||
instrument.write(f"SOUR:POW {float(sweep.power_dbm):.3f}")
|
||||
instrument.write("SENS:AVER OFF")
|
||||
instrument.write("CALC:PAR1:DEF S21")
|
||||
instrument.write("CALC:PAR1:SEL")
|
||||
instrument.write("FORM:DATA REAL32")
|
||||
instrument.write("FORM:BORD SWAP")
|
||||
instrument.write("INIT:CONT ON")
|
||||
instrument.write("TRIG:SOUR BUS")
|
||||
self._expect_opc("*OPC?", context="K209 setup")
|
||||
self._frequency_hz = self._query_float32_array("SENS:FREQ:DATA?", int(sweep.points))
|
||||
|
||||
def _expect_opc(self, command: str, *, context: str) -> None:
|
||||
instrument = self._require_instrument()
|
||||
response = str(instrument.query(command)).strip()
|
||||
if response != "1":
|
||||
raise RuntimeError(f"{context} returned unexpected *OPC? response: {response!r}")
|
||||
|
||||
def _query_float32_array(self, command: str, expected_values: int) -> np.ndarray:
|
||||
instrument = self._require_instrument()
|
||||
instrument.write(command)
|
||||
return self._read_float32_block(command, expected_values)
|
||||
|
||||
def _query_sweep_trace_pair(self, points: int) -> tuple[np.ndarray, np.ndarray]:
|
||||
instrument = self._require_instrument()
|
||||
instrument.write("TRIG:SING;*OPC?;:SENS:DATA:CORR? S11;:SENS:DATA:CORR? S21")
|
||||
response = self._read_ascii_token()
|
||||
if response != "1":
|
||||
raise RuntimeError(f"K209 sweep returned unexpected *OPC? response: {response!r}")
|
||||
return (
|
||||
self._read_float32_block("SENS:DATA:CORR? S11", points * 2),
|
||||
self._read_float32_block("SENS:DATA:CORR? S21", points * 2),
|
||||
)
|
||||
|
||||
def _read_ascii_token(self) -> str:
|
||||
token = bytearray()
|
||||
while True:
|
||||
byte = self._read_response_bytes(1)
|
||||
if byte in (b";", b"\n", b"\r"):
|
||||
if token:
|
||||
return token.decode("ascii").strip()
|
||||
continue
|
||||
token.extend(byte)
|
||||
if len(token) > 64 * 1024:
|
||||
raise RuntimeError("K209 ASCII response token is too long")
|
||||
|
||||
def _read_float32_block(self, context: str, expected_values: int) -> np.ndarray:
|
||||
marker = self._read_response_bytes(1)
|
||||
while marker in (b";", b"\n", b"\r"):
|
||||
marker = self._read_response_bytes(1)
|
||||
if marker != b"#":
|
||||
raise RuntimeError(f"K209 response for {context!r} does not start with IEEE block marker")
|
||||
|
||||
width = self._read_response_bytes(1)
|
||||
if width != b"8":
|
||||
raise RuntimeError(f"K209 response for {context!r} uses unsupported IEEE block header width")
|
||||
|
||||
payload_size = int(self._read_response_bytes(8).decode("ascii"))
|
||||
expected_size = expected_values * np.dtype(np.float32).itemsize
|
||||
if payload_size != expected_size:
|
||||
raise RuntimeError(
|
||||
f"K209 response for {context!r} returned {payload_size} payload bytes, "
|
||||
f"expected {expected_size}"
|
||||
)
|
||||
|
||||
payload = self._read_response_bytes(payload_size)
|
||||
array = np.frombuffer(payload, dtype="<f4")
|
||||
if array.size != expected_values:
|
||||
raise RuntimeError(
|
||||
f"K209 response for {context!r} returned {array.size} float32 values, "
|
||||
f"expected {expected_values}"
|
||||
)
|
||||
return array
|
||||
|
||||
def _read_response_bytes(self, count: int) -> bytes:
|
||||
instrument = self._require_instrument()
|
||||
data = instrument.read_bytes(count, break_on_termchar=False)
|
||||
if len(data) != count:
|
||||
raise RuntimeError(f"K209 response ended after {len(data)} bytes, expected {count}")
|
||||
return data
|
||||
|
||||
def _require_instrument(self) -> Any:
|
||||
if self._instrument is None:
|
||||
raise RuntimeError("K209 VISA instrument is not open")
|
||||
return self._instrument
|
||||
|
||||
@staticmethod
|
||||
def _validate_sweep(sweep: RadarSweepModel) -> None:
|
||||
if int(sweep.points) < 2:
|
||||
raise ValueError("K209 sweep points must be >= 2")
|
||||
if float(sweep.stop_hz) < float(sweep.start_hz):
|
||||
raise ValueError("K209 sweep stop_hz must be >= start_hz")
|
||||
if float(sweep.if_bandwidth_hz) <= 0.0:
|
||||
raise ValueError("K209 IF bandwidth must be > 0")
|
||||
|
||||
@staticmethod
|
||||
def _complex_from_interleaved(values: np.ndarray) -> np.ndarray:
|
||||
if values.size % 2 != 0:
|
||||
raise RuntimeError("K209 complex trace payload has odd scalar count")
|
||||
reshaped = np.asarray(values, dtype=np.float32).reshape((-1, 2))
|
||||
return (reshaped[:, 0] + 1j * reshaped[:, 1]).astype(np.complex64)
|
||||
@@ -202,6 +202,7 @@ class RunConfigModel:
|
||||
|
||||
LIBREVNA_MODEL = "librevna"
|
||||
LIBREVNA_MULTI_MODEL = "librevna_multi"
|
||||
COMPACT_M_K209_MODEL = "compact_m_k209"
|
||||
MULTI_DEVICE_INPUT_POSITIONS = 4
|
||||
MULTI_DEVICE_OUTPUT_POSITIONS = 2
|
||||
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
"""Standalone smoke test for Compact-M K209 VISA HiSLIP acquisition."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
|
||||
import numpy as np
|
||||
|
||||
from python_app.hardware_full.compact_m_k209_service import CompactMK209Service
|
||||
from python_app.models.run_config_model import RadarSweepModel
|
||||
|
||||
|
||||
def _parse_args() -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(description="Acquire one K209 sweep through VISA HiSLIP")
|
||||
parser.add_argument(
|
||||
"--resource",
|
||||
required=True,
|
||||
help=(
|
||||
"S2VNA VISA resource, e.g. TCPIP0::127.0.0.1::hislip0,4880::INSTR "
|
||||
"when the USB-connected K209 is controlled by local S2VNA"
|
||||
),
|
||||
)
|
||||
parser.add_argument("--start-hz", type=float, default=1_000_000.0)
|
||||
parser.add_argument("--stop-hz", type=float, default=6_000_000_000.0)
|
||||
parser.add_argument("--points", type=int, default=201)
|
||||
parser.add_argument("--ifbw-hz", type=float, default=50_000.0)
|
||||
parser.add_argument("--power-dbm", type=float, default=-10.0)
|
||||
parser.add_argument("--timeout-ms", type=int, default=20_000)
|
||||
parser.add_argument("--no-preset", action="store_true")
|
||||
parser.add_argument(
|
||||
"--visa-library",
|
||||
default="@ivi",
|
||||
help="PyVISA IVI backend specification, e.g. @ivi or /usr/lib/x86_64-linux-gnu/libvisa.so",
|
||||
)
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def _validate_result(result, expected_points: int) -> None:
|
||||
if result.x.shape != (expected_points,):
|
||||
raise RuntimeError(f"Unexpected frequency shape: {result.x.shape}")
|
||||
s11 = result.trace("s11")
|
||||
s21 = result.trace("s21")
|
||||
if s11.shape != (expected_points,) or s21.shape != (expected_points,):
|
||||
raise RuntimeError(f"Unexpected trace shapes: s11={s11.shape}, s21={s21.shape}")
|
||||
if not np.all(np.isfinite(result.x)):
|
||||
raise RuntimeError("Frequency axis contains non-finite values")
|
||||
if np.any(np.diff(result.x) < 0.0):
|
||||
raise RuntimeError("Frequency axis is not monotonic")
|
||||
if not np.all(np.isfinite(s11.real)) or not np.all(np.isfinite(s11.imag)):
|
||||
raise RuntimeError("S11 contains non-finite values")
|
||||
if not np.all(np.isfinite(s21.real)) or not np.all(np.isfinite(s21.imag)):
|
||||
raise RuntimeError("S21 contains non-finite values")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
args = _parse_args()
|
||||
sweep = RadarSweepModel(
|
||||
start_hz=args.start_hz,
|
||||
stop_hz=args.stop_hz,
|
||||
points=args.points,
|
||||
if_bandwidth_hz=args.ifbw_hz,
|
||||
power_dbm=args.power_dbm,
|
||||
)
|
||||
|
||||
service = CompactMK209Service(
|
||||
resource=args.resource,
|
||||
timeout_ms=args.timeout_ms,
|
||||
preset_on_open=not args.no_preset,
|
||||
visa_library=args.visa_library,
|
||||
)
|
||||
try:
|
||||
service.open()
|
||||
print(f"K209 IDN: {service.query_identity()}")
|
||||
service.configure(sweep)
|
||||
result = service.acquire()
|
||||
_validate_result(result, args.points)
|
||||
system_error = service.query_system_error()
|
||||
if not system_error.startswith("0,"):
|
||||
raise RuntimeError(f"K209 SCPI error after sweep: {system_error}")
|
||||
print(
|
||||
"K209 sweep OK: "
|
||||
f"points={result.x.size}, first_hz={result.x[0]:.3f}, last_hz={result.x[-1]:.3f}, "
|
||||
f"mean_abs_s11={np.mean(np.abs(result.trace('s11'))):.6g}, "
|
||||
f"mean_abs_s21={np.mean(np.abs(result.trace('s21'))):.6g}"
|
||||
)
|
||||
finally:
|
||||
service.close()
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,206 @@
|
||||
"""Measure Compact-M K209 sweep acquisition throughput through VISA HiSLIP."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
import statistics
|
||||
import time
|
||||
|
||||
import numpy as np
|
||||
|
||||
from python_app.hardware_full.compact_m_k209_service import CompactMK209Service
|
||||
from python_app.models.run_config_model import RadarSweepModel
|
||||
|
||||
|
||||
RESOURCE = "TCPIP0::127.0.0.1::hislip0,4880::INSTR"
|
||||
VISA_LIBRARY = "@ivi"
|
||||
|
||||
START_HZ = 100_000_000.0
|
||||
STOP_HZ = 6_000_000_000.0
|
||||
POINTS = 1501
|
||||
IFBW_HZ = 10_000.0
|
||||
POWER_DBM = -20.0
|
||||
|
||||
TIMEOUT_MS = 20_000
|
||||
WARMUP_SWEEPS = 3
|
||||
TIMED_SWEEPS = 20
|
||||
PRESET_ON_OPEN = False
|
||||
|
||||
# False measures the device/transport hot path: one synchronized TRIG:SING/*OPC?
|
||||
# message plus S11/S21 REAL32 reads.
|
||||
# True also includes public SweepResult construction and complex array conversion.
|
||||
INCLUDE_RESULT_CONVERSION = False
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class BenchmarkResult:
|
||||
"""Timing summary for repeated sweep acquisition."""
|
||||
|
||||
durations_s: list[float]
|
||||
points: int
|
||||
|
||||
@property
|
||||
def total_s(self) -> float:
|
||||
"""Return total timed acquisition duration."""
|
||||
return sum(self.durations_s)
|
||||
|
||||
@property
|
||||
def sweeps_per_s(self) -> float:
|
||||
"""Return completed sweeps per second."""
|
||||
return len(self.durations_s) / self.total_s
|
||||
|
||||
@property
|
||||
def points_per_s(self) -> float:
|
||||
"""Return measured sweep points per second."""
|
||||
return (len(self.durations_s) * self.points) / self.total_s
|
||||
|
||||
@property
|
||||
def binary_payload_mb_per_s(self) -> float:
|
||||
"""Return S11+S21 binary payload throughput, excluding SCPI headers."""
|
||||
payload_bytes = len(self.durations_s) * self.points * 2 * 2 * np.dtype(np.float32).itemsize
|
||||
return payload_bytes / self.total_s / 1_000_000.0
|
||||
|
||||
|
||||
def _validate_config() -> None:
|
||||
if POINTS < 2:
|
||||
raise ValueError("POINTS must be >= 2")
|
||||
if WARMUP_SWEEPS < 0:
|
||||
raise ValueError("WARMUP_SWEEPS must be >= 0")
|
||||
if TIMED_SWEEPS <= 0:
|
||||
raise ValueError("TIMED_SWEEPS must be > 0")
|
||||
if IFBW_HZ <= 0.0:
|
||||
raise ValueError("IFBW_HZ must be > 0")
|
||||
if STOP_HZ < START_HZ:
|
||||
raise ValueError("STOP_HZ must be >= START_HZ")
|
||||
if TIMEOUT_MS <= 0:
|
||||
raise ValueError("TIMEOUT_MS must be > 0")
|
||||
|
||||
|
||||
def _validate_interleaved(raw, expected_points: int) -> None:
|
||||
if raw.frequency_hz.shape != (expected_points,):
|
||||
raise RuntimeError(f"Unexpected frequency shape: {raw.frequency_hz.shape}")
|
||||
if raw.s11_values.shape != (expected_points * 2,):
|
||||
raise RuntimeError(f"Unexpected S11 shape: {raw.s11_values.shape}")
|
||||
if raw.s21_values.shape != (expected_points * 2,):
|
||||
raise RuntimeError(f"Unexpected S21 shape: {raw.s21_values.shape}")
|
||||
if not np.all(np.isfinite(raw.frequency_hz)):
|
||||
raise RuntimeError("Frequency axis contains non-finite values")
|
||||
if np.any(np.diff(raw.frequency_hz) < 0.0):
|
||||
raise RuntimeError("Frequency axis is not monotonic")
|
||||
if not np.all(np.isfinite(raw.s11_values)):
|
||||
raise RuntimeError("S11 contains non-finite values")
|
||||
if not np.all(np.isfinite(raw.s21_values)):
|
||||
raise RuntimeError("S21 contains non-finite values")
|
||||
|
||||
|
||||
def _validate_result(result, expected_points: int) -> None:
|
||||
if result.x.shape != (expected_points,):
|
||||
raise RuntimeError(f"Unexpected frequency shape: {result.x.shape}")
|
||||
for name in ("s11", "s21"):
|
||||
values = result.trace(name)
|
||||
if values.shape != (expected_points,):
|
||||
raise RuntimeError(f"Unexpected {name.upper()} shape: {values.shape}")
|
||||
if not np.all(np.isfinite(values.real)) or not np.all(np.isfinite(values.imag)):
|
||||
raise RuntimeError(f"{name.upper()} contains non-finite values")
|
||||
|
||||
|
||||
def _percentile(values: list[float], percentile: float) -> float:
|
||||
sorted_values = sorted(values)
|
||||
index = round((len(sorted_values) - 1) * percentile)
|
||||
return sorted_values[index]
|
||||
|
||||
|
||||
def _run_benchmark(service: CompactMK209Service, *, points: int, warmup: int, sweeps: int, convert: bool) -> BenchmarkResult:
|
||||
acquire = service.acquire if convert else service.acquire_interleaved
|
||||
|
||||
first = acquire()
|
||||
if convert:
|
||||
_validate_result(first, points)
|
||||
else:
|
||||
_validate_interleaved(first, points)
|
||||
|
||||
for _ in range(warmup):
|
||||
acquire()
|
||||
|
||||
durations_s: list[float] = []
|
||||
for _ in range(sweeps):
|
||||
start_ns = time.perf_counter_ns()
|
||||
last = acquire()
|
||||
end_ns = time.perf_counter_ns()
|
||||
durations_s.append((end_ns - start_ns) / 1_000_000_000.0)
|
||||
|
||||
if convert:
|
||||
_validate_result(last, points)
|
||||
else:
|
||||
_validate_interleaved(last, points)
|
||||
return BenchmarkResult(durations_s=durations_s, points=points)
|
||||
|
||||
|
||||
def _print_limits(limits: dict[str, float | int]) -> None:
|
||||
print(
|
||||
"K209 limits: "
|
||||
f"frequency={limits['min_frequency_hz']:.0f}..{limits['max_frequency_hz']:.0f} Hz, "
|
||||
f"IFBW={limits['min_ifbw_hz']:.0f}..{limits['max_ifbw_hz']:.0f} Hz, "
|
||||
f"power={limits['min_power_dbm']:.1f}..{limits['max_power_dbm']:.1f} dBm, "
|
||||
f"max_points={limits['max_points']}"
|
||||
)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
_validate_config()
|
||||
|
||||
sweep = RadarSweepModel(
|
||||
start_hz=START_HZ,
|
||||
stop_hz=STOP_HZ,
|
||||
points=POINTS,
|
||||
if_bandwidth_hz=IFBW_HZ,
|
||||
power_dbm=POWER_DBM,
|
||||
)
|
||||
service = CompactMK209Service(
|
||||
resource=RESOURCE,
|
||||
timeout_ms=TIMEOUT_MS,
|
||||
preset_on_open=PRESET_ON_OPEN,
|
||||
visa_library=VISA_LIBRARY,
|
||||
)
|
||||
|
||||
try:
|
||||
service.open()
|
||||
print(f"K209 IDN: {service.query_identity()}")
|
||||
_print_limits(service.read_device_limits())
|
||||
service.configure(sweep)
|
||||
print(
|
||||
"Benchmark settings: "
|
||||
f"start_hz={START_HZ:.3f}, stop_hz={STOP_HZ:.3f}, "
|
||||
f"points={POINTS}, ifbw_hz={IFBW_HZ:.3f}, power_dbm={POWER_DBM:.3f}, "
|
||||
f"warmup={WARMUP_SWEEPS}, sweeps={TIMED_SWEEPS}, "
|
||||
f"mode={'SweepResult' if INCLUDE_RESULT_CONVERSION else 'raw interleaved REAL32'}"
|
||||
)
|
||||
result = _run_benchmark(
|
||||
service,
|
||||
points=POINTS,
|
||||
warmup=WARMUP_SWEEPS,
|
||||
sweeps=TIMED_SWEEPS,
|
||||
convert=INCLUDE_RESULT_CONVERSION,
|
||||
)
|
||||
system_error = service.query_system_error()
|
||||
if not system_error.startswith("0,"):
|
||||
raise RuntimeError(f"K209 SCPI error after benchmark: {system_error}")
|
||||
finally:
|
||||
service.close()
|
||||
|
||||
durations_ms = [value * 1_000.0 for value in result.durations_s]
|
||||
print("Benchmark result:")
|
||||
print(f" total_s={result.total_s:.6f}")
|
||||
print(f" sweep_mean_ms={statistics.fmean(durations_ms):.3f}")
|
||||
print(f" sweep_median_ms={statistics.median(durations_ms):.3f}")
|
||||
print(f" sweep_min_ms={min(durations_ms):.3f}")
|
||||
print(f" sweep_max_ms={max(durations_ms):.3f}")
|
||||
print(f" sweep_p95_ms={_percentile(durations_ms, 0.95):.3f}")
|
||||
print(f" sweeps_per_s={result.sweeps_per_s:.3f}")
|
||||
print(f" points_per_s={result.points_per_s:.1f}")
|
||||
print(f" s11_s21_payload_mb_per_s={result.binary_payload_mb_per_s:.3f}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user