gilbertfl / escpos-netprinter

Emulator of a networked ESC/POS printer
GNU Affero General Public License v3.0
1 stars 1 forks source link

Deal with pre-print requests from POS systems #1

Open gilbertfl opened 6 months ago

gilbertfl commented 6 months ago

Many ESC/POS clients check the printer state or do setup before sending a print. In many cases, the print is not sent until the printer replied to status calls, leading to an empty print.

A typical example is the "handshake" added to version 2.0 after the beta release. The client sends b'\x1b\x40\x1b\x3d\x01\x10\x04\x01' and stops until it receives a byte as answer. Logging the communication with an Epson TM printer has shown that it replies b'\x16' then the client starts sending the receipt that is to be printed.

b'\x1b' is the ESC command which is used for printer control. Some ESC subcommands are used for print formatting; those commands are already dealt with in the escpos-php code.

We will have to add to the JetDirect service some basic ESC command handling to incite the clients to send the real print, without reimplementing the whole ESC/POS protocol in Python. We will also have to design a cutoff between the pre-print requests and print setup which should be sent to the backend.

gilbertfl commented 5 months ago

This has been partially addressed in this commit: DLE EOT requests for printer and paper status are now dealt with.

gilbertfl commented 4 months ago

Here is a list of candidate status codes. The current and obsolete commands are specified as blocking.

Current commands

  1. DLE EOT Transmit real-time status
  2. GS r Transmit status
  3. DLE DC4 <fn 7> Transmit specified status in real time
  4. GS I Transmit printer ID
  5. GS g 2 Transmit maintenance counter
  6. GS ( E <fn 1, 4, 6, 12, 14, 16, 50, 98 and 100> Set user setup commands
  7. GS ( H Request transmission of response or status This one may not be blocking?

Obsolete commands

  1. ESC u Transmit peripheral device status
  2. ESC v Transmit paper sensor status

Auto status back

These requests do not stop the printing, but a smart client may wait to get a clear status back before starting their print.

  1. FS ( e Enable/disable Automatic Status Back (ASB)
  2. GS a Enable/disable Automatic Status Back (ASB)
  3. GS j Enable/disable Automatic Status Back (ASB) for ink