Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jokubas11 opened this issue Jul 25, 2024 · 2 comments
Open

Comments

@jokubas11
Copy link

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
@daringer
Copy link

daringer commented Oct 8, 2024

@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?

@Eric-Canas
Copy link
Owner

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.

robin-nitrokey added a commit to Nitrokey/nitrokey-app2 that referenced this issue Dec 12, 2024
This patch updates the locked usb-monitor version to v1.23.  This
release should include a fix for the crash on Windows if a printer is
connected.

See also:
- Eric-Canas/USBMonitor#6
- Eric-Canas/USBMonitor@f7ea799
Fixes: #288
robin-nitrokey added a commit to Nitrokey/nitrokey-app2 that referenced this issue Dec 16, 2024
This patch updates the locked usb-monitor version to v1.23.  This
release should include a fix for the crash on Windows if a printer is
connected.

See also:
- Eric-Canas/USBMonitor#6
- Eric-Canas/USBMonitor@f7ea799
Fixes: #288
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants