escpos/printer
Functions for connecting to and communicating with ESC/POS printers.
Supports both USB (device file) and network (TCP socket) connections.
Example
// USB printer
let assert Ok(printer) = printer.device("/dev/usb/lp0")
// Network printer
let assert Ok(printer) = printer.connect("192.168.1.100", 9100)
escpos.new()
|> escpos.writeln("Hello!")
|> escpos.cut()
|> printer.print(printer)
// Close network printer socket
printer.disconnect(printer)
Types
Errors that can occur when connecting to or printing with a printer.
pub opaque type PrinterError
Values
pub fn connect(
ip: String,
port: Int,
) -> Result(Printer, PrinterError)
Connects to a network printer over TCP and sends the initialization command.
pub fn device(path: String) -> Result(Printer, PrinterError)
Opens a USB printer by its device file path (e.g. /dev/usb/lp0) and writes
the initialization command.
pub fn disconnect(printer: Printer) -> Result(Nil, PrinterError)
Closes the connection to a network printer. For USB printers this is a no-op.
pub fn print(
cb: @internal CommandBuffer,
printer: Printer,
) -> Result(Nil, PrinterError)
Sends a command buffer to the printer.
For network printers this writes to the TCP socket. For USB printers this writes directly to the device file.