I tried downloading the PyVisa module with the NI Visa libraries to find the GPIB port and address of the Agilent E4350B but no matter what I try it won't find it. I have a short code:
import visa
rm = visa.ResourceManager()
print(rm.open_resource())
But all it prints out is
('ASRL1::INSTR', 'ASRL2::INSTR')
I try to just open it anyways with the address I have it set at:
rm.open_resource('GPIB0::5::INSTR')
But it gives me this:
pyvisa.errors.VisaIOError: VI_ERROR_LIBRARY_NFOUND (-1073807202): A code library required by VISA could not be located or loaded.
I am running the same bit versions of Python and PyVISA. Can anyone tell me why it's not finding it?
Related
I have a DeLorme Earthmate LT-40 USB GPS device that I used years ago with a Windows XP program. Out of curiosity I plugged it into my Raspberry Pi to see if I could read the data. I've managed to see data using sudo gpsmon at the command prompt so I would like to take this a step further and write a Python program to read the data. Not knowing very much about Python I've searched YouTube and google for possible solutions. It looks like that I need to import pynmea2. I used pip install pynmea2 to install the module. I keep getting
"ModuleNotFoundError: No module named pynmea2"
when I try to run my script. I tried to reinstall pynmea2 again which gave me
Requirement already satisfied: pynmea2 in ./.local/lib/python2.7/site-packages(1.15.0).
I don't understand what I'm doing wrong. Any help would be greatly appreciated. Thank you.
I have the older version LT-20 of that GPS and usually it presents itself as ttyUSB0 (in my case) when I plug it on Raspberry.
Just do a dmesg command to see in which port it is being recognized, then you can do a cat /dev/ttyUSB0 command and you see all the messages coming from your GPS. The messages start with a $GP for each type of frame. See detailed $GP description at: http://aprs.gids.nl/nmea/ .
Then from your python program, you can open /dev/ttyUSB0 as a file (as read only) and handle each frame and interpetting it according to its format.
Best regards
Flavio
I am using python 2.7 to control a Newport 1936-R power meter which uses custom .dll.
It is not VISA (Virtual Instrument Software Architecture) compatible so I can't use pyvisa.
I have installed the USB driver which contains the dll named usbdll.dll. I copied the dll to a system folder so that it is visible. When using Python.Net I can AddReference but when I import the dll I get the error No module named usbdll.
My Python.Net version is 2.3.0
The correct dll to use is UsbDllWrap.dll located in Samples folder of your installation
I found a work around; by using NI Visa Wizard, I generated a driver and installed it. I can communicate with Newport Power Meter 1936-R with a 'raw' connection. I suggest trying NI VISA Wizard before going to Python.Net. The instrument connected can be seen in NI MAX, but not in Device Manager and pyvisa's resource manager. If anybody needs anything I am happy to help.
I want to access data in pap packets, currently i'm using pyshark with the following code
import pyshark,sys
cap = pyshark.FileCapture('test.pcap',display_filter='ppp && not ppp.length')
for packet in cap:
if packet.pap.get_field_value('peer_id'):
print ('user: '+packet.pap.peer_id+" logged in")
and it works fine on my pc and raspberrypi unfortunately i want to use this code on openwrt/lede router on which pyshark can't be installed due to ccache error:
unable to execute 'ccache_cc': no such file or directory
which i assumed that openwrt lacks some compiler features so I tried to install other pcap parsing libraries and could install scapy, dpkt and pypcapfile and they all installed fine so how can I convert my code to use one of these libraries
Thanks to #pierre I found out that the development version of scapy has some new usefull classes (PPP_PAP and PPP_PAP_Request) so I was able to write a working code for my problem and it works in python2 and python3
from scapy.all import PPP,PPP_PAP_Request,sniff
def logusers(pkt):
if PPP_PAP_Request in pkt:
print(pkt[PPP_PAP_Request].username.decode()+" logged in")
sniff(count=0,offline='all.pcap',prn=logusers,filter="pppoes",store=0)
I used sniff function because i found it a bit lightweight and fast(i'm trying to run the code on an embedded system after all) But nevertheless it's still a bit slow and i don't know if there is something faster (maybe other than scapy) so i'm not going to accept this answer for a while
With Scapy (use the development version from GitHub), you can try:
from scapy.all import PcapReader, PPP_PAP_Request
for pkt in PcapReader('test.pcap'):
if PPP_PAP_Request in pkt:
print(pkt.sprintf('user: %PPP_PAP_Request.username% logged in'))
I'm trying to connect to a GPIB instrument using pyVISA but I get an error. I'm following the simple example on the pyVISA website: http://pyvisa.readthedocs.org/en/master/
I type the following code into the IPython console:
import visa
rm = visa.ResourceManager()
rm.list_resources()
Out[4]:
(u'USB0::0x0957::0x0D0B::MY49431510::INSTR',
u'USB0::0x0957::0x17BC::MY52400338::INSTR',
u'ASRL1::INSTR',
u'ASRL2::INSTR',
u'ASRL5::INSTR',
u'ASRL6::INSTR',
u'ASRL7::INSTR',
u'ASRL8::INSTR',
u'ASRL9::INSTR',
u'ASRL10::INSTR')
However, my GPIB instruments do not show up, just the serial ports and my USB instruments. When I launch the Agilent Connection Expert (or NI MAX) I can see all my GPIB instruments and can communicate with them. I also am able to communicate with the instruments without issue with Matlab.
So when I try and connect to the instrument with the line:
inst = rm.open_resource('GPIB0::19::INSTR')
It throws an error:
VisaIOError: VI_ERROR_INTF_NUM_NCONFIG (-1073807195): The interface type is valid but the specified interface number is not configured.
I've also tried to connect with the USB instruments that show up when I list the resources and they do not throw this error. However, when I try and do a simple query:
inst = rm.open_resource('USB0::0x0957::0x0D0B::MY49431510::INSTR')
inst.query("*IDN?")
Nothing gets returned and no errors get thrown.
I'm using Python(X,Y) 2.7.9.0 with Python version 2.7.9 32 bit
pyVISA version is 1.6.3
NI bitness is 32
Any guidance is appreciated as I'm new to Python.
Thanks
You probably need to start the resource manager with:
rm = ResourceManager('Path to library')
where Path to library is the location of the NI Vista Library.
Also try:
python -m visa info
to ensure that you have it installed with the same word length as the python version that you are running.
I was having the same issue, and did manage to fix it by setting the path address to: 'C:/Program Files/IVI Foundation/VISA/WinNT/agvisa/agbin/visa32.dll'. If you haven't found the solution, I hope it works for you as well.
I had exactly the same problem - USB resources showed up, GPIB resources didn't. I tried to open the resource exactly as you did, inst = rm.open_resource('GPIB0::22::INSTR') (with the GPIB address changed to that of one of my instruments) with exactly the same result. Some inspired random guessing led me to
inst = rm.open_resource('GPIB1::22::INSTR')
which worked perfectly! Once the instrument is open it shows up in the list of resources, as expected. I have no idea why the interface is seen as GPIB1.
I am using the Keysight/Agilent/HP IO libraries suite as my VISA library (the NI library is not installed), and an Agilent 82357B USB to GPIB interface. I did not have to do any customisation of my pyVisa installation to get this working. Which is nice.
Hope this helps!
I had the same problem (running 32-bit python 2.7 on a 64-bit win7), I got it fixed using
rm = ResourceManager('C:/Program Files (x86)/IVI Foundation/VISA/WinNT/agvisa/agbin/visa32.dll')
which is the 32-bit VISA path given in the "About Agilent IO Control" Information.
I have ni-visa and Agilent visa installed on my computer. However, pyvisa cannot access the Agilent 82357B device due to pointing to the wrong library.
I used this command to specify the right library, it worked for me. Couples of notes:
Find the right library for the device which is visa32.dll located in different installation directories depends on each visa packet.
Use forward slash for delimiting characters even it is on windows.
Specify visa packet in the command: rm = visa.ResourceManager('c:/....')
I had the same issue. The problem was that the automatically installed Windows driver was wrong and my device showed up as USB0::0x3923::0x702A::010A65AB::RAW in NI MAX.
It was solved by an update of the driver (device manager-> properties) from C:\Program Files\National Instruments\NI-488.2 (or where your driver is installed).
Now GPIB works also from python.
I observed same error report when running on a PC with visa library from Keysight. Replacing with visa dll from National Instruments solved the problem.
I'm trying to have my Python application interface with an NFC device via USB.
The best option seems to be PyUSB, but I can't get it to connect to the libusb backend.
I keep getting
ValueError: No backend available
I've looked at the stack trace, and found that usb/backend/libusb10.py (which is part of pyusb) is trying to load libusb-1.0.dll to use as the backend, but it can't find it. It's not that it's not in my path, it's not on my computer at all!
I have installed libusb-win32, but the resulting directory only seems to include libusb0.dll. Where is libusb-1.0.dll???!
I would love to know either where to get that dll, or even a different suggestion to get PyUSB to work on Windows 7.
Download and install libusb-win32-devel-filter-1.2.6.0.exe. It should work.
2021 and the problem still occurs on Windows (Windows 10). I solved it by installing pyusb and libusb and adding libusb path to Windows environment:
pip install pyusb
pip install libusb
libusb-1.0.dll will be automatically added to:
\venv\Lib\site-packages\libusb\_platform\_windows\x64
and
\venv\Lib\site-packages\libusb\_platform\_windows\x32
Now just add those paths (the full path) to Windows Path and restart CMD / PyCharm.
I had a similar issue recently trying to talk to a USB device I am developing. I scoured the web looking for libusb-1.0.dll's and had no luck. I found source code, but nothing built and ready to install. I ended up installing the libusb-win32 binaries, which is the libusb0.dll.
PyUSB will search for libusb-1.0, libusb0, and openUSB backends.
libusb0.dll was already on my system, but something was still not set up right, do PyUSB was not working.
I followed the directions here to download and install the driver using the GUI tools provided to install the filter driver, and the INF wizard. Note, it didn't work until I ran the INF wizard.
I'm pretty new to programming and I've found the lack of clear documentation/examples to string this all together rather frustrating.
I am using Python 2.6.5, libusb-win32-device.bin-0.1.12.1 and pyusb-1.0.0-a0 on a windows XP system and kept receiving ValueError: No backend available.
Since there wasn't any real help on the web for this problem I spent a lot of time finding that ctypes util.py uses the Path variable to find the library file. My path did not include windows\system32 and PYUSB didn't find the library. I updated the path variable and now the USB is working.
There's a simpler solution.
Download and unpack to C:\PATH the libusb-1.0.20 from download link
Then try this line:
backend = usb.backend.libusb1.get_backend(find_library=lambda x: "C:\PATH\libusb-1.0.20\MS32\dll\libusb-1.0.dll")
dev = usb.core.find(backend=backend, find_all=True)
Depending on your system, try either MS64 or MS32 version of the .dll
Update of 17/01/2020, after a request to share more code:
import usb.core
import usb.util
from infi.devicemanager import DeviceManager
dm = DeviceManager()
devices = dm.all_devices
for i in devices:
try:
print ('{} : address: {}, bus: {}, location: {}'.format(i.friendly_name, i.address, i.bus_number, i.location))
except Exception:
pass
import usb.backend.libusb1
backend = usb.backend.libusb1.get_backend(find_library=lambda x: "C:\\libusb-1.0.20\\MS32\\dll\\libusb-1.0.dll")
dev = usb.core.find(backend=backend, find_all=True)
def EnumerateUSB(): #I use a simple function that scans all known USB connections and saves their info in the file
with open("EnumerateUSBLog.txt", "w") as wf:
counter = 0
for d in dev:
try:
wf.write("USB Device number " + str(counter) + ":" + "\n")
wf.write(d._get_full_descriptor_str() + "\n")
wf.write(d.get_active_configuration() + "\n")
wf.write("\n")
counter += 1
except NotImplementedError:
wf.write("Device number " + str(counter) + "is busy." + "\n")
wf.write("\n")
counter += 1
except usb.core.USBError:
wf.write("Device number " + str(counter) + " is either disconnected or not found." + "\n")
wf.write("\n")
counter += 1
wf.close()
I had the same problem with Windows 10, both Python 2.7.16 and Python 3.7.2. I installed libusb (through python -m pip install libusb ) but the error message remained. Also, the advice above about installing libusb-win32 did not work for me; neither of the 2 links (original post and #beebek's answer) existed.
What did work, however, is the comment by #user1495323 : I copied libusb-1.0.dll from
C:\Users\username\AppData\Roaming\Python\Python27\site-packages\libusb\_platform\_windows\x64\
to C:\Windows\System32\
download the latest libusb
Download libusb
Copy MS32\dll\libusb-1.0.dll to C:\Windows\SysWOW64
Copy MS64\dll\libusb-1.0.dll to C:\Windows\System32
3.
pip install libusb
Copy MS32\dll\libusb-1.0.dll to C:\Python\Python37-32\Lib\site-packages\libusb_platform_windows\x86
Copy MS64\dll\libusb-1.0.dll to C:\Python\Python37-32\Lib\site-packages\libusb_platform_windows\x64
This method works for me.
Had some problems with backendnotavailable at 2022 when I install pyusb and libusb on my Windows x64.
I've found a way to solve it reading -> Github solve explaining
To solve, first you need copy path to libusb-1.0.dll (..\envs<your_env_name>\Lib\site-packages\libusb_platform_windows\x64) at system's PATH variable.
Secondly restart IDE.
Third try to get_backend use usb.backend:
import usb.core
from usb.backend import libusb1
# it should find libusb-1.0.dll at our path variable
back = libusb1.get_backend()
print(type(back)) # return: <class 'usb.backend.libusb1._LibUSB'>
dev = usb.core.find(backend=back)
print(type(dev)) # return: <class 'usb.core.Device'>
# flag 'find_all=True' would return generator
# reprecent connected usb devices
dev_list = usb.core.find(find_all=True, backend=back)
print(type(dev_list)) # return: <class 'generator'>
If back is a NoneType, that means get_backend() hasn't found libusb-1.0.dll or found the wrong usblib (and that was my problem - I copied atPATH variable path to _x86 file, on my x64 machine).
Another way to solve it -> copy libusb-1.0.dll from (.._x64\libusb-1.0.dll) to (C:\Windows\System32).
"There are two versions of the libusb API: the current libusb-1.0 API, and its legacy predecessor libusb-0.1." (http://www.libusb.org/) "libusb-win32 is a port of the USB library ​libusb-0.1 to the Microsoft Windows operating systems". "Download the latest release tarball" from the same page (1.0.9 is the current version) to have libusb-1.0 equivalent, you'll find a folder Win32, where you'll find your libusb-1.0.dll to play with! You can even build it: http://www.libusb.org/wiki/windows_backend.
EDIT
You have to build it (download from/ http://sourceforge.net/projects/libusb/files/libusb-1.0/) since the tarball is from 2012, while the latest sources are from 2014-06-15.
To connect to your NFC device via USB using PYUSB, you will need to install the backend for that device. I do not think there is any backend for any device other than a libusb device.
To build a backend. You will need to know the driver (.sys file) for your device, so you could write a wrapper DLL to expose functionalities in the device. Your DLL would have to have a method to find device based on PID & VID, another method to open device and another method to send data and so on...
Just in case:
I haven't tried this on Windows but I had to set DYLD_LIBRARY_PATH path to circumvent this error on the Macintosh.
export DYLD_LIBRARY_PATH=/opt/local/lib
Discussion on whether or not to set this variable is here.
The libusb backend is initialized by the python script in /usb path,by loading the binary DLL from Windows PATH,if it's missed or installed by the zadig's dummy DLL,it will complained about this.Because the DLL installed by zadig doesn't exports any symbol to outside wolrd(dummy one I guess)