pololu / libusbp

The Pololu USB Library (also known as libusbp) is a cross-platform C library for accessing USB devices.
Other
104 stars 32 forks source link

Need to access device's friendly name #11

Open jporcher opened 1 year ago

jporcher commented 1 year ago

Under Windows, I need to access device's friendly name (SetupDiGetDeviceRegistryProperty with property SPDRP_FRIENDLYNAME).

This information is not part of libusbp::device. May it be added to the API? It's probably only available under Windows, I did not check. Would that be an acceptable pull request?

Else, can one retrieve the internal device handle from libusbp::device and later call SetupDiGetDeviceRegistryProperty?

DavidEGrayson commented 1 year ago

It's probably best to call libusbp_device_get_os_id and use that to retrieve the friendly name from SetupAPI. Does that work well enough?

On Wed, Dec 7, 2022, 7:47 AM jporcher @.***> wrote:

Under Windows, I need to access device's friendly name ( SetupDiGetDeviceRegistryProperty with property SPDRP_FRIENDLYNAME).

This information is not part of libusbp::device. May it be added to the API? It's probably only available under Windows, I did not check. Would that be an acceptable pull request?

Else, can one retrieve the internal device handle from libusbp::device and later call SetupDiGetDeviceRegistryProperty?

— Reply to this email directly, view it on GitHub https://github.com/pololu/libusbp/issues/11, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADR6THLJINU7OXUASZUW5DWMCPONANCNFSM6AAAAAASW45UPY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

jporcher commented 1 year ago

Sure, this can work. However, it would force to enumerate devices again as the API needs handles (OS IS as string won't help).

jporcher commented 1 year ago

Actually, not sure it will work. get_os_id returns me "USB\VID_0403&PID_6001\AR0JFBPE" while SetupDiGetDeviceRegistryProperty with SPDRP_HARDWAREID returns "FTDIBUS\COMPORT&VID_0403&PID_6001". So it's hard to safely determine if that's the same device or not (while it is in my case)

DavidEGrayson commented 1 year ago

The "OS ID" on Windows is a Device Instance ID, not a hardware ID. (It couldn't be a hardware ID because those are not unique when you plug two identical devices in.). You can use SetupDiGetDeviceInstanceIdA.

On Wed, Dec 7, 2022, 8:28 AM jporcher @.***> wrote:

Actually, not sure it will work. get_os_id returns me "USB\VID_0403&PID_6001\AR0JFBPE" while SetupDiGetDeviceRegistryProperty with SPDRP_HARDWAREID returns "FTDIBUS\COMPORT&VID_0403&PID_6001". So it's hard to safely determine if that's the same device or not (while it is in my case)

— Reply to this email directly, view it on GitHub https://github.com/pololu/libusbp/issues/11#issuecomment-1341135303, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADR6TGM6UDFZLNBEL65VEDWMCULRANCNFSM6AAAAAASW45UPY . You are receiving this because you commented.Message ID: @.***>

jporcher commented 1 year ago

Hi again,

get_os_id() is "USB\VID_0403&PID_6001\AR0JFBPE"

SetupDiGetDeviceInstanceId gives "FTDIBUS\VID_0403+PID_6001+AR0JFBPEA\0000" GetTextProperty/SPDRP_HARDWAREID gives "FTDIBUS\COMPORT&VID_0403&PID_6001"

So none fits. But this is maybe due to issue #10, looks like libusbp is pointing to "USB serial controller" while WindowsAPI is pointing to "USB serial port (COM8)". Then it's not surprising the names do not match.

jporcher commented 1 year ago

Just tested with a non FTDI device, using SetupDiGetDeviceInstanceId works fine to identify the device while enumerating using SetupAPI.

DavidEGrayson commented 1 year ago

A libusbp::device represents an actual physical device plugged into a USB port, not an interface/service provided by the device, so it is correct that the only libusbp::device there is "USB serial controller" (and the other nodes that are direct children of a USB hub).