vpelletier / python-libusb1

Python ctype-based wrapper around libusb1
GNU Lesser General Public License v2.1
168 stars 65 forks source link

unable to find devices #15

Closed railsfactory-prabhu closed 8 years ago

railsfactory-prabhu commented 8 years ago

Hi, I am trying to list of usb devices in windows machine. I am using python 3.4 and following is my code:

import usb1

with usb1.USBContext() as context:

handle = context.openByVendorIDAndProductID(

#     skip_on_error=True,
# )
handle=context.open()
if handle is None:
    #Device not present, or user is not allowed to access device.
    print("No device found")
else:
    print("device found")
# with handle.claimInterface(INTERFACE):
    # Do stuff with endpoints on claimed interface.

And i am getting following error: C:\Python34\python.exe C:/Users/Prabhu/PycharmProjects/USBTRACER/testsamples/usbtest1.py Traceback (most recent call last): File "C:/Users/Prabhu/PycharmProjects/USBTRACER/testsamples/usbtest1.py", line 1, in import usb1 File "", line 2237, in _find_and_load File "", line 2226, in _find_and_load_unlocked File "", line 1191, in _load_unlocked File "", line 1161, in _load_backward_compatible File "C:\Python34\lib\site-packages\libusb1-1.5.0-py3.4.egg\usb1.py", line 60, in import libusb1 File "", line 2237, in _find_and_load File "", line 2226, in _find_and_load_unlocked File "", line 1191, in _load_unlocked File "", line 1161, in _load_backward_compatible File "C:\Python34\lib\site-packages\libusb1-1.5.0-py3.4.egg\libusb1.py", line 193, in libusb = _loadLibrary() File "C:\Python34\lib\site-packages\libusb1-1.5.0-py3.4.egg\libusb1.py", line 167, in _loadLibrary return dll_loader('libusb-1.0' + suffix, loader_kw) File "C:\Python34\Lib\ctypesinit.py", line 351, in init** self._handle = _dlopen(self._name, mode) OSError: [WinError 126] The specified module could not be found

Process finished with exit code 1

Thanks in advance.

vpelletier commented 8 years ago

Hello,

There are several problems with this code.

handle=context.open()

This does not open an USB device, but does what the context manager already did: it initialises libusb1 internal stuctures.

You should instead call openByVendorIDAndProductID to get an opened handle for a specific USB device. Please see the documentation (pydoc usb1 or equivalent) for more details (and more variants).

OSError: [WinError 126] The specified module could not be found

Python cannot find libusb. It must be installed where the dynamic library loader can find it. Please check libusb 1.0.x documentation (the underlying C library) on how to install it. Note that windows requires extra steps to be able to use devices, installing libusb 1.0.x itself is not enough.

As there is no python-libusb1 bug here, I close this report. Feel free to reopen if you have any issue specific to python-libusb1.

railsfactory-prabhu commented 8 years ago

Hi Vincent, Thank you for response. I have tried and searched more about this and I can't able to fix. Will you please send me proper steps for win7 64 bit with Python 3.4 to deploy it. Because in installation document of libusb is not sufficient. Please kindly take it as request. On 28-May-2016 1:49 PM, "Vincent Pelletier" notifications@github.com wrote:

Hello,

There are several problems with this code.

handle=context.open()

This does not open an USB device, but does what the context manager already did: it initialises libusb1 internal stuctures.

You should instead call openByVendorIDAndProductID to get an opened handle for a specific USB device. Please see the documentation (pydoc usb1 or equivalent) for more details (and more variants).

OSError: [WinError 126] The specified module could not be found

Python cannot find libusb. It must be installed where the dynamic library loader can find it. Please check libusb 1.0.x documentation (the underlying C library) on how to install it. Note that windows requires extra steps to be able to use devices, installing libusb 1.0.x itself is not enough.

As there is no python-libusb1 bug here, I close this report. Feel free to reopen if you have any issue specific to python-libusb1.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/vpelletier/python-libusb1/issues/15#issuecomment-222296775, or mute the thread https://github.com/notifications/unsubscribe/AREYGucqCUhETPdAlP6DWlPG7By_MstIks5qF_qrgaJpZM4Ina1L .

vpelletier commented 8 years ago

Hello,

Having no access to this windows variant at the moment, my comments will be a bit generic.

Here is the Libusb 1.0 installation documentation. Make sure to also read the windows-specific page (especially the bit about Zadig).

I do not know the difference between Visual Studio and MinGW variants - you'll have to figure out the one which matches your python installation (which is AFAIK not necessarily 64 bits). You may also have to figure which folder the library has to go in (long ago, it would have been something like C:\Windows\System32 IIRC - it may have changed).

Once you installed libusb correctly, the OSError will disappear - and you will start actually using python-libusb1 to control libusb to control your device.

Regards.