USBMonitor icon indicating copy to clipboard operation
USBMonitor copied to clipboard

Create support for USBPRINT driver type or at least allow to ignore it

Open jokubas11 opened this issue 1 year ago • 2 comments

I have a USB printer connected and I cannot initialize the USBMonitor class, even if I device to use filter_devices argument, which would exclude that particular printer, so theoretically I am unable to even use this package whenever the printer is connected to PC, unless I modify source code in the package to ignore any USBPRINT devices.

  File "C:\projects\label_printer\env\lib\site-packages\usbmonitor\__platform_specific_detectors\_windows_usb_detector.py", line 126, in __get_driver_type_from_device_id
    assert driver_type in _WINDOWS_REGEX_ATTRIBUTES_BY_DRIVER, f"The driver type '{driver_type}' is not supported " \
AssertionError: The driver type 'USBPRINT' is not supported yet, please create an issue in github

jokubas11 avatar Jul 25 '24 05:07 jokubas11

@Eric-Canas would you mind taking a look at how this might be implemented, I'd like to help - but it's not entirely clear to me how to solve that - I also don't have devices to test this - essentially a first fix might be just skipping such devices, or do you have a better suggestion how to avoid crashing usbmonitor if such a device is connected?

daringer avatar Oct 08 '24 14:10 daringer

Hi!

That's for Windows right?

I have just uploaded a patch that should solve this issue. But I don't have such a device for testing so the attributes like ID_MODEL_ID, ID_VENDOR_ID and DEVTYPE could be actually wrong.

That's the relevant part of constants.py

_WINDOWS_USBPRINT_REGEX_ATTRIBUTES = {ID_MODEL_ID: r'PID_([0-9A-Fa-f]{4})', ID_VENDOR_ID: r'VID_([0-9A-Fa-f]{4})', DEVTYPE: r'^(.+?)\\', ID_SERIAL: r'\\([^\\]+)$'}

For making sure that device is fully supported, you should put a breakpoint after 41. devices = self._wmi_interface.query(_WINDOWS_USB_QUERY) in _windows_usb_detector.py and show me the wmi attributes: HardwareID and PNPDeviceID.

Just to make sure the regex are properly configured. But by the way, it should not break now.

Eric-Canas avatar Nov 17 '24 10:11 Eric-Canas