Libusb error not found

An Android device has a different vid:pid depending on whether USB debugging is enabled or not. For example, on a Nexus 5: without USB debugging: 18d1:4ee1 with USB debugging: 18d1:4ee2 Here is a m...

An Android device has a different vid:pid depending on whether USB debugging is enabled or not.

For example, on a Nexus 5:

  • without USB debugging: 18d1:4ee1
  • with USB debugging: 18d1:4ee2

Here is a minimal sample:

source

#include <assert.h>
#include <stdio.h>
#include <unistd.h>

#include <libusb-1.0/libusb.h>

#define VID 0x18d1

int main() {
    int r = libusb_init(NULL);
    assert(!r);

    libusb_device **list;
    ssize_t count = libusb_get_device_list(NULL, &list);
    assert(count != -1);

    libusb_device *device = NULL;
    struct libusb_device_descriptor desc;

    for (size_t i = 0; i < (size_t) count; ++i) {
        int r = libusb_get_device_descriptor(list[i], &desc);
        if (r < 0)
            continue;
        if (desc.idVendor == VID) {
            device = libusb_ref_device(list[i]);
            break;
        }
    }

    libusb_free_device_list(list, 1);

    if (!device) {
        fprintf(stderr, "Device %04x:xxxx not foundn", VID);
        goto end;
    }

    printf("Device %04x:%04x okn", VID, desc.idProduct);

    libusb_device_handle *handle;
    r = libusb_open(device, &handle);
    if (r) {
        fprintf(stderr, "error: %sn", libusb_strerror(r));
        goto end;
    }

    char buffer[128];
    r = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber,
                                           (unsigned char *) buffer,
                                           sizeof(buffer) - 1);
    libusb_close(handle);
    if (r < 0) {
        fprintf(stderr, "serial: libusb error: %s", libusb_strerror(r));
        goto end;
    }

    buffer[r] = '';

    printf("serial: [%s]n", buffer);

end:
    libusb_unref_device(device);
    libusb_exit(NULL);
    return 0;
}
# native compilation (Linux)
gcc test.c -o test -lusb-1.0

# cross-compilation from Linux for Windows
x86_64-w64-mingw32-gcc test.c -o test.exe -Ilibusb-1.0.25/include -Llibusb-1.0.25/MinGW64/dll -lusb-1.0

On Linux, I can open the device and read the serial in both modes:

$ ./test
Device 18d1:4ee2 ok
serial: [05f5e60a0ae518e5]

$ ./test
Device 18d1:4ee1 ok
serial: [05f5e60a0ae518e5]

On Windows, I can open the device in both cases. However, I can only read the serial when USB debugging is enabled:

> test.exe
Device 18d1:4ee2 ok
serial: [05f5e60a0ae518e5]

> test.exe
Device 18d1:4ee1 ok
serial: libusb error: Entity not found

If I enable warnings:

libusb_set_option(NULL, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_WARNING);

Then I get these errors:

Device 18d1:4ee1 ok
libusb: error [winusbx_claim_interface] could not access interface 0: [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 1 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 2 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 3 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 4 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 5 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 6 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 7 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 8 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 9 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 10 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 11 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 12 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 13 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 14 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 15 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 16 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 17 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 18 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 19 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 20 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 21 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 22 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 23 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 24 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 25 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 26 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 27 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 28 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 29 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 30 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 31 with WinUSB): [1] Fonction incorrecte.
libusb: error [auto_claim] could not auto-claim any interface
serial: libusb error: Entity not found

It looks like #761, but I’m not sure it’s the same situation (Windows 10, libusb 1.0.25, WinUSB I guess).

For reference, the real use case: Genymobile/scrcpy#3050

Thank you for your help.

I’m creating a program that reads in input from a midi controller using libusb. How do I properly call libusb_bulk_transfer? Currently I’m receiving the error «LIBUSB_ERROR_NOT_FOUND» every time, and the data that I receive is «P».

I’ve swapped out the function ‘libusb_bulk_transfer’ with ‘libusb_interrupt_transfer’ but I still receive the same error: LIBUSB_ERROR_NOT_FOUND

Below are the libraries that I currently have included

#include <stdlib.h>
#include <stdio.h>
#include <libusb-1.0/libusb.h>

Below is main function that finds all of the usb devices and calls the function that is causing me issues: printDeviceUsbInput(devices[i]); For all I know, the main function is working fine. I removed the error checking to make the code shorter

int main(int argc, char *argv[])
{
    libusb_device **devices;
    libusb_context *context = NULL;

    size_t list;
    size_t i;
    int returnValue;

    returnValue = libusb_init(&context);

    list = libusb_get_device_list(context, &devices);

    printf("There are %zu devices found nn", list);
    for (i = 0; i < list; i++)
    {
        printDeviceUsbInput(devices[i]);
        //printDevices(devices[i]);
    }

    libusb_free_device_list(devices, 1);
    libusb_exit(context);
    return 0;
}

