Let the printer client wait for the printer to confirm a job
A write to the printer's socket returns once the operating system holds the bytes, not once the printer has them. On the TM-T88IV with its cover open, Windows took all of a 128 KB receipt into its send buffer at once, so the job read done; once the cover closed, only its first third printed, without its cut, and the printer was left inside the image command, waiting for the rest. With the new option printer.Confirm(true), Send asks for status with GS r 1, which the printer answers only once it has run every byte before it, and, on the TM-T88IV, only while it can print: - Before beforeWrite, it sends DLE EOT 1, GS a 0 and GS r 1 in one write. The printer answers DLE EOT on receipt, ahead of anything it receives after it, so the answer is a fence: every byte before it left the printer before the request reached it, and Send drops it. That takes care of answers owed to requests the printer ran on an earlier connection or for an earlier run of the daemon, of the last bytes of a status block whose header went to an earlier connection, and of late DLE EOT answers, however long a lost segment holds the request back. Send waits for the fence until the write timeout or the context's deadline, then for an answer to GS r 1 after it. Without them, as with the cover open, no paper, or a printer stuck inside an earlier job, Send returns a plain error with nothing of the job written, as after a failed dial. Requests still queued in the printer ahead of this one are answered after the fence too, and answers carry nothing that tells them apart, so the wait reads every answer until 100 ms have passed since the last and drops them all, and none can be taken for a later job's confirmation. Each job waits those 100 ms. Only answers keep the wait open, so status blocks cannot, and a wait that the deadline or the connection's end cuts short counts as not ready, as one without an answer does. A printer may run GS r 1 while offline, so Send then asks DLE EOT 1 again, for up to 2 s, and writes the job only if the printer answers that it is online. Last, it reads on for 100 ms. Once the answers have settled none is owed, so an answer to GS r 1 during the online check or after it means one taken for the ready answer was not, as when a late DLE EOT answer from an earlier connection stood in for the fence and an owed answer followed it; Send then returns a plain error with nothing written, and the job is tried again. A cancellation stops the wait at once: it sets a flag that every reset of the read deadline checks, and the wait returns only once a cancellation that raced its end has finished with the connection. - After the job, it sends GS a 0 and GS r 1 again and returns once the answer arrives. If it does not arrive before the write deadline, or the connection fails or closes after the job was written in full, Send returns an *UnconfirmedError: the job may have printed in full, in part or not at all. The error has an Unconfirmed method, so the queue can tell it apart without importing the package. Automatic status blocks are what GS a 0 is for. The UB-E02 and UB-E03 boards turn them on at power-on, and a job's own ESC @ does not turn them off on a TM-T88VII with DIP switch 2-1 on. A block's last three bytes have an answer's fixed bits (bits 4 and 7 clear), and the board can send them on the next connection, where they would stand for the ready answer. The printer runs GS a 0 in order, so no block follows the answer to a GS r 1 sent after it. Blocks that come before it are passed over by their header's fixed bits: each connection keeps its place in a block across reads, and once Send has the confirmation it reads on for up to 100 ms for the rest of a block it ended inside. A block cut short ends with its connection, and last bytes that still begin a connection, before the first job after a power-on has turned blocks off, come before the fence's answer and are dropped. Status sends no GS a 0, which the printer does not run while it is offline. It passes over blocks, answers to DLE EOT n that a job's own bytes hold, and a late answer to GS r 1, and before it closes it reads what has come, to the end of any block, so that the next connection gets none of it. It returns ErrStatusUnsupported at once on a byte that fits no answer, and within 100 ms when a byte like an answer to GS r is not followed by an answer to DLE EOT, rather than after its 2 s. The printers plan and the job-store plan say so. The TM-T88IV answered GS r 1 with 0x00 within 4 ms when asked on its own. Nothing turns the option on yet. Tests pin the bytes Send sends with the option on, refuse a printer that answers DLE EOT 1 as offline, put an owed answer, a block's last bytes or both before the fence and delay the ready answer behind it, as after a lost segment or while the printer feeds and cuts at cover close, answer the ready request after an answer owed to an earlier run, and after one owed since a job's own GS r 1, split a status block across reads and across a confirmation and the 50 ms after it, and put owed answers around a block; in each, Send waits for the job's own answer. Others cut a block short and find the next jobs and Status unharmed, send a cover-open block in place of the ready answer, start a connection with the last bytes of a block whose header came after a confirmation, before the confirmation's deadline, with the confirmation at the write deadline, before the ready deadline or after Status's last answer, and find nothing written to a printer with its cover open. Others cut the ready wait short by its deadline and find nothing written, send status blocks every 50 ms and find the job sent and confirmed, and answer DLE EOT with bytes that are not DLE EOT answers and find Status unsupported within 100 ms. Others flood the online check with bytes like answers and Status with status blocks, and find both bounded, and turn the option off and find the job's bytes sent alone. Others put a late DLE EOT answer and an owed answer ahead of a held-back request, or an answer during the online check, and find nothing written; cancel during a steady stream and a flood of answers and find the wait stops at once; and play two cases the client leaves open, a long pause between queued answers and a fence answer between a block's last bytes, logging how they end. Part of stage 1d of docs/plans/job-store.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5cc4614ad7
commit
9376653e1a
6 files changed
+2030
-18
No files matched your search
@@ -200,9 +200,9 @@ For stage 4a:
|
||||
28. **The TM-T88VII's near-end through `GS r 1`.** `Status` sends it last, only when `DLE EOT` says online and ready, under a deadline of its own, 500 ms. The anycast check (decision 23) never sends it.
|
||||
- Its reply has a decoder of its own, since its fixed bits differ from `DLE EOT`'s and `Status.Apply` would refuse it. The decoder accepts the byte the TM-T88VII actually sends, since Epson's page contradicts itself.
|
||||
- No answer means near-end is unknown: `paper` reads as `DLE EOT 4` gave it, never `timeout`, never `503`.
|
||||
- The connection closes after a missed answer, since a late one could be read as the answer to the next request. Closing does not stop a late reply: the board, not TCP, routes the printer's output, so the reply can reach the next connection. There it fails the `DLE EOT` mask, since its bits 0 and 1 are both clear or both set, and reads once as unsupported (`unknown`, `200`).
|
||||
- Trade-off: `GS r 1` is not real-time. It is answered once the lines before it have printed, so during a long print it is usually missed. A late reply costs one `unknown` reading.
|
||||
29. **More status bits, and frames nobody asked for.** `Ready()` also counts `DLE EOT 2` bit 6 (an error occurred) and `DLE EOT 3` bit 2 (a recoverable error; the TM-T88IV lacks it), read again like the rest. `Normalized()` clears `DLE EOT 2` bit 6 while `DLE EOT 1` says online, as it clears that byte's other bits, so a stale bit while cutting does not read as not ready. On the TM-T88VII the autocutter-error bit also means a paper jam; api.md says so. Automatic-status frames are left alone until stage 4a's first step shows whether they reach a port 9100 client. The UB-E02 and UB-E03 boards turn them on at power-on, and a TM-T88VII with DIP switch 2-1 on keeps them on. If they do reach the client, job-store phase 5's frame reader comes forward.
|
||||
- The connection closes after a missed answer, since a late one could be read as the answer to the next request. Closing does not stop a late reply: the board, not TCP, routes the printer's output, so the reply can reach the next connection. There it fails the `DLE EOT` mask, since its bits 0 and 1 are both clear or both set, so `Status` passes over it, and `Send`'s ready wait drops it with its own answer when it comes within 100 ms of that answer.
|
||||
- Trade-off: `GS r 1` is not real-time. It is answered once the lines before it have printed, so during a long print it is usually missed. A late reply costs nothing: one the printer sent before the next connection's requests reached it comes ahead of the answer to the `DLE EOT 1` that opens that connection, and is dropped with everything before it, and one still queued comes just before the answer to the ready request, and is dropped with it.
|
||||
29. **More status bits, and frames nobody asked for.** `Ready()` also counts `DLE EOT 2` bit 6 (an error occurred) and `DLE EOT 3` bit 2 (a recoverable error; the TM-T88IV lacks it), read again like the rest. `Normalized()` clears `DLE EOT 2` bit 6 while `DLE EOT 1` says online, as it clears that byte's other bits, so a stale bit while cutting does not read as not ready. On the TM-T88VII the autocutter-error bit also means a paper jam; api.md says so. `Status` and `Send` pass over automatic-status frames, by the fixed bits of a frame's first byte, so a frame that reaches a port 9100 client reads neither as unsupported nor as an answer to `GS r 1`. The UB-E02 and UB-E03 boards turn them on at power-on, and a TM-T88VII with DIP switch 2-1 on keeps them on. With confirmation, `Send` opens each connection with `DLE EOT 1`, `GS a 0` and `GS r 1` and drops everything that comes before the `DLE EOT` answer, a frame's leftover bytes included, turns frames off again before the job's confirmation request, and asks `DLE EOT 1` again before it writes; `Status` reads to the end of any frame before it closes. Stage 4a's first step shows whether they reach the client; job-store phase 5's frame reader replaces the skipping.
|
||||
- Trade-off: `/healthz` can answer `503` on a recoverable error where it answered `200`.
|
||||
|
||||
For stage 4b:
|
||||
@@ -302,7 +302,7 @@ THE THREE PRINTERS (Epson's Technical Reference Guides and command reference)
|
||||
- Every command the renderer sends is in each model's command list, and so are the code pages it uses (0, 2, 16 and 19). Each job starts with `ESC @` then `ESC t`, so a printer's own default page never matters.
|
||||
- The TM-m50II's command list includes `GS ( H` fn 48, which job-store.md lists as unconfirmed for it. It is still unverified over port 9100.
|
||||
- Only the first accepted connection prints; the others connect, and their data waits until it closes.
|
||||
- The UB-E02 and UB-E03 turn automatic status on at power-on; a job's `ESC @` turns it off. A TM-T88VII with DIP switch 2-1 on keeps it on after `ESC @`. A frame's first byte fails the `DLE EOT` mask, so `Status` would read it as "unsupported".
|
||||
- The UB-E02 and UB-E03 turn automatic status on at power-on; a job's `ESC @` turns it off. A TM-T88VII with DIP switch 2-1 on keeps it on after `ESC @`. A frame's first byte fails the `DLE EOT` mask, and `Status` passes over the frame by it.
|
||||
- A byte string inside a command's parameters that matches a real-time command is executed as one: image or `raw` bytes that hold `10 04 n` make the printer send a status byte during a send.
|
||||
- Buffers:
|
||||
- Each model keeps a receive buffer per interface.
|
||||
@@ -1060,7 +1060,7 @@ internal/app/uberbringer
|
||||
|
||||
First, before any code, with the owner's OK. These are status reads only, nothing printed, and they settle the details of decisions 28 and 29:
|
||||
1. On the TM-T88VII: the `GS r 1` reply byte with a full roll, and with a roll past the near-end mark if he has one, read by a probe run from outside the repository.
|
||||
2. On the TM-T88IV just after power-on, and on the TM-T88VII with DIP switch 2-1 as it is set: does `/healthz` read `unknown`, a sign that automatic-status frames reach the connection?
|
||||
2. On the TM-T88IV just after power-on, and on the TM-T88VII with DIP switch 2-1 as it is set: do automatic-status frames reach the connection? A probe run from outside the repository reads the raw bytes, since `Status` passes over the frames and `/healthz` does not show them. It also shows whether a frame's four bytes ever arrive apart, and checks what `Send` assumes (design.md): that no frame follows the answer to a `GS r 1` sent after `GS a 0`, that `DLE EOT 1` is answered ahead of a `GS r 1` sent just after it, and that no answer to `DLE EOT` comes between a frame's bytes. One between the last bytes of a frame whose header went to an earlier connection would let those bytes count as answers to `GS r 1`; within one connection the header keeps them apart. On the TM-m50II it also reads `DLE EOT 1` and `GS r 1` during the auto feed and cut at cover close, to see whether the printer reports online before it has run a queued `GS r 1`.
|
||||
3. The TM-T88VII's status sheet, read by the owner: column mode, paper width, paper reduction, top margin, the port 9100 time-out and DIP switch 2-1 (decision 31).
|
||||
|
||||
internal/pkg/escpos
|
||||
|
||||
Reference in new issue
Block a user