Skip to content

Z90 Printer

The Z90Printer class is a concrete implementation of the POSPrinter interface specifically designed for the Z90 POS device. It provides functionality to print receipts or other documents on the Z90 device using the printer driver provided by the DriverManager.

Properties

  • printer: A lazily initialized property that holds the printer instance obtained from the DriverManager.

Methods

  • print(creator: ReceiptCreator): A suspending function that prints a receipt created by the provided ReceiptCreator. This function is designed to be called from a coroutine context.

print Method Details

The print method performs the following steps:

  1. Builds a bitmap representation of the receipt using the ReceiptCreator's build() method.
  2. Sets the alignment for appending the bitmap to the printer buffer to center.
  3. Creates a PrnStrFormat object with centered alignment and bold style for formatting strings.
  4. Appends a space and a newline character to the printer buffer using the formatted style.
  5. Starts the print job and checks the result.
  6. Based on the result of the print job, it either resumes the coroutine with an appropriate exception or proceeds with the next steps.

Exception Handling

The method includes exception handling for common printer issues such as:

  • Out of Paper: Throws an exception indicating that the printer is out of paper.
  • General Error: Throws an exception indicating a general error during printing.
  • Overheating: Throws an exception indicating that the printer is overheating.
  • Fault: Throws an exception indicating a fault with the printer.

Usage

To use the Z90Printer class, create an instance of the class and call the print method with a ReceiptCreator object that defines the content to be printed. This method should be called from a coroutine scope to ensure proper asynchronous execution.

kotlin
val z90Printer = Z90Printer()

val receiptCreator = // ... obtain or create a ReceiptCreator instance

launch {
    z90Printer.print(receiptCreator)
}

This documentation provides an overview of the Z90Printer class, its properties, methods, and exception handling for printing tasks on the Z90 POS device.