I do not have any prior experience in Python and was trying to see if I can query information from a device with USB VISA address. I am running a Raspbian GNU/Linux 9 (stretch) with a Python 3.5.3 Shell. The VISA packages for python was installed using pip3:
$ sudo pip3 install pyvisa-py
Since I am interfacing the device with USB interface, I installed the python USB package as well.
$ sudo pip3 install pyusb
When I use the generic commands as per PyVISA website, I am able to read the partial VISA address without the serial number as shown below:
>>> import visa
>>> rm = visa.ResourceManager()
>>> print(rm.list_resources())
Found a device whose serial number cannot be read. The partial VISA resource name is: USB0::2391::11032::???::0::INSTR
('ASRL/dev/ttyAMA0::INSTR',)
Here is the python VISA info:
$ python3 -m visa info
Machine Details:
Platform ID: Linux-4.14.62-v7+-armv7l-with-debian-9.4
Processor:
Python:
Implementation: CPython
Executable: /usr/bin/python3
Version: 3.5.3
Compiler: GCC 6.3.0 20170124
Bits: 32bit
Build: Jan 19 2017 14:11:04 (#default)
Unicode: UCS4
PyVISA Version: 1.9.1
Backends:
ni:
Version: 1.9.1 (bundled with PyVISA)
Binary library: Not found
py:
Version: 0.3.0
TCPIP SOCKET: Available
GPIB INSTR:
Please install linux-gpib to use this resource type.
No module named 'gpib'
USB INSTR: Available via PyUSB (1.0.2). Backend: libusb1
ASRL INSTR: Available via PySerial (3.2.1)
USB RAW: Available via PyUSB (1.0.2). Backend: libusb1
TCPIP INSTR: Available
Not sure what I am doing wrong. How do I read the full VISA resource name? Without that, even if I try to force open the device with the full VISA address, it would throw another error.
I found the answer for my problem after referring to NI-VISA 17.0 read me file. USB devices are not accessible by VISA due to read only access. The solution on how and which file to edit were found from LinuxQuestions.org and GitHub. The steps that I took are as follows:
To become root on a Linux system, in a terminal, issue the command
sudo -i
and give your login password when asked. Then give the comand as above. Please check your spelling / copying very carefully before you press
While here, to edit the USB permissions file, you need to give the following commands in a terminal: Become root (as above). Notice how your terminal prompt has changed. Back up the original file:
cp /etc/udev/rules.d/99-com.rules /etc/udev/rules.d/99-com.rules.BAK
Open the file with the nano editor:
nano /etc/udev/rules.d/99-com.rules
Edit the file by adding the following:
SUBSYSTEM=="usb", MODE="0666", GROUP="usbusers"
Save the changes with "WriteOut" which is , press Enter to confirm the file name and location. Then "Exit" which is You'll need to restart udev so the changes are noticed:
/etc/init.d/udev restart
Close the terminal.