سؤال

I'm creating a program to list all USB devices in Linux (Ubuntu in my case). I've been following this tutorial http://www.signal11.us/oss/udev/ and changed the subsystem from "hidraw" to "usb".

It lists the devices fine but it contains duplicates.

I can obviously remove the duplicates with my code but I was wondering if you know how to setup the device enumeration in a way that wouldn't return the duplicates.

If you want to have a look at my code (didn't change much) it's at https://github.com/DiogoNeves/LinuxUsbTest

Thanks!

هل كانت مفيدة؟

المحلول

For my system, I see my USB camera duplicated, but this is the correct behaviour because it occupies multiple slots in udev. When I do udevadm info --attribute-walk --name=video0, I see an entry for the USB endpoint and an entry for the USB device. If a device has many endpoints, it will be undoubtedly listed multiple times in udev. To remove the “duplicates”, you could filter on other attribues that are only present in the parent USB device and not the endpoint.

If you are scanning for USB devices, it might make more sense to use libusb-1.0 as it has a “better” view of USB devices.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top