```展示 HN:Instrumation,一个用于仪器的 PyPI 库```
Show HN: Instrumation a PYPI library for Instruments

原始链接: https://github.com/abduznik/instrumation

**Instrumation** 是一款高层级的硬件抽象层(HAL),旨在简化射频(RF)测试平台的自动化流程。它通过提供统一且具备类型感知能力的 API,兼容各大主流仪器品牌(如 Keysight、Rigol、Tektronix 等),从而消除了处理 PyVISA 样板代码、各种 SCPI 方言以及硬编码地址所带来的困扰。 **主要特性包括:** * **统一 API:** 使用直观且经过验证的方法替代原始 SCPI 字符串。 * **数字孪生模式:** 支持离线模拟仪器,无需物理硬件即可进行代码开发与调试。 * **自动发现:** 自动检测并配置已连接的 USB/LAN 仪器。 * **工作站管理:** 通过 `station.toml` 配置文件管理复杂的测试设置。 * **数据广播:** 内置 UDP 支持,适用于实时仪表盘展示与日志记录。 * **集成化报告:** 可配合 `instrumation-report` 生成结构化的 HTML、Excel 或 PDF 报告,并进行通过/失败评估。 通过抽象化各厂商的特殊差异并自动化连接逻辑,Instrumation 使工程师能够专注于测试逻辑,而非底层的代码实现。它支持 Windows、Linux 和 macOS,为传统的手动 VISA 编程提供了一种简洁、专业的替代方案。

抱歉。
相关文章

原文

All projects made with passion 💙

Sponsor me

PyPI version License Python Versions Stars Downloads

Example

A high-level Hardware Abstraction Layer (HAL) for RF test stations. Stop wrestling with PyVISA boilerplate — write test logic, not connection code.


RF test bench automation is painful. Every instrument brand has its own quirks, SCPI dialects vary, and testing your scripts requires physical hardware on your desk. Instrumation fixes all three:

  • One API for everything — same code works on Keysight, Rigol, and any other supported brand
  • Digital Twin mode — develop and debug offline with simulated instruments that emit realistic Gaussian noise
  • Smart auto-detection — scans connected devices and loads the right driver automatically, no manual config

Instrumation has been validated against real lab hardware. See our experiment reports:


PyVISA vs Instrumation: See the Difference

Programming a signal generator the traditional way vs. with Instrumation:

Aspect PyVISA (raw SCPI) Instrumation
Discovery Manual — find the resource string, manage ResourceManager Auto — just pass "AUTO" and the HAL scans USB + LAN for you
Connection rm.open_resource("TCPIP0::192.168.1.100::...") — hardcoded address connect_instrument("AUTO", "SG") — type-aware routing
Configuration sg.write(":FREQ:CW 2.4e9") — raw SCPI strings, no validation sg.set_frequency(2.4e9) — typed method with bounds checking
Cleanup Manual sg.close() — easy to forget Context manager — automatic with block cleanup
Offline Dev Requires real hardware connected Digital Twin — set INSTRUMATION_MODE=SIM and develop anywhere
Portability Vendor-specific SCPI — rewrite for each brand One API — works on Keysight, Rigol, Tektronix, Siglent, R&S, Anritsu
# ─── PyVISA: 8 lines of boilerplate ───
import pyvisa
rm = pyvisa.ResourceManager()
# Manually find the right resource...
sg = rm.open_resource("TCPIP0::192.168.1.100::inst0::INSTR")
sg.write("*RST")
sg.write(":FREQ:CW 2.4e9")
sg.write(":POW:AMPL -10")
sg.write(":OUTP ON")
sg.close()

# ─── Instrumation: 5 lines, zero config ───
from instrumation import connect_instrument

with connect_instrument("AUTO", "SG") as sg:
    sg.set_frequency(2.4e9)
    sg.set_amplitude(-10)
    sg.set_output(True)

No resource manager. No SCPI strings. No hardcoded addresses. Just your test logic.


Instrumation includes a built-in DataBroadcaster for streaming live readings over UDP. This allows you to build real-time dashboards or loggers with zero external dependencies.

  • Zero-lag — UDP delivery doesn't block your test flow.
  • Zero-config — Broadcast to any host/port as JSON packets.
  • Zero-dep — Built-in with Python standard library.

