libusb
libusb copied to clipboard
Offer an internal hardware ID for more complex device matching
- Working on Linux, macOS and WinUSB
On Linux we return sysfs_dir which can be used with udev_device_new_from_subsystem_sysname(,"usb",id) to get a udev_device. On macOS we return an IOServicePath which can be used with IORegistryEntryFromPath(,id) to make an io_service_t. On Windows WinUSB we return the dev_id which can be used with CM_Locate_DevNodeA(,id,) to get device information.
I believe this needs adding to the .def file for DLL on windows but I do not know how to do that
look like
libusb_get_platform_id libusb_get_platform_id@12=libusb_get_platform_id
The compiler also decorates C functions that use the __stdcall calling convention with an underscore (_) prefix and a suffix composed of the at sign (@) followed by the number of bytes (in decimal) in the argument list.
My project need work with difference type device, HID and customized USB device. It work well at Windows and linux. but face issue at MAC OS. MAC OS's HID driver can't unload easily. Maybe HIDAPI is quick solution. I need match port between HIDAPI and libusb. May this API can help me much.
Perfectly, I hope libusb can support detach kernel driver in MAC OS or work as like windows. Added another hook for HID.
I am not sure I understand the benefit of this PR. How does exposing internal location data help with matching devices?
We are using libusb for device searching and communicating. One question we needed to solve was 'which disk is in this usb storage device?'. To answer that question I needed to get an identifier from the libusb device that could then be used for matching the device.
On macOS I had to get the IORegistry node of the usb device and traverse the children looking for kIOBSDNameKey On Linux I had to get the udev device of the usb device and iterate the block devices, matching if the block device had the usb device as a parent On Windows I had to use CM_Locate_DevNodeA to get the device and CM_Get_Child to get the disk, followed by a HUGE amount of messing about to turn that into a PhysicalDrive string
All of these methods required access to the initial matching identifier string of the usb device and having my method rescan the usb seemed unnecessary when libusb had many of those identifiers internally already.
This seems to be a popular request.
@hjmallon
Just wonder if you are still interested in getting this PR updated?
My project need work with difference type device, HID and customized USB device. It work well at Windows and linux. but face issue at MAC OS. MAC OS's HID driver can't unload easily. Maybe HIDAPI is quick solution. I need match port between HIDAPI and libusb. May this API can help me much.
Perfectly, I hope libusb can support detach kernel driver in MAC OS or work as like windows. Added another hook for HID.
This is an old post. But just to make it clear, there will be NO HID backend for libusb under macOS. HIDAPI is the way to go.
We are using libusb for device searching and communicating. One question we needed to solve was 'which disk is in this usb storage device?'. To answer that question I needed to get an identifier from the libusb device that could then be used for matching the device.
On macOS I had to get the IORegistry node of the usb device and traverse the children looking for kIOBSDNameKey On Linux I had to get the udev device of the usb device and iterate the block devices, matching if the block device had the usb device as a parent On Windows I had to use CM_Locate_DevNodeA to get the device and CM_Get_Child to get the disk, followed by a HUGE amount of messing about to turn that into a PhysicalDrive string
All of these methods required access to the initial matching identifier string of the usb device and having my method rescan the usb seemed unnecessary when libusb had many of those identifiers internally already.
Indeed there are requests to match 'which disk is in this usb storage device?' and 'which serial port is linked to the USB to Serial devices', etc.