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 资源地址)。
  • 📝 开箱即用日志:内置彩色日志流(依赖 colorlog),方便调试 SCPI 指令交互。

📦 安装方法

确保你的系统已配置 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.instrument_drivers import KeysightN9020B
from pyinsts.data.log_data import setup_logging

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

# 2. 建立仪器连接(若不传入 address,则自动从 config.yaml 读取 model='N9020B' 的配置)
config_path = 'config.yaml'
try:
    with KeysightN9020B(config_path=config_path, model="N9020B") as spec_analyser:
        # 设置中心频率为 1 GHz
        spec_analyser.set_freq_cent(1, "GHz")

        # 将分辨率带宽 (RBW) 设置为自动
        spec_analyser.set_rbw_auto()

        # 触发 Peak Search
        spec_analyser.set_peak_search()

        # 查询当前 Marker1 的功率值
        power = spec_analyser.query_mark_y_power()
        print(f"当前信号峰值功率为: {power} dBm")

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
同惠 (Tonghui) 数字万用表 Th1963 TH1963
其他设备 (Others) 源表 / 测量单元 P2401 P2401
其他设备 (Others) 温控箱单元 Ts760 TS760

🏷 更新日志与贡献

📄 开源协议

本项目采用 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.0.8.tar.gz (56.9 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.0.8-py3-none-any.whl (76.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyinsts-0.0.8.tar.gz
  • Upload date:
  • Size: 56.9 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.0.8.tar.gz
Algorithm Hash digest
SHA256 5825d28b7f036c97298b37be8124f17c527b9822ba32e25c16f711da606bf08d
MD5 466118c32ef10f79dc8e8730fb80b20c
BLAKE2b-256 2a2d9e9cd4bdffe20d44ebdbf542b6465c6bc60c2a3c7a51b169e08b2cdbed1e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyinsts-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 76.7 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.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 9782d7860965065b93157c457e3502b92a28bc1fac7bf24cd682ac4012d72e06
MD5 e7594ae90076d4b1fe748875a3db9fbd
BLAKE2b-256 7a4b79c60bc6442057d8fd037c7f538b338df2eacec203e8608f692c0a1b6994

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.0

2 files

0.0.9

2 files

This release

0.0.8 This release

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