See examples/broadcast_demo.py and examples/dashboard.py for usage.

  • Auto-Discovery — scans VISA and Serial buses, identifies what's connected
  • Smart Factory — detects instrument brand and loads the correct driver
  • Digital Twin — full simulation mode for offline development and CI pipelines
  • Unified API — write once, run on any supported hardware
  • Built-in CSV logging — test results logged out of the box

Or install from source:

git clone https://github.com/abduznik/instrumation.git
cd instrumation
pip install .

Windows users: You may need NI-VISA or Keysight IO Libraries Suite for physical hardware access.


import instrumation

sa = instrumation.connect_instrument("USB0::0x2A8D::...")

peak_power = sa.get_peak_value()
print(f"Peak Power: {peak_power} dBm")

Digital Twin (no hardware needed)

# Linux/macOS
export INSTRUMATION_MODE=SIM

# Windows PowerShell
$env:INSTRUMATION_MODE="SIM"
from instrumation.factory import get_instrument

# Safer usage with context manager
with get_instrument("DUMMY_ADDRESS", "DMM") as dmm:
    print(dmm.get_id())
    result = dmm.measure_voltage()
    print(f"Voltage: {result}")

Manage complex test stations with multiple instruments using a station.toml file.

[instruments.sa_main]
driver = "SA"
address = "USB0::0x2A8D::0x0101::MY12345678::0::INSTR"

[instruments.psu_dut]
driver = "PSU"
address = "TCPIP0::192.168.1.100::inst0::INSTR"

Use it in your code:

from instrumation import Station

station = Station("station.toml")
station.connect()

# Access instruments via dot notation
res = station.instr.sa_main.get_peak_value()
print(f"Peak: {res}")

station.disconnect()

Instrumation comes with a powerful CLI for quick interaction and diagnostics.

# Scan for connected hardware
instrumation scan

# Take a quick measurement
instrumation measure USB0::... DMM measure_voltage

# List instruments in your station.toml
instrumation station list

# Measure using a named instrument from your station
instrumation station measure sa_main get_peak_value

Command Description
scan() Lists all connected Serial and VISA devices
connect() Auto-connects to a generic Test Station (Box + Instrument)
connect_instrument(addr) Connects to a specific instrument with auto driver detection

Platform Status
Windows Supported
Linux Supported
Termux (Android) Supported
macOS Supported

# Install in editable mode (required for tests to pick up local changes)
pip install -e .
# This project uses pyproject.toml (PEP 517/518). No setup.py is required.


# Install test dependencies
pip install pytest flake8

# Run tests (simulation mode)
export INSTRUMATION_MODE=SIM  # Linux/macOS
pytest

A lightweight Python library for generating structured UUT (Unit Under Test) test reports from measurement data. Works standalone or alongside Instrumation.

Features:

  • HTML, Excel, and PDF report output
  • Automatic pass/fail evaluation with configurable conditions
  • Structured sections and test tables
  • Easy integration with Instrumation measurements
pip install instrumation-report
from instrumation_report import Report, Section, TestTable, Measurement

report = Report(header=ReportHeader(
    title="RF Subsystem Validation",
    engineer="Yan",
    uut_serial="SN-2024-001",
))

section = Section(number="1", title="Voltage Tests")
table = TestTable(title="Power Supply Checks", sub_number="1.1")
table.add(Measurement("3.3V Rail", 3.31, "V", condition=(3.2, 3.4)))
section.add_table(table)
report.add_section(section)

report.generate_html("report.html")
report.generate_excel("report.xlsx")

  • Language: Python 3.7+
  • Libraries: PyVISA, PySerial
  • Architecture: Smart Factory Pattern, Polymorphism
  • Standards: SCPI (Standard Commands for Programmable Instruments)

Instrumation is maintained in my spare time alongside a full-time RF technician job. If it's saved you hours of boilerplate or made your test bench easier to automate, consider supporting:

GitHub Sponsors

Commercial support or custom driver development? Reach out via GitHub Issues or Discussions.


PRs and driver contributions are welcome. Open an issue first to discuss larger changes.

See LICENSE for details.

联系我们 contact @ memedata.com