本文介绍了PyVISA未列出Linux上的USB仪器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
我正在尝试从树莓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本身的东西)。我认为示波器配置正确,因为如果我转到Options(使用示波器本身的屏幕),然后转到";Remote Options&Quot;,我看到它是为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.
>>>
推荐答案
我设法找到了一个为子孙后代分享的解决方案。我只需向内容为SUBSYSTEM=="usb", MODE="0666", GROUP="usbusers"
的文件/etc/udev/rules.d/99-com.rules
添加一行(如果文件已存在,则追加该行),然后重新启动计算机。总结:
- 进入sudo环境:
sudo su
- 现在将所需的行添加到各自的文件中:
echo 'SUBSYSTEM=="usb", MODE="0666", GROUP="usbusers"' >> /etc/udev/rules.d/99-com.rules
重新启动计算机。
尽情享受。
$ 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
'
这篇关于PyVISA未列出Linux上的USB仪器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!