You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I'm trying to migrate from usb-detection. I have lot of devices with the same VID and PID and I need to differenciate them by their serial number. Using usb-detection I could get the serialNumber directly in the callback:
If I read the docs correctly, I need to open the USB Device in order to read its serial number, right? This feeld wrong, because there might be another process trying to open that device, too. I don't want to just claim every usb device with that VID and PID...
Did usb-detection open them in the background?
This is probably similar to #328, but I can't reopen that one.
Error: LIBUSB_ERROR_NOT_SUPPORTED
at Device.ExtendedDevice.open (A:\_Source\GLUE\node_modules\usb\tsc\usb\device.ts:68:14)
at Discoverer.getSerialNumber (A:\_Source\GLUE\packages\makehaus-lib\src\control\Discovery.ts:108:24)
at EventEmitter.<anonymous> (A:\_Source\GLUE\packages\makehaus-lib\src\control\Discovery.ts:64:39)
at EventEmitter.emit (node:events:390:28)
at EventEmitter.emitHotplugEvents (A:\_Source\GLUE\node_modules\usb\tsc\usb\index.ts:63:17)
at EventEmitter.emit (node:events:390:28) {
errno: -12
}
If I read #182 correctly, that means that there's a wrong driver. Unfortunately, I can't require users to use Zadig to change the driver, just that I can read the serial number...
I only need to find the serial number of the device. The physical usb device provides a virtual com port which is used by serialport.
I wonder if usb-detection also opened the device...
It will (or Windows will when you plug it in)
This library uses libusb to be compatible across operating systems. Windows requires a driver for usb devices and can load winusb drivers for common devices (including HID devices AFAIK).
So it appears that it is possible on some platforms to retrieve the serialnumber without opening the device. But perhaps libusb isnt exposing a way to access this information?
Looking upstream, it sounds like there is no technical reason it isnt possible, and there has been some interest in supporting it, but nobody has provided a complete implementation yet.
Thanks for your hints. I'm gonna stay with @Julusian's patch of the usb-detection lib for now.
Maybe we can leave this open until some implements it upstream?
This feeld wrong, because there might be another process trying to open that device, too
there's nothing wrong with multiple processes accessing a device at the same time. as long as you don't do stuff such as resetting the device, changing to another configuration, or claiming an interface, you shouldn't interfere with other processes.
your use case in particular (opening a set of usb devices to get their serial number) is something I've definitely seen done in other libraries
Interesting. I thought that (at least on Windows) USB devices would be opened in exclusive mode (or was that only with hid devices? I can't remember.)
Even if that did not cause trouble, I'm still stuck with the LIBUSB_NOT_SUPPORTED error.
I would be happy to expose/utilise functionality to get the usb serial number on windows if someone were to port it from usb-detection.
e.g., the findBySerialNumber function could use native Windows code on windows and libusb otherwise. This feels like it would really harden the library and avoid a lot of libusb crashes finding devices on Windows. @Julusian WDYT?
For those watching, there is movement on this upstream libusb/libusb#1258.
I am keeping an eye on it in case I can help either there or here
I would be happy to expose/utilise functionality to get the usb serial number on windows if someone were to port it from usb-detection.
e.g., the findBySerialNumber function could use native Windows code on windows and libusb otherwise. This feels like it would really harden the library and avoid a lot of libusb crashes finding devices on Windows. @Julusian WDYT?
I would treat anything from node-usb-detection as questionable, as there are probably newer apis that will make the task simpler (as was the case for hotplug detection), but it could be done if someone is motivated to do it.
Reacted by Rob Moran, Harper Andrews, Hannes Rüger and Alba Mendez
Activity
thegecko commentedon Sep 22, 2022
Yes, the serial number string is not available in the usb descriptors, so you need to read it.
Other things which may help:
hrueger commentedon Sep 22, 2022
Wow, thanks for that quick answer 🎉
does this internally open the device?
I wonder if
usb-detectionalso opened the device... Maybe @Julusian knows that? (sorry for pinging you ;-) )thanks, I see that it also opens the device. I'll try that.
hrueger commentedon Sep 22, 2022
I just did a quick test using the code of the
findBySerialNumberfunction.However, I get
If I read #182 correctly, that means that there's a wrong driver. Unfortunately, I can't require users to use Zadig to change the driver, just that I can read the serial number...
I only need to find the serial number of the device. The physical usb device provides a virtual com port which is used by
serialport.thegecko commentedon Sep 22, 2022
Yes
It will (or Windows will when you plug it in)
This library uses libusb to be compatible across operating systems. Windows requires a driver for usb devices and can load winusb drivers for common devices (including HID devices AFAIK).
On windows you can also try:
https://github.com/node-usb/node-usb#usbuseusbdkbackend
Julusian commentedon Sep 22, 2022
It looks like
usb-detectionis using os native methods to fetch the serialnumber for each device.Parsing the unique device id on windows: https://github.com/MadLittleMods/node-usb-detection/blob/master/src/detection_win.cpp#L442-L467
Linux exposes it as part of a set of properties https://github.com/MadLittleMods/node-usb-detection/blob/master/src/detection_linux.cpp#L153-L155
Mac has an api to call for it https://github.com/MadLittleMods/node-usb-detection/blob/master/src/detection_mac.cpp#L189
So it appears that it is possible on some platforms to retrieve the serialnumber without opening the device. But perhaps libusb isnt exposing a way to access this information?
Julusian commentedon Sep 22, 2022
Looking upstream, it sounds like there is no technical reason it isnt possible, and there has been some interest in supporting it, but nobody has provided a complete implementation yet.
libusb/libusb#866
libusb/libusb#875
hrueger commentedon Sep 22, 2022
Thanks for your hints. I'm gonna stay with @Julusian's patch of the usb-detection lib for now.
Maybe we can leave this open until some implements it upstream?
[-]Migrating from `usb-detection`: How to get Serial Number[/-][+]Get SerialNumber without opening device[/+]mildsunrise commentedon Sep 22, 2022
hi, just wanted to say
there's nothing wrong with multiple processes accessing a device at the same time. as long as you don't do stuff such as resetting the device, changing to another configuration, or claiming an interface, you shouldn't interfere with other processes.
your use case in particular (opening a set of usb devices to get their serial number) is something I've definitely seen done in other libraries
hrueger commentedon Sep 23, 2022
Interesting. I thought that (at least on Windows) USB devices would be opened in exclusive mode (or was that only with hid devices? I can't remember.)
Even if that did not cause trouble, I'm still stuck with the LIBUSB_NOT_SUPPORTED error.
thegecko commentedon Oct 31, 2022
I would be happy to expose/utilise functionality to get the usb serial number on windows if someone were to port it from
usb-detection.e.g., the
findBySerialNumberfunction could use native Windows code on windows and libusb otherwise. This feels like it would really harden the library and avoid a lot of libusb crashes finding devices on Windows. @Julusian WDYT?hrueger commentedon Nov 1, 2022
What would speak agains exposing that functionality on MacOS and Linux, too?
thegecko commentedon Nov 1, 2022
I believe on those platforms you would be recreating how libusb does it.
ItsHarper commentedon Mar 22, 2023
Does this mean that on macOS and Linux you can retrieve the serial number without calling
open()?Julusian commentedon Mar 22, 2023
For those watching, there is movement on this upstream libusb/libusb#1258.
I am keeping an eye on it in case I can help either there or here
I would treat anything from node-usb-detection as questionable, as there are probably newer apis that will make the task simpler (as was the case for hotplug detection), but it could be done if someone is motivated to do it.
ItsHarper commentedon Jan 23, 2024
The libusb PR got closed and its branch deleted* :(
*Of course you can still view the changes at https://github.com/libusb/libusb/pull/1258/files
qwertychouskie commentedon Oct 1, 2024
libusb/libusb#1532 is the current version being worked on.
ItsHarper commentedon Aug 28, 2025
After just shy of 3 years, the day has finally come that
libusbsupports this on its main branch: libusb/libusb@e894c3eI no longer even have much reason to care haha