Commands¶
ESC/POS command builders for the GoojPrt PT-210.
Every function in this module is pure: it has no side effects, performs no I/O, and merely returns the byte sequence that the caller sends over the chosen transport (BLE or SPP).
Two levels of helpers are provided:
Low-level builders (
init(),align(),bold(),feed(),cut(), …) emit a single ESC/POS escape sequence.Composite builders (
build_text_block(),build_qr_block()) concatenate several low-level commands into a ready-to-send block. These are shared by the BLE and SPP print APIs ofGoojPrtPT210to avoid duplicating byte construction logic.
Reference: ESC/POS Command Reference by Epson. Only the subset
implemented by the PT-210 firmware is exposed here.
- goojprt.commands.align(a: Align) bytes[source]¶
ESC a n— set horizontal alignment (LEFT / CENTER / RIGHT).
- goojprt.commands.barcode_qr(data: str, size: int = 6, error_correction: int = 1) bytes[source]¶
GS ( k— build the four-command sequence that prints a QR code.The sequence configures the model/error-correction level, stores the payload into the printer’s symbol buffer, and then triggers printing.
- Parameters:
data – Payload to encode (encoded as UTF-8 on the wire).
size – Module size, 1–16 (default
6).error_correction – Correction level —
0=L,1=M,2=Q,3=H (default1).
- Returns:
Bytes containing the complete QR command sequence.
- goojprt.commands.build_qr_block(data: str, size: int = 6, align_val: Align = Align.CENTER, error_correction: int = 1) bytes[source]¶
Build a QR block: alignment + QR command sequence + trailing newline.
Shared by both the BLE and SPP QR APIs.
- goojprt.commands.build_text_block(text: str, align_val: Align = Align.LEFT, bold_on: bool = False, underline_on: bool = False, size_val: TextSize = TextSize.NORMAL, newline: bool = True, encoding: str = 'gb2312') bytes[source]¶
Build the full ESC/POS block that prints a single text line.
The resulting byte stream contains, in order: alignment, bold toggle, underline toggle, text-size setting, the encoded text, and (optionally) a trailing line feed. This function is shared by BLE and SPP print APIs to keep the wire format identical.
- goojprt.commands.charset(cp: CodePage) bytes[source]¶
ESC t n— select code page for native ESC/POS text output.
- goojprt.commands.energy(dots: int = 7, heating: int = 120, interval: int = 2) bytes[source]¶
ESC 7 n1 n2 n3— configure thermal head heating parameters.- Parameters:
dots – Maximum number of simultaneously heated dots, 0–7. Higher values print faster but draw more current.
heating – Heating time, 0–255. Higher values produce darker output (the factory default is ≈ 80).
interval – Heating interval, 0–255. Lower values print faster (the factory default is ≈ 2).
- goojprt.commands.feed(lines: int = 1) bytes[source]¶
ESC d n— feed paper bylinesrows (clamped to 0–255).
- goojprt.commands.font(font_b: bool = False) bytes[source]¶
ESC M n— select font.False= Font A (12×24),True= Font B (9×17).
- goojprt.commands.init() bytes[source]¶
ESC @— initialise the printer (reset it to its default state).
- goojprt.commands.line_spacing(dots: int = 30) bytes[source]¶
ESC 3 n— set line spacing, measured in motion units (0–255).