Repository navigation
Conversation
|
Thats odd, any idea why this is the case? |
|
(●__● ) great question, I have no idea |
|
oops I accidently attached the wrong issue - I meant #803 haha |
|
I think (please correct me if this is wrong):
Therefore, the correct fix may be to disable udev for windows builds only. WDYT? |
|
I was running it on Linux... |
Oh, the original issue was on windows |
|
@JonathanLeeIFX can you confirm if this fixes your issue on Windows? |
|
I'm not sure what the impact would be defaulting to not using udev. It seems a different source file is included: |
|
It's interesting that the example program did not work for you. It's supposed to be working because it only uses libusb. This fix did not work for me, but I may have done it wrong.
Output (edited for readability) device run 2: { |
|
Did you rebuild the binaries as well? Try the |
|
navigating to 'node_modules\usb' and running 'npm run prebuild' gives me the following error: > usb@2.13.0 prebuild gyp info it worked if it ends with ok gyp http GET https://nodejs.org/dist/v23.0.0/node-v23.0.0-headers.tar.gz |
|
hmm... Try to clone the repo, run |
|
I cloned the repo and it failed on 'npm install'. I had to copy the 'libusb' folder in from my original test repo. After that, 'npm install' worked. I then changed 'libusb.gypi' and 'binding.gyp', ran 'npm run prebuild', and copied 'prebuilds\win32-x64' to my test repo. |
|
I can't get it to work on windows either... On my Linux machine: import { getDeviceList } from "usb";
async function main() {
while (true) {
const allDevices = getDeviceList();
const device = allDevices.find(
(device) => device.deviceDescriptor.idProduct === <PID>
);
console.log(device?.deviceAddress);
await new Promise((resolve) => setTimeout(resolve, 1000));
}
}
main();Maybe this fix only works on linux? |
|
Possibly, but I'm still confused about the root issue: why does the node-usb package have an issue but not the original libusb DLL? |
|
Like I said in the PR, the original libusb DLL also didn't work for me |
|
@thegecko I think I found something (I don't know c++ that well, so please correct me if I get anything wrong). If I add If I remove the calls to |
I looked at this too, doesn't |
it starts at 1 ref |
then why does it get incremented in the constructor :/ |
|
I don't know man, maybe it was an oversight. If I had to guess it's because when the device is destroyed and not removed from the byPtr map it can cause some very weird behaviour in the get method. I added a log whenever a device was destroyed in the unref method, and it only ran whenever I didn't increment it in the constructor. |
|
Thanks for your help on this, I'll have a play around. This only fixes the windows issue, right? Linux is still tied up with udev. |
correct I pushed a potential fix. If the devices we actually unrefered at the end of We also can't use the pointer as the key in the byPtr map anymore as the pointer changes every time. What do you think? |
I don't think we can rely on this, I can imagine more odd edge cases than we have at the moment :/. Perhaps we should just recreate everything as soon as a |
That's not going to work is it? Any existing reads/etc. would break. I can't help feeling we are patching over and underlying issue here. We should be able to enumerate devices again while still holding references to them. What if we create a new usb context for getting a fresh list of devices then copy the changes over? |
How would we know what changed? how can we compare the devices and be certain they are the same physical device? |
|
Yeah you are right. Hmm. If we key based on |

Changes
Compiling libusb without udev fixes the problem.
I tried running libusbTest from #803 (comment) and it didn't work either - unless I compiled libusb without udev.
Fixes
Checklist
Have you...