Eric-Canas / USBMonitor

USBMonitor is an easy-to-use cross-platform library for USB device monitoring that simplifies tracking of connections, disconnections, and examination of connected device attributes on both Windows and Linux, freeing the user from platform-specific details or incompatibilities.
MIT License
33 stars 7 forks source link

Fix bug where the monitoring would stop at the first error #1

Closed juleaume closed 1 year ago

juleaume commented 1 year ago

If your computer has several usb ports, and one is valid but not any other, it will be ignored, rendering this lib useless.

Eric-Canas commented 1 year ago

Hi!! Thanks for your PR.

Do you know which device type was the one that gave you problems?

I put the assert there instead of ignoring the device because I didn't want to miss out a device that should be detected, just because I didn't take into account that device type.

So instead of ignoring it, in case it should be detected, I would prefer to parse its information. In case it is really a device_type to discard that's fine to apply this discarding logic.

Do you know which were those device_types that give you problems?

juleaume commented 1 year ago

Here is a clip from a modified version that only prints unsupported USB

>>> from usbmonitor import USBMonitor
>>> u = USBMonitor()
['USB4', 'ROOT_DEVICE_ROUTER&VID_8086&PID_463E', '4&1A0D213B&0&0']
['USB4', 'VIRTUAL_POWER_PDO', '4&1A0D213B&0&0']
Eric-Canas commented 1 year ago

I have been trying to include support for a USB4 device_type on windows, but I think my laptop does not have USB4 ports, as all the devices I tried where always USB or USBTOR devices.

I have anyway uploaded a new version to PyPi using the print you sent me as guide, as it looks exactly the same as common USB Devices. Could you try if it works for you by pip install --upgrade usb-monitor?

In case it doesn't work and you still want to make a PR, could you try to modify this _constants file, specifically from 34 to 48 to include the regex that would correctly decode the device_types that are giving you problems? Or, in case they are not devices that should be tracked because they don't correspond to physical devices, add them to _WINDOWS_NON_USB_DEVICES_IDS as I added "VIRTUAL_POWER_PDO".

I would like to support all USB device_types tracking instead of skipping unsupported ones, as they could be relevant for some users.

The _constants file I mentioned, is the one that manages the parsing needed for supporting new device_types.

Thanks a lot for your help

juleaume commented 1 year ago

It works seamlessly, thank you for your work!

Eric-Canas commented 1 year ago

Thanks!! Please tell me if you find any other error ^~^

I would like to maximize compatibility by accepting all kind of USB devices, but it seems that windows have some "USB types" that I have never seen from my laptop, so I can't test with them :(