Below is the function that finds the midi keyboard device and attempts to print out the midi input. AKA the function that is causing me problems. I was inspired by this code: http://libusb.sourceforge.net/api-1.0/libusb_io.html

I also removed the error checking to make the function shorter.

void printDeviceUsbInput(libusb_device *device)
{

    struct libusb_device_descriptor deviceDescriptor;

    int returnValue;

    returnValue = libusb_get_device_descriptor(device, &deviceDescriptor);

    if(deviceDescriptor.idProduct == 49)
    {
        printf("Keyboard foundnn");
        unsigned char data[4];
        int actual_length;
        libusb_device_handle *deviceHandle;
        returnValue = libusb_open(device, &deviceHandle);

        while(1)
        {
            returnValue = libusb_bulk_transfer(deviceHandle, LIBUSB_ENDPOINT_IN,data, sizeof(data), &actual_length, 0);
            printf("Data: %snn", data);
            printf("returnValue: %snn", libusb_error_name(returnValue));
        }
    }
}

I expect that the call to libusb_bulk_transfer will return 0, and that the value of the variable data will change every-time I press a key on the midi keyboard.

  • Index
  • » Newbie Corner
  • » [SOLVED] libusb not found error

#1 2012-02-19 16:09:31

ephan
Member
Registered: 2011-11-02
Posts: 171

[SOLVED] libusb not found error

When I try to run simple-scan I get:

david@davidarch:~$ simple-scan
simple-scan: error while loading shared libraries: libusb-0.1.so.4: cannot open shared object file: No such file or directory
david@davidarch:~$

I have libusb installed, and my system is updated. What can I do? Thanks.

Last edited by ephan (2012-02-19 17:32:12)

#2 2012-02-19 16:48:21

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: [SOLVED] libusb not found error

output of pacman -Q simple-scan sane libusb-compat libusb


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

#3 2012-02-19 16:48:49

ephan
Member
Registered: 2011-11-02
Posts: 171

Re: [SOLVED] libusb not found error

david@davidarch:~$ pacman -Q simple-scan sane libusb-compat libusb
simple-scan 3.2.1-1
sane 1.0.22-5
libusb-compat 0.1.3-2
libusb 1.0.8-2
david@davidarch:~$ 

#4 2012-02-19 16:58:21

Gcool
Member
Registered: 2011-08-16
Posts: 1,456

Re: [SOLVED] libusb not found error

Could you post the output of…

# ls -lah /usr/lib | grep libusb-0.1.so.4

#5 2012-02-19 17:06:59

ephan
Member
Registered: 2011-11-02
Posts: 171

Re: [SOLVED] libusb not found error

Gcool wrote:

Could you post the output of…

# ls -lah /usr/lib | grep libusb-0.1.so.4

Blank output, nothing is outputted.

#6 2012-02-19 17:11:45

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 27,833
Website

Re: [SOLVED] libusb not found error

It looks like you’re missing libusb-compat, even though pacman says it’s installed.

You can check `pacman -Ql libusb-compat` to check.


«UNIX is simple and coherent…» — Dennis Ritchie, «GNU’s Not UNIX» —  Richard Stallman

#7 2012-02-19 17:13:05

Gcool
Member
Registered: 2011-08-16
Posts: 1,456

Re: [SOLVED] libusb not found error

Strange, seems that you’re missing some things there. Have you tried reinstalling libusb and libusb-compat?

#8 2012-02-19 17:17:15

ephan
Member
Registered: 2011-11-02
Posts: 171

Re: [SOLVED] libusb not found error

Reinstalling libusb-compat worked smile Thanaks!

#9 2012-02-19 17:27:18

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: [SOLVED] libusb not found error

Great, don’t forget to mark this thread as solved. (Directions can be found here.) Thanks!


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

#10 2016-11-07 08:18:48

TuxForLife
Member
Registered: 2015-11-14
Posts: 18

Re: [SOLVED] libusb not found error

Almost 5 years later here to thank Trilby!

#11 2016-11-07 11:21:25

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 27,833
Website

Re: [SOLVED] libusb not found error

*headdesk*

If you really want to thank me, read the code of conduct and do not necrobump, especially for an empty post.  Gratitude is nice, but do not let it dillute the signal to noise ratio here.

Closed.


«UNIX is simple and coherent…» — Dennis Ritchie, «GNU’s Not UNIX» —  Richard Stallman

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Libstdc 6 dll ошибка
  • Libscepad dll fallout 4 ошибка
  • Libreoffice ошибка при сохранении документа
  • Libreoffice ошибка ucrtbase dll
  • Libreoffice код ошибки 177

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии