Libusb matching USB vendor id/product id with path in linux

1.5k views Asked by At

I have the following code that lists the IDVendor and IDProduct

#include <stdio.h>                                                         
#include <usb.h>                                                           

int main() {                                                               
    struct usb_bus *bus;                                                   
    struct usb_device *dev;                                                
    usb_init();                                                            
    usb_find_busses();                                                     
    usb_find_devices();                                                    
    uint8_t *ports;                                                        

    for (bus = usb_busses; bus; bus = bus->next)                           
        for (dev = bus->devices; dev; dev = dev->next) {                   
            printf("Trying device %s/%s\n", bus->dirname, dev->filename);  
           // printf("Port number: %d \n", libusb_get_port_number(dev));   
            printf("\tID_VENDOR = 0x%04x\n", dev->descriptor.idVendor);    
            printf("\tID_PRODUCT = 0x%04x\n", dev->descriptor.idProduct);  
            printf("\tDev Num = %d\n", dev->devnum);                       
        }                                                                  
    return 0;                                                              
}                                                                          

I want to recognize to which path "dev/ttyUSBX" these numbers are assigned to, so I can read data from serial for certain IDs I know beforehand. I've been scouring through libusb but I could not find how to get these paths.

0

There are 0 answers