I currently have a device that has a known PID and VID that is unique to the device and I want to use that information to find it's dev device path, like /dev/ttyUSB0
.
Is this possible? So far, I have been successful in using libudev to find the correct udev_device
for the pid and vid, but unsuccessful finding the path from this.
Is there any way to get this information?
ud = udev_new();
struct udev_enumerate *enumerate = udev_enumerate_new(ud);
udev_enumerate_add_match_subsystem(enumerate, "usb");
udev_enumerate_add_match_property(enumerate, "DEVTYPE", "usb_device");
udev_enumerate_scan_devices(enumerate);
struct udev_list_entry *devices;
devices = udev_enumerate_get_list_entry(enumerate);
struct udev_list_entry *dev_list_entry;
udev_list_entry_foreach(dev_list_entry, devices)
{
const char *sysfs_path = udev_list_entry_get_name(dev_list_entry);
struct udev_device *raw_dev = udev_device_new_from_syspath(ud, sysfs_path);
uint16_t vendor_id;
uint16_t product_id;
udev_get_sysattr_u16_base16(raw_dev, "idVendor", &vendor_id);
udev_get_sysattr_u16_base16(raw_dev, "idProduct", &product_id);
if (vendor_id == VID && product_id == PID) {
//find the device path
}
}