How can I fix pyVISA on Linux Ubuntu 22.04, get error 'VI_ERROR_NPERMISSION (-1073807192)'?

165 views Asked by At

I am trying to communicate with a Newport ESP300 motion controller using python 3.10 on a Linux machine. Either USB or Serial connection will work but I can't connect with either.

I started with a clean install (minimal) of Linux Ubuntu 22.04.3 LTS. Then, installed NI drivers (ni-ubuntu2204-drivers-2023Q4.deb) and NI-VISA. That seemed to work as no errors were generated. When I install pyVISA and create ResourceManager, I just get a list of 33 ASRLx::INSTR ports. When I install pyMeasure and list resources I see the same 33 but with the error (repeated for each of the 33 ports.

0 : ASRL1::INSTR : Visa IO Error: check connections
VI_ERROR_NPERMISSION (-1073807192): Access to the resource or remote machine is denied. This is due to lack of sufficient privileges for the current user or machine

My pyvisa-info (all python packages installed in virtual environment):

(practice) physix@physix-Latitude-E7470:~$ pyvisa-info
Machine Details:
   Platform ID:    Linux-6.2.0-37-generic-x86_64-with-glibc2.35
   Processor:      x86_64

Python:
   Implementation: CPython
   Executable:     /home/physix/Projects/practice/bin/python3
   Version:        3.10.12
   Compiler:       GCC 11.4.0
   Architecture:   ('x86', 64)
   Build:          Nov 20 2023 15:14:05 (#main)
   Unicode:        UCS4

PyVISA Version: 1.14.1

Backends:
   ivi:
      Version: 1.14.1 (bundled with PyVISA)
      #1: /usr/lib/x86_64-linux-gnu/libvisa.so.23.8.0:
         found by: auto
         architecture:
            ('x86', 64)
         Vendor: National Instruments
         Impl. Version: 24119296
         Spec. Version: 7340032
   py:
      Version: 0.7.1
      ASRL INSTR: Available via PySerial (3.5)
      USB INSTR: Available via PyUSB (1.2.1). Backend: libusb1
      USB RAW: Available via PyUSB (1.2.1). Backend: libusb1
      TCPIP INSTR: Available 
         Resource discovery:
         - VXI-11: ok
         - hislip: ok
      TCPIP SOCKET: Available 
      VICP INSTR:
         Please install PyVICP to use this resource type.
      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 functionalities.
         No module named 'gpib'
      GPIB INTFC:
         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 functionalities.
         No module named 'gpib'

So far, I have tried (unsuccessfully) the following:

  1. sudo chmod 777 /dev
  2. sudo usermod -a -G tty physix
  3. echo 'SUBSYSTEM=="usb", MODE="0666", GROUP="usbusers"' >> /etc/udev/rules.d/99-com.rules
  4. sudo udevadm trigger
  5. add output from hostname -I to visa configuration, security, allow access
1

There are 1 answers

0
Earthling75 On

To communicate with ESP300 motion controller, start with a clean install of Ubuntu 22.04. Forget about NI-VISA; for this simple instrument it's not necessary. I connected the ESP300 to a Dell Inspiron laptop via USB to Serial cable (with FTDI chip). Install the necessary python packages in the environment:

python3 -m pip install --upgrade pip
python3 -m pip install pyvisa
python3 -m pip install pyvisa-py
python3 -m pip install pyserial
python3 -m pip install pyusb
python3 -m pip install pymeasure

I did the next part in VS Code but Jupyter Notebook also works.

import pyvisa
#test = rm.open_resource('ASRL/dev/ttyS4::INSTR')
rm = pyvisa.ResourceManager()
rm.list_resources()

('ASRL/dev/ttyS4::INSTR', 'ASRL/dev/ttyUSB0::INSTR')

# Import necessary packages
from pyvisa.constants import StopBits, Parity
from pymeasure.adapters import VISAAdapter
from pymeasure.instruments.newport import ESP300

# Connect and configure the instrument
adapter = VISAAdapter('ASRL/dev/ttyUSB0::INSTR', baud_rate=19200, data_bits=8,  
                      parity=Parity.none, stop_bits=StopBits.one, timeout=None)
myesp = ESP300(adapter)

myesp.id

'ESP300 Version 3.00 05/04/05'

I didn't need any special drivers, but I had to edit the groups to give myself access to the usb and serial ports.

sudo usermod -a -G tty username
sudo usermod -a -G dialout username

and just for good measure

chmod 666 /dev/tty*

All that's left is to modify the ESP class file to program specific routines or whatever. I hope this helps somebody else.