Skip to content

[Windows] USB thermal printers cannot reliably print raw ESC/POS receipts #206

Closed

Description

@khaira777

Problem

Windows USB thermal printers do not reliably print receipts or kitchen order tickets through the desktop app.

Reproduction

  1. Run FloCafe on Windows.
  2. Install/configure a USB thermal printer through Windows.
  3. Add it in FloCafe under Settings → Receipts & Printers.
  4. Set it as the default printer.
  5. Use Test Print, complete a sale, or print a KOT.

Actual behavior

The Windows USB print path fails before sending raw ESC/POS data.

The current implementation creates node-thermal-printer with a printer:<name> interface but does not provide the required printer driver. With the current node-thermal-printer version, this produces:

No driver set!

The fallback uses PowerShell PrintTo against a .bin file, which is not a reliable raw ESC/POS printing mechanism.

Expected behavior

The app should send the generated ESC/POS bytes directly to the configured Windows printer and successfully print:

  • Test pages
  • Receipts
  • Kitchen order tickets
  • 58mm and 80mm layouts

If the printer is unavailable, the app should report a clear failure without claiming that printing succeeded.

Root cause

The affected code is:

  • main/printers/thermal.ts
  • printViaUSBWindows()

The node-thermal-printer system-printer interface requires a printer driver, but the current code does not pass one.

Verification required

The fix needs real Windows hardware testing. Please verify with at least one USB thermal printer, preferably including Epson, Xprinter, or Rugtek hardware:

  • Test Print
  • Normal receipt printing
  • KOT printing
  • 58mm and 80mm paper
  • Printer disconnected
  • Printer reconnected
  • Printer configured through auto-detection and manual configuration

The native Winspool/raw-printing approach should be validated on Windows before considering this fixed. Linux/macOS printer tests do not validate this path.

Activity

  1. itsbkm commented on Aug 1, 2026

    @itsbkm
    Contributor

    Fixed on main in fe65926 (Windows) and d1a4b71 (CUPS parity). Leaving this open — the Windows path still needs hardware validation, checklist below.

    Root cause

    Confirmed as reported. printViaUSBWindows() built a node-thermal-printer instance with a printer:<name> interface but passed no driver, so it threw No driver set! before any bytes were sent. The fallback used PowerShell Start-Process -Verb PrintTo, which hands the file to the print driver rather than writing raw bytes — and reported success whether or not anything printed.

    Fix

    Write to the Windows spooler with datatype RAW (OpenPrinter → StartDocPrinter → StartPagePrinter → WritePrinter), the documented way to get bytes past the driver untouched. Implemented as C# compiled at run time by Add-Type, so the app stays free of per-Electron-ABI native prebuilds.

    Also addressed along the way:

    • Unicode entry points (OpenPrinterW / StartDocPrinterW) so non-ASCII printer names survive marshalling.
    • Pre-flight GetPrinter status check. OpenPrinter succeeds against the queue even when the device is unplugged, so without this a disconnected printer silently spools and reports success — the exact behaviour this issue asks to eliminate.
    • -EncodedCommand instead of a .ps1 file. A GPO-set ExecutionPolicy silently overrides -ExecutionPolicy Bypass, so a script file would have failed on precisely the managed machines a POS runs on.
    • Printer name and payload path passed through the child environment, never interpolated into script text.
    • %TEMP% instead of C:\Windows\Temp, which a standard user cannot write to.
    • Async, with a timeout and windowsHide — printing no longer blocks the Electron main process or the Express API, and no console window flashes on each receipt.

    node-thermal-printer is dropped; that call site was its only consumer.

    Verified before hardware

    • The exact embedded C# compiles at LangVersion 5 (what PowerShell 5.1's CodeDom accepts) with 0 warnings and 0 errors.
    • The full pipeline runs under pwsh: the here-string embedding survives, Add-Type compiles it, and SendRaw is genuinely reached — failing only at the winspool.drv P/Invoke, which exists only on Windows.
    • Injection probe: a printer name of '; Write-Output PWNED; # is treated as data, not script.
    • Every failure path exits non-zero and returns false. No path reports success without having written bytes.
    • Build clean, no new lint, 106 printing-related tests pass.

    Still needs real hardware

    None of the above proves bytes reach paper. Please run:

    • Test Print
    • Receipt on a completed sale
    • KOT
    • 58mm and 80mm
    • Printer disconnected — must report failure, not success
    • Printer reconnected
    • Auto-detected and manually configured printers

    Two log lines tell the story:

    [Printer] Windows raw print accepted for "<name>" (FLO_JOB_ID=<n>)
    [Printer] Windows raw print failed for "<name>": <reason>
    

    A FLO_JOB_ID means the spooler accepted the bytes. If that appears but no paper comes out, the problem is downstream — please attach the printer's driver name and port from Windows print settings.

    Known weak spot: the disconnected-printer case depends on the driver populating GetPrinter status flags. Plenty of low-cost thermal drivers report Status=0 even when unplugged; the check then degrades to a no-op and that bullet may still fail. This is the one I would expect to need a second pass.

    Known gap: printers installed as a USB virtual COM port rather than as a Windows print queue will not work — there is no queue for OpenPrinter to open. Those do not appear in wmic printer detection either, so they fail at discovery first.

    Related

    d1a4b71 fixes the same false-success class on macOS and Linux, which were never covered by this issue but had the identical flaw: lp exits 0 as soon as CUPS accepts a job, so a disabled queue — which is what CUPS does after a backend failure, e.g. an unplugged printer — was also reported as a successful print. Now pre-flighted with lpstat, run under LC_ALL=C since that output is localised.

    Worth stating plainly for both platforms: a spooler can only confirm it accepted the bytes, never that paper emerged. The first print immediately after a disconnect may still report success on Windows and CUPS alike, because the queue is only marked bad once a job has actually failed.

  2. itsbkm commented on Aug 4, 2026

    @itsbkm
    Contributor

    Resolved in the v2.7.0 release.

    The Windows USB path now sends raw ESC/POS bytes through Winspool instead of relying on node-thermal-printer without a driver or the unreliable PowerShell PrintTo fallback. It includes Unicode-safe printer names, printer pre-flight checks, timeout/error handling, and reports a FLO_JOB_ID only after the spooler accepts the raw job. Test Print, receipts, and KOTs now use the same corrected path, and failures are surfaced instead of reported as success.

    The remaining hardware checklist (Epson/Xprinter/Rugtek, 58/80mm, disconnect/reconnect, auto-detected/manual queues) should be covered as release validation, but the implementation defect described here is fixed. Closing issue 206.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

platform:windows

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions