Skip to content

Make libusb1 backend work for FreeBSD - #763

Open
saper wants to merge 1 commit into
python-escpos:masterfrom
saper:freebsd-fix
Open

saper wants to merge 1 commit into
python-escpos:masterfrom
saper:freebsd-fix

Conversation

@saper

@saper saper commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Description

  • The kernel driver might be there and it does not bother us
    and cannot be detached via libusb1
  • set_configuration() is already a soft reset, full reset() returns an error

Tested with

FreeBSD 16.0 (-current)
Epson TM-T88V

* The kernel driver might be there and it does not bother us
  and cannot be detached via libusb1
* set_configuration() is already a soft reset, full reset() returns an error
@codecov

codecov Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.07%. Comparing base (faf5249) to head (5880c31).
⚠️ Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
src/escpos/printer/usb.py 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master     #763   +/-   ##
=======================================
  Coverage   79.07%   79.07%           
=======================================
  Files          21       21           
  Lines        1754     1754           
  Branches      243      243           
=======================================
  Hits         1387     1387           
  Misses        286      286           
  Partials       81       81           
Flag Coverage Δ
unittests 79.07% <33.33%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/escpos/printer/usb.py 58.24% <33.33%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@belono

belono commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Hi @saper .

Do you mean that in the BSD platform the USB is handled differently than in Linux so is_kernel_driver_active(0) and detach_kernel_driver(0) are problematic and we have to avoid run those checks on the BSDs?

Those checks are needed specially on the Linux platform to let python get exclusive control of the USB device, so we should keep the checks on Linux.

@saper

saper commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

I understood from the code comments that this was mainly needed for Windows, will check how the driver detach prevents this from working and why (FreeBSD uses something similar to Linux, too).

What I am sure is that reset() was always returning an error and prevented a whole thing from working.

Comment thread src/escpos/printer/usb.py
@@ -155,7 +156,11 @@ def _check_driver(self) -> None:
and detach_kernel_driver().
This helps enable this library to work on Windows.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This helps enable this library to work on Windows.

This line is confusing, remove for the moment

Comment thread src/escpos/printer/usb.py
if (
self.device
and self.device.backend.__module__.endswith("libusb1")
and os.name == "win32"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
and os.name == "win32"
and os.name == "posix"

Check the kernel driver if the OS is posix (Linux, MacOS, BSD)

@belono

belono commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Yeah, the docstring is a bit confusing.

I've suggested to ckeck the kernel driver only on posix systems.

¿Could you test this change on FreeBSD?
If you find any problem then we should adapt the line to run only on linux with sys.platform.startswith("linux")

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

Successfully merging this pull request may close these issues.

2 participants