gpt4 book ai didi

python - PyVISA 未在 Linux 上列出 USB 仪器

转载 作者:行者123 更新时间:2023-12-05 01:08:07 34 4
gpt4 key购买 nike

我正在尝试通过 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'

关于python - PyVISA 未在 Linux 上列出 USB 仪器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66480203/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com