Valentyn
Valentyn

Reputation: 719

PyUSB error "USBError: [Errno 2] Entity not found" using libusb0 driver (Windows 10)

I am trying to establish communication with an usb device. I do have libusb1 and libusb installed in Python as well as driver installed for the device I am communicating with. The device appears as libusb-win32-devices in the Device Manager. I have tried to follow this tutorial https://github.com/walac/pyusb/blob/master/docs/tutorial.rst I am not sure what I am doing wrong.

Simple code example:

import usb
dev = usb.core.find(idVendor=0x0683, idProduct=0x4108)
if dev is None:
       print 'Unable to find the usb device'
dev.set_configuration()

I get this error:

---------------------------------------------------------------------------
USBError                                  Traceback (most recent call last)
Y:\All Projects\Lab Equipment\DataQ\python\DI-4108\DI_4108_SANDBOX.py in <module>()
      9
     10
---> 11 dev.set_configuration()
     12
     13 # get an endpoint instance

C:\Anaconda2\lib\site-packages\usb\core.pyc in set_configuration(self, configuration)
    867         without arguments is enough to get the device ready.
    868         """
--> 869         self._ctx.managed_set_configuration(self, configuration)
    870
    871     def get_active_configuration(self):

C:\Anaconda2\lib\site-packages\usb\core.pyc in wrapper(self, *args, **kwargs)
    100         try:
    101             self.lock.acquire()
--> 102             return f(self, *args, **kwargs)
    103         finally:
    104             self.lock.release()

C:\Anaconda2\lib\site-packages\usb\core.pyc in managed_set_configuration(self, device, config)
    146
    147         self.managed_open()
--> 148         self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
    149
    150         # cache the index instead of the object to avoid cyclic references

C:\Anaconda2\lib\site-packages\usb\backend\libusb1.pyc in set_configuration(self, dev_handle, config_value)
    792     @methodtrace(_logger)
    793     def set_configuration(self, dev_handle, config_value):
--> 794         _check(self.lib.libusb_set_configuration(dev_handle.handle, config_value))
    795
    796     @methodtrace(_logger)

C:\Anaconda2\lib\site-packages\usb\backend\libusb1.pyc in _check(ret)
    593             raise NotImplementedError(_strerror(ret))
    594         else:
--> 595             raise USBError(_strerror(ret), ret, _libusb_errno[ret])
    596
    597     return ret

USBError: [Errno 2] Entity not found

I do get information about my device:

> DEVICE ID 0683:4108 on Bus 002 Address 005 =================  bLength 
> :   0x12 (18 bytes)  bDescriptorType        :    0x1 Device  bcdUSB   
> :  0x200 USB 2.0  bDeviceClass           :   0xff Vendor-specific 
> bDeviceSubClass        :    0x0  bDeviceProtocol        :    0x0 
> bMaxPacketSize0        :   0x40 (64 bytes)  idVendor               :
> 0x0683  idProduct              : 0x4108  bcdDevice              : 
> 0x100 Device 1.0  iManufacturer          :    0x1 Error Accessing
> String  iProduct               :    0x2 Error Accessing String 
> iSerialNumber          :    0x3 Error Accessing String 
> bNumConfigurations     :    0x1   CONFIGURATION 1: 500 mA
> ==================================    bLength              :    0x9 (9 bytes)    bDescriptorType      :    0x2 Configuration    wTotalLength 
> :   0x20 (32 bytes)    bNumInterfaces       :    0x1   
> bConfigurationValue  :    0x1    iConfiguration       :    0x5 Error
> Accessing String    bmAttributes         :   0xc0 Self Powered   
> bMaxPower            :   0xfa (500 mA)
>     INTERFACE 0: Vendor Specific ===========================
>      bLength            :    0x9 (9 bytes)
>      bDescriptorType    :    0x4 Interface
>      bInterfaceNumber   :    0x0
>      bAlternateSetting  :    0x0
>      bNumEndpoints      :    0x2
>      bInterfaceClass    :   0xff Vendor Specific
>      bInterfaceSubClass :    0x0
>      bInterfaceProtocol :    0x0
>      iInterface         :    0x4 Error Accessing String
>       ENDPOINT 0x81: Bulk IN ===============================
>        bLength          :    0x7 (7 bytes)
>        bDescriptorType  :    0x5 Endpoint
>        bEndpointAddress :   0x81 IN
>        bmAttributes     :    0x2 Bulk
>        wMaxPacketSize   :   0x40 (64 bytes)
>        bInterval        :    0x0
>       ENDPOINT 0x1: Bulk OUT ===============================
>        bLength          :    0x7 (7 bytes)
>        bDescriptorType  :    0x5 Endpoint
>        bEndpointAddress :    0x1 OUT
>        bmAttributes     :    0x2 Bulk
>        wMaxPacketSize   :   0x40 (64 bytes)
>        bInterval        :    0x0

So, the final question is: How do I get premissions in Windows? In Linux, you can do it through udev. How to fix this problem in Windows?

Upvotes: 3

Views: 8685

Answers (2)

copslock
copslock

Reputation: 21

There are 2 problems in this scnerio 1.the pyusb libusb library searching problem,the pyUSB will try to search any libusb1 dll in Windows PATH instead of prefering the libusb0 installed by zadig in system32 path,you can find this problem out through setting the PYUSB_DEBUG flag

 To enable PyUSB logging, you define the environment variable PYUSB_DEBUG with one of the following logging level values:

critical - only log critical errors
error - only log critical errors and errors
warning - log warnings, errors, and critical errors
info - log info, warnings, errors, and critical errors
debug - log everything including debug messages

But it has problem sometime that outputs nothing ,you have to redirect the output into local file to find its behaviour that trying to use the libusb1 dll it found in any related PATH program folder

By default, logged messages are sent to sys.stderr. You can redirect log messages to a file by defining the PYUSB_LOG_FILENAME environment variable to a string that is a valid file path and all logged messages will be written to the file rather than being sent to sys.stderr.

2.the libusb1 compat problem,neither the libusb1 dll from the libusb or libusb-win32 on sourceforge provides the required function exports that required by some specific python program,it may come out as such way

  1. Entity not found + Not implemented on this platform

  2. Permission denied

Both result from the incomplete implementation of libusb1.0 API on Windows platform

Just remove any libusb1 dll from your log above and makes the pyUSB trying to use the libusb0 instead.

Upvotes: 2

Valentyn
Valentyn

Reputation: 719

Solution #1: If your USB bulk device appears as libusb-win32 in the device manager. You need to change the libusb-win32 driver which uses libusb0 (v1.0.6.0) enter image description here

To libusbK USB device which uses libusbK driver (in my case v3.0.7.0). This will actually install libusbK driver and change the driver. This seamlessly can be done with Zadig free software Zadig screenshot libusbK USB device

This will solve the problem with the error code

USBError: [Errno 2] Entity not found

Upvotes: 1

Related Questions