> ## Documentation Index
> Fetch the complete documentation index at: https://docs.plato.ae/llms.txt
> Use this file to discover all available pages before exploring further.

# Console Integration

> How Plato Console talks to the PC printer driver.

# Console Integration

Plato Console uses the `WIN_DRIVER` printer adapter for the PC printer driver.

## Printer Record

Console stores printers in an IndexedDB database named `printer-database`.

Printer records include:

* printer type
* status
* last error
* config
* paper width
* categories
* order types
* logo

Relevant type:

```ts theme={null}
type PrinterType =
  | "EPSON"
  | "WIN_DRIVER"
  | "USB"
  | "BUILT_IN"
  | "ANDROID_DRIVER"
  | "SUNMI";
```

## Driver URL

The `WIN_DRIVER` adapter builds its base URL from printer config:

```txt theme={null}
http://<driverIpAddress>:<driverPort>
https://<driverIpAddress>:<driverPort>
```

If `driverPort` is empty, the adapter omits the port. This is useful for HTTPS on port `443`.

## Printer Target

The adapter sends the physical printer target separately from the driver URL.

| Config Field      | Request Field | Notes                                |
| ----------------- | ------------- | ------------------------------------ |
| `driverIpAddress` | URL host      | Machine running `plato-printer.exe`. |
| `driverPort`      | URL port      | Driver HTTP/HTTPS port.              |
| `driverUseHttps`  | URL protocol  | Uses `https` when true.              |
| `ipAddress`       | `ip_address`  | Physical printer IP.                 |
| `port`            | `port`        | Physical printer TCP port.           |
| `vendor`          | `vendor_id`   | Mapped vendor ID.                    |
| `productId`       | `product_id`  | Sent for compatibility.              |
| `beep`            | `beep`        | Enables post-print beep sequence.    |

If the printer IP is missing or equals `192.168.0.0`, the adapter sends `ip_address: null` and `port: null`, which the current driver rejects with `Missing printer address`.

## Vendor IDs

The adapter maps vendors:

| Vendor    | Vendor ID |
| --------- | --------- |
| `EPSON`   | `0x04b8`  |
| `BIRCH`   | `0x1fc9`  |
| `PHILIPS` | `0x0471`  |
| `SUNMI`   | `0x04b8`  |
| `OSCAR`   | `0x04b8`  |

## Print Preparation

Console print flow:

1. Render DOM to PNG blob.
2. Load blob into canvas.
3. Convert canvas pixels to black/white raster rows.
4. Split raster rows into 128-row chunks.
5. Encode each chunk as ESC/POS raster bytes.
6. Base64 encode each byte chunk.
7. Send `POST /print`.

The driver never receives HTML. It receives printable ESC/POS chunks.

## Browser Queue

Console has a local browser queue before requests reach the PC driver.

* Jobs are stored in IndexedDB.
* Jobs move from `pending` to `printing`.
* Failed jobs are marked `failed`.
* A stale `printing` job is recovered after 60 seconds.
* Scheduled jobs are checked every 30 seconds.
* Failed jobs are retried every 60 seconds.

The PC printer driver has its own Redis queue after the HTTP request is accepted. That means there are two queues:

| Queue         | Location                | Purpose                                                       |
| ------------- | ----------------------- | ------------------------------------------------------------- |
| Browser queue | Plato Console IndexedDB | Keeps POS-side print jobs until a driver accepts them.        |
| Driver queue  | Redis/BullMQ            | Keeps accepted jobs until the physical printer receives them. |

## Status Mapping

Console calls `POST /status`.

* HTTP failure returns `OFFLINE`.
* Response with `ok: true` and `status` not `offline` returns `ONLINE`.
* Other driver responses are stored as `lastError`.

## Cash Drawer

Console calls `POST /cash-drawer` for every online printer configured with a cash drawer.
