0

I have a small problem with the libusb.I want to open a USB port, but this port is never found. Result of lsusb command :

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 003 Device 002: ID 0461:4e22 Primax Electronics, Ltd 
Bus 001 Device 003: ID 046d:c326 Logitech, Inc. 
Bus 001 Device 004: ID 080c:0300 Datalogic S.p.A. Gryphon D120 Barcode Scanner

So in my main.c I try to open one USB port with :

libusb_open_device_with_vid_pid(NULL, VID, PID);

So my main.c is :

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

#define VID 0x0461
#define PID 0x4e22

static struct libusb_device_handle *devh = NULL;

int main(int argc,char** argv)
{

    libusb_init(NULL);
    devh = libusb_open_device_with_vid_pid(NULL, VID, PID);
    if (devh == NULL )
    {
       printf("not found\n");
       return -1;
    }
}

If I test all port usb none is found

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
simon
  • 1,180
  • 3
  • 12
  • 33
  • 1
    The `libusb_open_device_with_vid_pid` does multiple things at once, and returns null on *any* error, not just "not found", and you can't get the exact error, which is why it is not recommended to use in an actual application. By using [`libusb_get_device_list`](http://libusb.sourceforge.net/api-1.0/group__dev.html#gac0fe4b65914c5ed036e6cbec61cb0b97) and `libusb_open` you can get the actual error. Perhaps you just don't have the rights to open the device ? – Leiaz Jul 08 '15 at 14:16
  • Yes maybe I do not have the right, if I run my code with the sudo commande, I could not "not found" message.But is suspicious is that if I change my vid and pid and I put a bad address, and I run my code with the command sudo I do not have my message not found. I will try to use `libusb_get_device_list` and `libusb_open` – simon Jul 08 '15 at 15:06
  • do not use `NULL` for the libusb context – Alex P. Jul 09 '15 at 13:55
  • @PeterMortensen" **DO NOT** introduce false quoted error messages into questions. These give a misleading impression that the software has reported that specific error (often worth doing a web search on) which is not the case here. – Chris Stratton Jul 11 '15 at 16:18
  • 1
    @simon - note that the device you are trying to talk to is an HID mouse. That may introduce some additional complications, such as the need to detach the kernel driver, which typically requires root on linux. – Chris Stratton Jul 11 '15 at 16:20
  • @Chris Stratton Thanks for your answer, I actually found the function to detach the kernel driver, but I think I can not send signals to the USB port if I have no devices to connect over – simon Jul 16 '15 at 10:00
  • Talking on an empty port is unlikely to be supported outside of test register modes that might exist in some host controllers - what would you hope to achieve by it? – Chris Stratton Jul 16 '15 at 12:47
  • I thought light a LED on the USB port that is why I wanted to speak with an empty port on which I would plug my LED – simon Jul 20 '15 at 06:49

0 Answers0