PyVISA 未在 Linux 上列出 USB 仪器

PyVISA not listing USB instrument on Linux

我正在尝试通过 Raspberry Pi 与 LeCroy WaveRunner 640Zi 示波器通信,它们通过 USB 电缆连接。我已经在 Windows 下完成了此操作,但现在我无法在 Linux.

下使用它

如果我 运行 lsusb 我看到这个:

$ lsusb
Bus 001 Device 009: ID 05ff:1023 LeCroy Corp.
...

如果我现在去 Python 我得到这个:

$ python3
Python 3.7.3 (default, Dec 20 2019, 18:57:59) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyvisa
>>> pyvisa.ResourceManager().list_resources()
('ASRL/dev/ttyAMA0::INSTR',)
>>> 

示波器不在那里(ASRL/dev/ttyAMA0::INSTR 我认为是 Raspberry Py 本身的东西)。我认为示波器配置正确,因为如果我转到选项(使用示波器本身的屏幕)并转到“远程选项”,我会看到它是为 USB 设置的,VISA 地址是 USB0::bla::bla::bla::INSTR.

我尝试按照 this page 中的说明进行操作,但没有成功。如果我 运行 python3 -m visa info 我得到

$ python3 -m visa info
~/.local/lib/python3.7/site-packages/visa.py:23: 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.
  FutureWarning,
Machine Details:
   Platform ID:    Linux-4.19.97-v7+-armv7l-with-debian-10.3
   Processor:      

Python:
   Implementation: CPython
   Executable:     /usr/bin/python3
   Version:        3.7.3
   Compiler:       GCC 8.3.0
   Bits:           32bit
   Build:          Dec 20 2019 18:57:59 (#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.4)
      USB INSTR: Available via PyUSB (1.0.2). Backend: libusb1
      USB RAW: Available via PyUSB (1.0.2). Backend: libusb1
      TCPIP INSTR: Available 
      TCPIP SOCKET: Available 
      GPIB INSTR:
         Please install linux-gpib (Linux) or gpib-ctypes (Windows, Linux) to use this resource type. Note that installing gpib-ctypes will give you access to a broader range of funcionality.
         No module named 'gpib'

我也曾尝试通过 pyvisa.ResourceManager().open_resource('USB0::bla::bla::bla::INSTR') 在不“列出资源”的情况下连接示波器,但我得到:

>>> osc = pyvisa.ResourceManager().open_resource('USB0::0x05ff::0x1023::2810N60091::INSTR')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/.local/lib/python3.7/site-packages/pyvisa/highlevel.py", line 3304, in open_resource
    res.open(access_mode, open_timeout)
  File "~/.local/lib/python3.7/site-packages/pyvisa/resources/resource.py", line 298, in open
    self._resource_name, access_mode, open_timeout
  File "~/.local/lib/python3.7/site-packages/pyvisa/highlevel.py", line 3232, in open_bare_resource
    return self.visalib.open(self.session, resource_name, access_mode, open_timeout)
  File "~/.local/lib/python3.7/site-packages/pyvisa_py/highlevel.py", line 167, in open
    sess = cls(session, resource_name, parsed, open_timeout)
  File "~/.local/lib/python3.7/site-packages/pyvisa_py/sessions.py", line 323, in __init__
    self.after_parsing()
  File "~/.local/lib/python3.7/site-packages/pyvisa_py/usb.py", line 84, in after_parsing
    self.parsed.serial_number,
  File "~/.local/lib/python3.7/site-packages/pyvisa_py/protocols/usbtmc.py", line 287, in __init__
    super(USBTMC, self).__init__(vendor, product, serial_number, **kwargs)
  File "~/.local/lib/python3.7/site-packages/pyvisa_py/protocols/usbtmc.py", line 199, in __init__
    raise ValueError("No device found.")
ValueError: No device found.
>>> 

我设法找到了一个解决方案,为了子孙后代而分享。我只需要在文件 /etc/udev/rules.d/99-com.rules 中添加一行内容为 SUBSYSTEM=="usb", MODE="0666", GROUP="usbusers"(或者在文件已经存在的情况下追加这一行),然后 重新启动计算机 .总结:

  1. 进入sudo环境:
sudo su
  1. 现在将所需的行添加到相应的文件中:
echo 'SUBSYSTEM=="usb", MODE="0666", GROUP="usbusers"' >> /etc/udev/rules.d/99-com.rules
  1. 重启电脑.

  2. 尽情享受吧。

$ python3
Python 3.7.3 (default, Dec 20 2019, 18:57:59) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyvisa
>>> pyvisa.ResourceManager().list_resources()
('ASRL/dev/ttyAMA0::INSTR', 'USB0::bla::bla::bla::INSTR')
>>>  osc = pyvisa.ResourceManager().open_resource('USB0::bla::bla::bla::INSTR')
>>> osc.query('*IDN?')
'*IDN LECROY,WR640ZI,LCRY28blablabla,7.7.1\n'