PyVISA not listing USB instrument on Linux
Asked Answered
P

1

6

I am trying to communicate with a LeCroy WaveRunner 640Zi oscilloscope from a Raspberry Pi, they are connected with a USB cable. I have already done this under Windows, but now I am not able to make it work in Linux.

If I run lsusb I see this:

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

If I now go to Python I get this:

$ 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',)
>>> 

The oscilloscope is not there (the ASRL/dev/ttyAMA0::INSTR I think is something from the Raspberry Py itself). The oscilloscope is properly configured, I think, because if I go to the options (using the screen from the scope itself) and go to "remote options" I see that it is set up for USB and the VISA address is USB0::bla::bla::bla::INSTR.

I tried to proceed as explained in this page but did not work. If I run python3 -m visa info I get

$ 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'

I have also tried to connect with the oscilloscope without "listing the resources" by doing pyvisa.ResourceManager().open_resource('USB0::bla::bla::bla::INSTR') but I get:

>>> 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.
>>> 

Pattison answered 4/3, 2021 at 17:37 Comment(0)
P
13

I managed to find a solution which I share for the sake of future generations to come. I had just to add a line to the file /etc/udev/rules.d/99-com.rules with the content SUBSYSTEM=="usb", MODE="0666", GROUP="usbusers" (or append this line in case the file already exists) and then restart the computer. In summary:

  1. Enter into the sudo environment:
sudo su
  1. Now add the required line into the respective file:
echo 'SUBSYSTEM=="usb", MODE="0666", GROUP="usbusers"' >> /etc/udev/rules.d/99-com.rules
  1. Restart the computer.

  2. Enjoy.

$ 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'
Pattison answered 4/3, 2021 at 17:59 Comment(1)
tincantools.com/accessing-devices-without-sudoPythagorean

© 2022 - 2024 — McMap. All rights reserved.