Skip to main content

简体中文 | English

🚀 PyInsts

基于 PyVISA 的仪器自动化控制封装库 (支持 Windows, macOS, Linux)

PyPI Version Supported Python Versions License


pyinsts 是一个轻量级、健壮的 Python 仪器控制封装库。它基于 PyVISA,针对射频和电子测试实验室中常用的频谱分析仪、信号源、网络分析仪、电源、万用表等仪器进行了高层 SCPI 指令封装,同时支持底层的串口与硬件接口通信。

✨ 核心特性与架构

  • 🏗 模块化设计
    • instrument_drivers/: 存放 SCPI 仪器驱动及基类 baseinstrument.py,驱动类可直接从 pyinsts.instrument_drivers 统一导出使用。
    • drivers/: 存放底层硬件通信协议封装(如 serial_interface.py, ft2232h 等)。
    • instrument/sim/: 存放无实体硬件测试所需的仿真配置文件。
  • 🔄 自动连接重试:内置连接重试机制,自动规避短暂的硬件握手超时。
  • 高效同步阻塞:提供 wait_opc() 机制,相比硬编码 time.sleep 更安全,避免截图或扫频时的竞态问题。
  • 🗂 灵活配置加载:支持通过外部 config.yamlconfig.json 自动解析和分配仪器的物理地址(如 VISA 资源地址)。
  • 📝 开箱即用日志:内置彩色日志流(依赖 loguru),方便调试 SCPI 指令交互,并自动拦截 PyVISA 底层日志。

📦 安装方法

确保你的系统已配置 VISA 后台驱动(如 NI-VISA 或 Keysight IO Libraries Suite)。

pip install pyinsts

⚙️ 仪器地址配置文件示例

本库支持通过配置文件集中管理仪器的 VISA 地址。默认寻找 config.yamlconfig.json

在你的项目目录下创建 config.yaml

instruments_address:
  N9020B: "USB0::0x2A8D::0x1D0B::MY55480186::INSTR"  # Keysight 频谱仪地址
  E5052B: "GPIB0::17::INSTR"                         # Keysight 信号源分析仪地址
  FSWP-26: "TCPIP0::192.168.1.100::inst0::INSTR"     # R&S 信号分析仪地址

🚀 快速开始 (Quick Start)

下面是控制 Keysight N9020B 频谱仪并设置参数的示例:

import logging
from pyinsts.data import setup_logging
from pyinsts.instrument_drivers import FSV3030Sp

# 1. 初始化日志输出(支持控制台彩色显示与 Loguru 记录)
setup_logging(log_level=logging.INFO)

# 2. 建立仪器连接(支持连接实体硬件,也可追加 ;@sim 使用内置仿真测试)
sim_address = "USB::0x0AAD::0x0119::100001::INSTR;@sim"

try:
    with FSV3030Sp(address=sim_address, model="FSV3030") as spec:
        print(f"成功连接仪器,IDN: {spec.idn}")

        # 1. 设置中心频率为 1.0 GHz
        spec.set_freq_center(1.0, "GHz")

        # 2. 设置频跨 (Span) 为 10 MHz
        spec.set_freq_span(10.0, "MHz")

        # 3. 设置 RBW 为自动模式
        spec.set_rbw_auto()

        # 4. 触发 Peak Search 峰值查找
        spec.set_peak_search()

        # 5. 等待命令处理完成
        spec.wait_opc()
        print("仪器控制流程成功执行完毕!")

except Exception as e:
    print(f"仪器操作过程中发生错误: {e}")

📟 目前支持的仪器型号矩阵

支持的驱动类均支持从 pyinsts.instrument_drivers 直接导入:

厂商 (Manufacturer) 仪器类型 (Type) 驱动类名 (Class) 验证型号 (Tested Models)
Keysight / Agilent 信号/频谱分析仪 KeysightN9020B N9020B
Keysight / Agilent 信号/频谱分析仪 KeysightN9030A, KeysightN9030B N9030A, N9030B
Keysight / Agilent 信号源分析仪 KeysightE5052B E5052B
Keysight / Agilent 模拟信号发生器 KeysightE8257D E8257D
Keysight / Agilent 矢量网络分析仪 KeysightN5245B N5245B
Keysight / Agilent 直流电源 KeysightE36312A E36312A
Keysight / Agilent 射频功率计 KeysightN1914A N1914A
Keysight / Agilent 数字万用表 DM34461A 34461A
Rohde & Schwarz 频谱/信号分析仪 FSV3030Sp FSV3030
Rohde & Schwarz 信号/相噪分析仪 FswpSp (频谱模式), FswpPN (相噪模式) FSWP-26 / FSWP
Rohde & Schwarz 矢量网络分析仪 Zna43 ZNA43
Rohde & Schwarz 实时频谱分析仪 Rsa6000Sp RSA6000
同惠 (Tonghui) 矢量网络分析仪 Sna6034a SNA6034A
同惠 (Tonghui) 数字万用表 Th1963 TH1963
其他设备 (Others) 源表 / 测量单元 P2401 P2401
其他设备 (Others) 温控箱单元 Ts760, Ts760Set TS760

🧪 运行测试

项目内置基于 PyVISA @sim 仿真后端的单元测试,无需实体仪器即可验证连接与 SCPI 交互:

pip install -e ".[dev]"
pytest

🏷 更新日志与贡献

📄 开源协议

本项目采用 MIT License 开源协议。

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyinsts-0.1.0.tar.gz (59.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyinsts-0.1.0-py3-none-any.whl (81.8 kB view details)

Uploaded Python 3

File details

Details for the file pyinsts-0.1.0.tar.gz.

File metadata

  • Download URL: pyinsts-0.1.0.tar.gz
  • Upload date:
  • Size: 59.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pyinsts-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c3a483f95b53d80d0ac2ec08b7a8cfa45549e8c9e77ef29dfd8fc4b554c7199b
MD5 24138b82636904edfc534adf5bc98cf2
BLAKE2b-256 2ca5995403f70d9ba6649cb903610c31e37ead80f9b053c5642179da7bf222d1

See more details on using hashes here.

File details

Details for the file pyinsts-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyinsts-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 81.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pyinsts-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8273d29b2b227cb1b42c4e5f91d949a5db412183698e554c826bb94b1e35a42
MD5 e140777bfc0e99b9a5a99166bfbf13e0
BLAKE2b-256 7c063a88ee358ff22a74a637903287bdeac933ac410a9dd458a79ac7a9ba07d0

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.3.3

2 files

0.0.3.2

2 files

0.0.3.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page