amosborne / rigol-ds1000z

Python library for interfacing with Rigol DS1000Z series oscilloscopes.
https://amosborne.github.io/rigol-ds1000z/
MIT License
16 stars 5 forks source link

Failure in find_visas(): OSError: Could not open VISA library #3

Open 0cjs opened 1 year ago

0cjs commented 1 year ago

This seems to be related to #2, but that PR is a bit confusing to me and documenting different issues, so I'm filing this one to try to focus on just this one problem, which is that library loading and TCP/IP network connectivity seem to have issues.

I'm on Debian 12 with Python 3.11.2. Other than using the system Python I've got very little installed from the OS; I use virtualvenvs for almost all my Python applications, including this one. I installed this package with pip install rigol-ds1000z and it gave me version 0.3.0, PyVISA 1.13.0 and PyVISA-py 0.5.3.

The PyVISA library and connectivity to the 'scope seem to be working:

(rigol) $ python3
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyvisa
>>> rm = pyvisa.ResourceManager()
>>> inst = rm.open_resource('TCPIP0::192.168.XXX.XXX::INSTR')
>>> inst.query('*IDN?')
'RIGOL TECHNOLOGIES,DS1104Z,DS1ZA191003179,00.04.04.SP1\n'
>>> 

When started with no options, or with -v TCPIP0::192.168.XXX.XXX::INSTR, I get the following:

Traceback (most recent call last):
  File "/home/cjs/.pyvirtenv/rigol/.build/virtualenv/bin/rigol-ds1000z", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/cjs/.pyvirtenv/rigol/.build/virtualenv/lib/python3.11/site-packages/rigol_ds1000z/cli.py", line 59, in main
    tui.run(args.visa)
  File "/home/cjs/.pyvirtenv/rigol/.build/virtualenv/lib/python3.11/site-packages/rigol_ds1000z/app/tui.py", line 227, in run
    Rigol_DS100Z_TUI.run(visa=visa, title="rigol-ds1000z")
  File "/home/cjs/.pyvirtenv/rigol/.build/virtualenv/lib/python3.11/site-packages/textual/app.py", line 206, in run
    asyncio.run(run_app())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/cjs/.pyvirtenv/rigol/.build/virtualenv/lib/python3.11/site-packages/textual/app.py", line 203, in run_app
    app = cls(screen=screen, driver_class=driver, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cjs/.pyvirtenv/rigol/.build/virtualenv/lib/python3.11/site-packages/rigol_ds1000z/app/tui.py", line 28, in __init__
    self.oscope = Rigol_DS1000Z(visa).open()
                  ^^^^^^^^^^^^^^^^^^^
  File "/home/cjs/.pyvirtenv/rigol/.build/virtualenv/lib/python3.11/site-packages/rigol_ds1000z/src/oscope.py", line 28, in __init__
    visas = find_visas()
            ^^^^^^^^^^^^
  File "/home/cjs/.pyvirtenv/rigol/.build/virtualenv/lib/python3.11/site-packages/rigol_ds1000z/utils.py", line 21, in find_visas
    visa_manager = ResourceManager(visa_backend)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cjs/.pyvirtenv/rigol/.build/virtualenv/lib/python3.11/site-packages/pyvisa/highlevel.py", line 2992, in __new__
    visa_library = open_visa_library(visa_library)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cjs/.pyvirtenv/rigol/.build/virtualenv/lib/python3.11/site-packages/pyvisa/highlevel.py", line 2904, in open_visa_library
    return cls(argument)
           ^^^^^^^^^^^^^
  File "/home/cjs/.pyvirtenv/rigol/.build/virtualenv/lib/python3.11/site-packages/pyvisa/highlevel.py", line 175, in __new__
    raise OSError("Could not open VISA library:\n" + "\n".join(errs))
OSError: Could not open VISA library:

I've tried the hack from the other PR, adding return [("TCPIP0::192.168.XXX.XXX::INSTR", "@py")] to the top of find_visas() in utils.py; and then rigol-ds1000z -v TCPIP0::192.168.XXX.XXX::INSTR -d z.png or rigol-ds1000z -d z.png does do the dump, but takes just over 106 seconds to do so. However, the "takes a long time" is not a problem for this issue, here I'd like to focus on that find_visas() seems to fail rather than happily connect to the address I give on the command line.

MichaDit commented 1 year ago

For fast readouts connect via socket (needs explicit termination set):

instrument = rm.open_resource(f"TCPIP0::[IP]::5555::SOCKET", write_termination = '\n', read_termination = '\n')