首页 > 解决方案 > PyVISA GPIB 函数将引发 OSError 直到手动加载库

问题描述

我正在尝试通过 USB 连接一个新的开源 VNA 或矢量网络分析仪 (LibreVNA),以便能够自动进行一些读数。我在尝试通过 PyVISA 连接到设备时遇到了问题。我无法访问 SCPI 命令,因为 PyVISA 会导致以下错误以及两个不是开源 VNA 的“ASRL/dev/ttyS0::INSTR”设备。

当我运行 python3 -m 签证信息时:

/usr/local/lib/python3.8/dist-packages/visa.py:13: FutureWarning: The visa module provided by PyVISA is being deprecated. You can replace `import visa` by `import pyvisa as visa` to achieve the same effect.

The reason for the deprecation is the possible conflict with the visa package provided by the https://github.com/visa-sdk/visa-python which can result in hard to debug situations.
  warnings.warn(
/usr/local/lib/python3.8/dist-packages/gpib_ctypes/gpib/gpib.py:54: UserWarning: GPIB library not found. Please manually load it using _load_lib(filename). All GPIB functions will raise OSError until the library is manually loaded.
  warnings.warn(message)
Machine Details:
   Platform ID:    Linux-5.11.0-25-generic-x86_64-with-glibc2.29
   Processor:      x86_64

Python:
   Implementation: CPython
   Executable:     /usr/bin/python3
   Version:        3.8.10
   Compiler:       GCC 9.4.0
   Bits:           64bit
   Build:          Jun  2 2021 10:49:15 (#default)
   Unicode:        UCS4

PyVISA Version: 1.11.3

Backends:
   ivi:
      Version: 1.11.3 (bundled with PyVISA)
      Binary library: Not found
   py:
      Version: 0.5.2
      ASRL INSTR: Available via PySerial (3.5)
      USB INSTR: Available via PyUSB (1.2.1). Backend: libusb1
      USB RAW: Available via PyUSB (1.2.1). Backend: libusb1
      TCPIP INSTR: Available 
      TCPIP SOCKET: Available 

从我之前的尝试中,我尝试添加 GPIB-ctypes 库,这就是添加错误的时候。我收到一个错误,提示如果不添加 gpib-ctypes 库就无法找到名为“gpib”的模块。

标签: pyvisagpib

解决方案


如果您查看此设备的SCPI 示例,您会发现 SCPI 通信实际上是通过 TCP 端口完成的(默认值为 19542)。此外,GUI 必须正在运行,并且必须在 GUI 中启用 SCPI 通信。GUI 似乎运行了一个小型 SCPI 服务器。这种方法通常用于更昂贵的 USB 网络分析仪(例如 Keysight 和 Textronix)。

根据PyVisa docs,您应该能够使用此语法来连接设备字符串:

TCPIP::localhost::19542::SOCKET

或者

TCPIP::127.0.0.1::19542::SOCKET

我不知道是否有任何 VISA 库能够通过rm.list_resources().


推荐阅读