Closed YiyuanYin closed 1 year ago
The code checking whether a usb is attached is by finding the new device which has the different deviceAddress from the former one.
The attach/detach events are exposing hotplug events from the libusb library (except on Windows)
Perhaps you need to raise this issue there?
You mentioned "The code checking whether a usb is attached" so I assume you're in Windows. There's #488 to try to implement actual hotplug detection support on Windows.
By the way, I've just realized why this doesn't work... deviceAddress
is only unique within the bus the device is connected to.
To properly identify the device, we need the busNumber
too. Something like the deviceId
from WebUSB:
But I think we can do it even simpler... libusb will never return different libusb_device
pointers for the same device. And the bindings will never create two Device
instances for the same libusb_device
. Therefore we should be able to just say device1 === device2
to compare both lists of devices.
Closing this issue due to inactivity, please create a new issue as required.
I have an electron application that use this package to listen to the usb attach event. Sometimes attaching a usb can trigger
usb.on('attach')
event, sometimes it won't. The code checking whether a usb is attached is by finding the new device which has the differentdeviceAddress
from the former one. However, sometimes when a usb is attached, thedeviceAddress
is the same as the old ones in the device list. Therefore,usb
won't emitattach
event. Have you ever thought about adding some other conditions to decide whether a usb is attached?