Printer¶
The high-level, chainable API. See the Guide for usage.
vkp80iii.printer ¶
High-level, ergonomic API for the Custom VKP80III.
:class:Printer wraps a :class:~vkp80iii.transport.Transport and the pure
byte builders in :mod:vkp80iii.commands. Formatting/print methods are
chainable (they return self); query methods return decoded values.
Example::
from vkp80iii import Printer, Justify
with Printer() as p: # opens /dev/usb/lp0
p.align(Justify.CENTER).bold().textln("CAFE DEMO").bold(False)
p.textln("------------------------")
p.align(Justify.LEFT).textln("1x Espresso 2.50")
p.qrcode("https://example.com")
p.feed(3).present() # cut + present the ticket
Printer ¶
A connected VKP80III printer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transport
|
Transport | None
|
any :class: |
None
|
codepage
|
CodePage | int
|
initial code page, also used to pick the text codec. |
PC437
|
auto_open
|
bool
|
open the transport immediately (default True). |
True
|
Source code in src/vkp80iii/printer.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 | |
for_paper
classmethod
¶
for_paper(
transport: Transport | None = None,
*,
width_mm: float,
margin_mm: float = 1.5,
codepage: CodePage | int = CodePage.PC437,
auto_open: bool = True,
) -> Printer
Build a Printer centered on a width_mm roll (the recommended setup).
Assumes the firmware PRINT WIDTH matches the paper, so the logical
origin is the paper's left edge (see the README "Narrow paper" section).
margin_mm is inset on each side: the print area becomes
width_mm - 2 * margin_mm and content is centered via
left_offset_dots = round(margin_mm * DOTS_PER_MM). The margin also
keeps left-aligned text off the head's physical non-printable left edge
(offset 0 clips the first column by 1-2 px).
This is the convenient counterpart to passing paper_width_mm +
left_offset_dots yourself; use those directly for the software
fallback where the firmware PRINT WIDTH is not matched to the paper
and the offset is measured with python -m vkp80iii calibrate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width_mm
|
float
|
physical paper width in mm (= firmware |
required |
margin_mm
|
float
|
safety/centering margin per side (default 1.5 mm = 12 dots at 8 dots/mm). |
1.5
|
Source code in src/vkp80iii/printer.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
set_print_area ¶
set_print_area(dots: int | None = None) -> Printer
GS W -- set the printing area width (default: this paper's width).
Source code in src/vkp80iii/printer.py
170 171 172 | |
apply_layout ¶
apply_layout() -> Printer
Send the left margin + print width for this paper (GS L + GS W).
Call right after :meth:reset (ESC @ clears margins). This makes the
paper's left edge the print origin and constrains the printable width,
so text wrapping, centering and right-justify all use the real paper.
Source code in src/vkp80iii/printer.py
174 175 176 177 178 179 180 181 182 | |
begin ¶
begin() -> Printer
Convenience: :meth:reset then :meth:apply_layout.
Source code in src/vkp80iii/printer.py
184 185 186 | |
send ¶
send(data: bytes) -> Printer
Send raw bytes straight to the printer.
Source code in src/vkp80iii/printer.py
204 205 206 207 | |
text ¶
text(s: str, *, encoding: str | None = None) -> Printer
Send a text string (encoded with the active code page codec).
Source code in src/vkp80iii/printer.py
218 219 220 221 | |
textln ¶
textln(
s: str = "", *, encoding: str | None = None
) -> Printer
Send s followed by a line feed.
Source code in src/vkp80iii/printer.py
223 224 225 | |
newline ¶
newline(n: int = 1) -> Printer
Emit n blank line feeds.
Source code in src/vkp80iii/printer.py
229 230 231 | |
reset ¶
reset() -> Printer
ESC @ -- reset the printer to power-on defaults.
This also reverts the device to its default code page (PC437), so the cached text codec is resynced to match.
Source code in src/vkp80iii/printer.py
236 237 238 239 240 241 242 243 244 | |
reverse ¶
reverse(on: bool = True) -> Printer
White-on-black reverse printing.
Source code in src/vkp80iii/printer.py
258 259 260 | |
char_size ¶
char_size(width: int = 1, height: int = 1) -> Printer
Character magnification (width/height each 1..8).
Source code in src/vkp80iii/printer.py
271 272 273 | |
print_modes ¶
print_modes(**kwargs: bool) -> Printer
Set several modes at once: font_b, bold, double_height, double_width, italic, underline.
Source code in src/vkp80iii/printer.py
275 276 277 | |
line_spacing ¶
line_spacing(n: int | None = None) -> Printer
Set line spacing: None -> default 1/6", else n motion units.
Source code in src/vkp80iii/printer.py
314 315 316 | |
line_spacing_tight ¶
line_spacing_tight() -> Printer
1/8-inch line spacing.
Source code in src/vkp80iii/printer.py
318 319 320 | |
code_page ¶
code_page(page: CodePage | int) -> Printer
Select the active code page.
For pages with a known Python codec (see _CODEPAGE_CODEC) the text
codec is updated to match. For any other page the codec is left
unchanged -- set :attr:encoding yourself so :meth:text encodes
correctly.
Source code in src/vkp80iii/printer.py
323 324 325 326 327 328 329 330 331 332 333 | |
feed ¶
feed(lines: int = 1) -> Printer
Print buffer and feed lines lines.
Source code in src/vkp80iii/printer.py
349 350 351 | |
feed_units ¶
feed_units(n: int) -> Printer
Print buffer and feed n vertical motion units.
Source code in src/vkp80iii/printer.py
353 354 355 | |
cut ¶
cut(feed: int | None = None) -> Printer
Cut the paper (optionally feeding feed units first).
Source code in src/vkp80iii/printer.py
357 358 359 | |
present ¶
present(
steps: int = 2,
*,
blink_led: bool = False,
retract: bool = False,
timeout_s: int = 0,
) -> Printer
FS P -- cut and present the ticket at the bezel.
See :func:vkp80iii.commands.present_ticket for the parameter meanings.
Source code in src/vkp80iii/printer.py
361 362 363 364 365 366 367 368 369 370 371 372 373 | |
collect_mode ¶
collect_mode(enabled: bool) -> Printer
Enable/disable COLLECT mode (batch uncut tickets into the bin).
Source code in src/vkp80iii/printer.py
375 376 377 | |
eject_mode ¶
eject_mode() -> Printer
Enable EJECT (dispenser-continuous) mode; close it with :meth:present.
Source code in src/vkp80iii/printer.py
379 380 381 | |
black_mark_distance ¶
black_mark_distance(tenths_mm: int) -> Printer
Persisted in NVRAM -- set once during setup, not per ticket.
Source code in src/vkp80iii/printer.py
395 396 397 | |
barcode ¶
barcode(
symbology: Barcode | int,
data: bytes | str,
*,
height: int | None = None,
width: int | None = None,
hri: HRIPosition | int | None = None,
hri_font: HRIFont | int | None = None,
) -> Printer
Print a 1D barcode, optionally configuring height/width/HRI first.
Source code in src/vkp80iii/printer.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
qrcode ¶
qrcode(
data: bytes | str,
*,
module_size: int = 6,
ecc: QRErrorCorrection | int = QRErrorCorrection.M,
model: QRModel | int = QRModel.MODEL2,
version: int = 0,
) -> Printer
Configure and print a QR code in one call.
Source code in src/vkp80iii/printer.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 | |
pdf417 ¶
pdf417(
data: bytes | str,
*,
columns: int = 0,
rows: int = 0,
module_width: int = 3,
module_height: int = 3,
) -> Printer
Configure and print a PDF417 symbol.
Source code in src/vkp80iii/printer.py
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | |
aztec ¶
aztec(
data: bytes | str,
*,
module_size: int = 6,
type: AztecType | int = AztecType.FULL,
) -> Printer
Configure and print an AZTEC symbol.
Source code in src/vkp80iii/printer.py
469 470 471 472 473 474 475 476 477 478 479 480 481 | |
datamatrix ¶
datamatrix(
data: bytes | str,
*,
module_size: int = 6,
encoding: DataMatrixEncoding
| int = DataMatrixEncoding.AUTO,
) -> Printer
Configure and print a DataMatrix symbol.
Source code in src/vkp80iii/printer.py
483 484 485 486 487 488 489 490 491 492 493 494 495 | |
image ¶
image(
image: Image | str,
*,
max_width: int | None = None,
threshold: int | None = None,
dither: bool = True,
invert: bool = False,
mode: int = 0,
) -> Printer
Print a raster image (path or PIL image). Requires Pillow.
The image is downscaled to fit the paper width if wider. Tall images are
split into bands automatically, since a single GS v 0 is capped at
2047 rows. The left offset is applied in whole bytes -- if the configured
left_offset_dots is not a multiple of 8, the sub-byte remainder is
not shifted.
Source code in src/vkp80iii/printer.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 | |
print_logo ¶
print_logo(
number: int,
*,
justify: Justify | int = Justify.LEFT,
rotate: bool = False,
border_dots: int = 0,
position_dots: int | None = None,
) -> Printer
Print a logo stored in the printer's flash by its id.
Source code in src/vkp80iii/printer.py
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | |
upload_logo ¶
upload_logo(
number: int,
image: Image | str,
*,
name: str = "LOGO.BMP",
max_width: int | None = None,
threshold: int | None = 128,
dither: bool = False,
timeout: float = 8.0,
) -> bool
Store an image into flash as logo number (FS 0x94).
Returns True on success (the printer replies <PC1\xAA>), else raises
:class:~vkp80iii.exceptions.PrinterError.
IMPORTANT: the printer only re-reads its logo index on boot, so you must
power-cycle the printer once after uploading before :meth:print_logo
can find the new logo (otherwise it prints "FILE ERROR"). Flash has
limited write cycles -- upload during setup, not per print. Numbers 1/2
hold the factory demo logo; use your own (e.g. 200).
Source code in src/vkp80iii/printer.py
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 | |
led ¶
led(
rgb: tuple[int, int, int], *, persist: bool = False
) -> Printer
Set the bezel LED bar colour (FS L immediate).
Note: on some firmware the RGB colour is only visible while a ticket is
being presented/ejected; standalone the bar may show a default amber.
Use :meth:led_off (FS B) to turn it off / stop a flash.
Source code in src/vkp80iii/printer.py
598 599 600 601 602 603 604 605 | |
led_off ¶
led_off() -> Printer
Turn the LED bar off (stops any steady/flash/rainbow mode).
Source code in src/vkp80iii/printer.py
607 608 609 | |
setup_counter ¶
setup_counter(
start: int,
end: int,
*,
step: int = 1,
repeat: int = 1,
digits: int = 0,
align: str = "right",
pad_zero: bool = False,
) -> Printer
Configure the on-printer serial-number counter.
Source code in src/vkp80iii/printer.py
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 | |
print_counter ¶
print_counter() -> Printer
Queue the current counter value for printing, then advance it.
Source code in src/vkp80iii/printer.py
636 637 638 | |
density ¶
density(level: int = 0) -> Printer
GS | -- relative print darkness, level -2..+2 (12.5% steps; 0 = default).
Source code in src/vkp80iii/printer.py
652 653 654 655 656 | |
read_logs ¶
read_logs(timeout: float = 3.0) -> bytes
FS G 0 -- retrieve the flash-disk text log files (for remote diagnostics).
The printer first sends a 4-byte size, then that many log bytes.
Source code in src/vkp80iii/printer.py
658 659 660 661 662 663 664 665 666 667 | |
clear_logs ¶
clear_logs(timeout: float = 3.0) -> bool
FS G 1 -- delete the flash-disk log files. Returns True on ACK (0x06).
Source code in src/vkp80iii/printer.py
669 670 671 | |
status ¶
status(timeout: float = 1.0) -> FullStatus
Request and decode the full 6-byte status block.
Source code in src/vkp80iii/printer.py
676 677 678 679 680 681 | |
paper_status ¶
paper_status(timeout: float = 1.0) -> PaperStatus
Query the paper sensor (ESC v).
Source code in src/vkp80iii/printer.py
683 684 685 686 687 688 | |
is_ready ¶
is_ready(timeout: float = 1.0) -> bool
True if the printer reports it can print right now.
Returns False on no reply (StatusTimeout) or an unparseable/short
reply (PrinterError) rather than propagating.
Source code in src/vkp80iii/printer.py
690 691 692 693 694 695 696 697 698 699 | |
device_id ¶
device_id(timeout: float = 1.0) -> bytes
Return the 2-byte device model id (expected b'\x02\x05').
Source code in src/vkp80iii/printer.py
713 714 715 | |
enable_auto_status_back ¶
enable_auto_status_back(
*,
paper: bool = True,
user: bool = True,
recoverable: bool = True,
unrecoverable: bool = True,
) -> Printer
Make the printer push status automatically whenever it changes.
Source code in src/vkp80iii/printer.py
721 722 723 724 725 726 727 728 729 730 731 732 | |
read_auto_status ¶
read_auto_status(timeout: float = 1.0) -> FullStatus | None
Read one unsolicited automatic status-back frame, if pending.
The frame is 0x10 <mask> <enabled status bytes>: the mask's low four
bits (paper / user / recoverable / unrecoverable) say which category
bytes follow, in that order. Categories not enabled are reported as 0.
Returns None if no (valid) frame is pending.
Source code in src/vkp80iii/printer.py
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 | |