ESC/P2

The Developer's Guide to Gutenprint
Prev |  | Next

# Chapter 5. ESC/P2

This is a description of the ESC/P2 raster commands used by the Gutenprint printer driver, which is a subset of the complete command set. Note that these are not always correct, and are certainly not complete.

All ESCP/2 raster commands begin with the `ESC` character (0x1b), followed by either one or two command characters and arguments where applicable. Older commands generally have one command character. Newer commands usually have a ‘`(`’ (left parenthesis) followed by a command character and a byte count for the arguments that follow. The byte count is a 16-bit (2 byte) binary integer, in little endian order.

All arguments listed here are of the form `name[bytes]` where `[bytes]` is the number of bytes that comprise the argument. The arguments themselves are usually one, two, or four byte integers, always little endian (the least significant bits come first). Presumably this is to match Intel processors.

In some cases, the same command sequence identifies different versions of the same command, depending upon the number of bytes of arguments.

# Standard commands

ESC/P2 Commands

`ESC @`

  Reset the printer. Discards any output, ejects the existing page, returns all settings to their default. Always use this before printing a page.

`ESC (G `BC`=1 `ON1``

  Turn on graphics mode. `ON` should be `1` (turn on graphics mode).

`ESC (U `BC`=1 `UNIT1``

  Set basic unit of measurement used by printer. This is expressed in multiples of 1/3600". At 720 DPI, `UNIT` is `5`; at 360 DPI, `UNIT` is `10`.

`ESC (U `BC`=5 `PAGEUNITS1` `VUNIT1` `HUNIT1` `BASEUNIT2``

  Set basic units of measurement used by the printer. `PAGEUNIT` is the unit of page measurement (for commands that set page dimensions and the like). `VUNIT` is the unit of vertical measurement (for vertical movement commands). `HUNIT` is the unit of horizontal movement (for horizontal positioning commands). All of these units are expressed in `BASEUNIT`, which is in reciprocal inches. Typically, `BASEUNIT` is `1440`. In 720 DPI mode, `PAGEUNIT`, `VUNIT`, and `HUNIT` are all `2`; in 1440×720 DPI mode, `PAGEUNIT` and `VUNIT` are normally set to `2`; `HUNIT` is set to `1`.

`ESC (K `BC`=2 `ZERO1` `GRAYMODE1``

  Set color or grayscale mode, on printers supporting an explicit grayscale mode. These printers can be identified because they are advertised as having more black nozzles than nozzles of individual colors. Setting grayscale mode allows use of these extra nozzles for faster printing. `GRAYMODE` should be `0` or `2` for color, `1` for grayscale. `ZERO` should always be `0`.

`ESC (i `BC`=1 `INTERLEAVE1``

  If `INTERLEAVE` is `1`, use printer interleave mode (referred to by Epson as "MicroWeave". On older printers, this is used to turn on printer interleave; on newer printers, it prints one row at a time. All printers support this mode. It should only be used at 720 (or 1440×720) DPI. The Epson Stylus Pro series indicates additional modes (with additional optionss on newer ones):

  `2`

    “Full-overlap”

  `3`

    “Four-pass”

  `4`

    “Full-overlap 2”

  Any of these commands can be used with the high four bits set to either `3` or `0`.

`ESC U `DIRECTION1``

  If `DIRECTION` is `1`, print unidirectionally; if `0`, print bidirectionally.

`ESC (s `BC`=1 `SPEED1``

  On some older printers, this controls the print head speed. `SPEED` of `2` is 10 inches/sec; `SPEED` of `0` or 1 is 20.

`ESC (e `BC`=2 `ZERO1` `DOTSIZE1``

  Choose print dotsize. `DOTSIZE` can take on various values, depending upon the printer. Almost all printers support `0` and `2`. Variable dot size printers allow a value of `16`. Other than the value of `16`, this appears to be ignored at resolutions of 720 DPI and above.

`ESC (C `BC`=2 `PAGELENGTH2``, `ESC (C `BC`=4 `PAGELENGTH4``

  Set the length of the page in “pageunits” (see `ESC (U` above). The second form of the command allows setting of longer page lengths on new printers (these happen to be the printers that support variable dot size).

`ESC (c `BC`=4 `TOP2` `LENGTH2``, `ESC (c `BC`=8 `TOP4` `LENGTH4``

  Set the vertical page margins of the page in “pageunits” (see `ESC (U` above). The margins are specified as the top of the page and the length of the page. The second form of the command allows setting of longer page lengths on new printers (these happen to be the printers that support variable dot size).

`ESC (S `BC`=8 `WIDTH4` `LENGTH4``

  Set the width and length of the printed page region in “pageunits” (see `ESC (U` above).

`ESC (v `BC`=2 `ADVANCE2``, `ESC (v `BC`=4 `ADVANCE4``

  Feed vertically `ADVANCE` “vertical units” (see `ESC (U` above) from the current print head position.

`ESC (V `BC`=2 `ADVANCE2``, `ESC (V `BC`=4 `ADVANCE4``

  Feed vertically `ADVANCE` “vertical units” (see `ESC (U` above) from the top margin.

`ESC ($ `BC`=4 `OFFSET4``

  Set horizontal position to `OFFSET` from the left margin. This command operates on printers of the 740 class and newer (all printers with variable dot size).

`ESC $ `OFFSET2``

  Set horizontal position to `OFFSET` from the left margin. This command operates on printers of the 740 class and newer (all printers with variable dot size).

`ESC (\ `BC`=4 `UNITS2` `OFFSET2``

  Set horizontal position to `OFFSET` from the previous print head position, measured in `UNITS`. `UNITS` is measured in inverse inches, and should be set to 1440 in all cases. This operates on all 1440 dpi printers that do not support variable dot size.

`ESC (/ `BC`=4 `OFFSET4``

  Set horizontal position to `OFFSET` from the previous print head position, measured in “horizontal units” (see `ESC (U` above). This operates on all variable dot size printers.

`ESC \ `OFFSET2``

  Set horizontal position to `OFFSET` from the previous print head position, measured in basic unit of measurement (see `ESC (U` above). This is used on all 720 dpi printers, and can also be used on 1440 dpi printers in lower resolutions to save a few bytes. Note that `OFFSET` may be negative. The range of values for this command is between `-16384` and `16383`.

`ESC r `COLOR1``, `ESC (r `BC`=2 `DENSITY1` `COLOR1``

  Set the ink color. The first form is used on four-color printers; the second on six-color printers. `DENSITY` is `0` for dark inks, `1` for light. `COLOR` is

  Table 5-1. Colors

  `COLOR` | Color name
  --- | ---
  `0` | Black
  `1` | Magenta
  `2` | Cyan
  `4` | Yellow

  This command is not used on variable dot size printers in softweave mode.

`ESC . `COMPRESS1` `VSEP1` `HSEP1` `LINES1` `WIDTH2` data...`

  Print data. `COMPRESS` signifies the compression mode.

  Table 5-2. Compression modes

  `COMPRESS` | Compression mode
  --- | ---
  `0` | No compression
  `1` | TIFF compression (incorrectly documented as “run length encoded”)
  `2` | TIFF compression with a special command set.

  `VSEP` depends upon resolution and printer type. At 360 DPI, it is always `10`. At 720 DPI, it is normally `5`5. On the ESC 600, it is `40` (8 × 5}). On some other printers, it varies.

  `HSEP1` is `10` at 360 DPI and `5` at 720 or 1440 DPI (1440 DPI cannot be printed in one pass; it is printed in two passes, with the dots separated in each pass by 1/720").

  `LINES` is the number of lines to be printed. It should be `1` in printer interleave and 360 DPI. At 720 DPI softweave, it should be the number of lines to be actually printed.

  `WIDTH` is the number of pixels to be printed in each row. Following this command, a carriage return (`13` decimal, `0A` hex) should be output to return the print head position to the left margin.

  The basic data format is a string of bytes, with data from left to right on the page. Within each byte, the highest bit is first.

  The TIFF compression is implemented as one count byte followed by one or more data bytes. There are two cases:

  1. If the count byte is `128` or less, it is followed by ([count] + 1) data bytes. So if the count byte is `0`, it is followed by 1 data byte; if it is `128`, it is followed by 129 data bytes.

  2. If the count byte is greater than 128, it is followed by one byte. This byte is repeated (257 - [count]) times. So if [count] is 129, the next byte is treated as though it were repeated 128 times; if [count] is 255, it is treated as though it were repeated twice.

`ESC i `COLOR1` `COMPRESS1` `BITS1` `BYTES2` `LINES2` data...`

  Print data in the newer printers (that support variable dot size), and Stylus Pro models. `COLOR` is the color.

  Table 5-3. Extended Colors

  `COLOR` | Color name
  --- | ---
  `0` | Black
  `1` | Magenta
  `2` | Cyan
  `4` | Yellow
  `5` | Alternate black (Stylus C70/C80)
  `6` | Alternate black (Stylus C70/C80)
  `16` | Gray (“light black”)
  `17` | Light magenta
  `18` | Light cyan

  `COMPRESS` signifies the compression mode:

  Table 5-4. Compression modes

  `COMPRESS` | Compression mode
  --- | ---
  `0` | No compression
  `1` | TIFF compression (incorrectly documented as “run length encoded”)
  `2` | TIFF compression with a special command set, or “run length encoding 2” on some printers.

  `BITS` is the number of bits per pixel.

  `BYTES` is the number of bytes wide for each row (ceiling(BITS × width_of_row, 8)}). Note that this is different from the `ESC .` command above.

  `LINES` is the number of lines to be printed. This command is the only way to get variable dot size printing. In variable dot mode, the size of the dots increases as the value (`1`, `2`, or `3`) increases.

`ESC (D `BC`=4 `BASE2` `VERTICAL1` `HORIZONTAL1``

  Set printer horizontal and vertical spacing. It only applies to variable dot size printers in softweave mode (and possibly other high end printers).

  `BASE` is the base unit for this command; it must be `14400`.

  `VERTICAL` is the distance in these units between printed rows; it should be ((separation_in_nozzles × `BASE` ÷ 720).

  `HORIZONTAL` is the horizontal separation between dots in a row. Depending upon the printer, this should be either (14400 ÷ 720) or (14400 ÷ 360). The Stylus Pro 9000 manual suggests that the settings should match the chosen resolution, but that is apparently not the case (or not always the case) on other printers.

`ESC (R `BC`=8 00 R E M O T E 1`

  Enters “remote mode”. This is a special, undocumented command set that is used to set up various printer options, such as paper feed tray, and perform utility functions such as head cleaning and alignment. It does not appear that anything here is actually required to make the printer print. Our best understanding of what is in a remote command sequence is described in a separate section below.

`ESC 01 @EJL [sp] ID\r\n`

  Return the printer ID. This is considered a remote mode command, although the syntax is that of a conventional command. This returns the following information:

      @EJL ID\r
      MFG:EPSON;
      CMD:ESCPL2,BDC;
      MDL:[printer model];
      CLS:PRINTER;
      DES:EPSON [printer model];
      \f

  After all data has been sent, a form feed byte should be sent.

All newer Epson printers (STC 440, STP 750) require the following command to be sent at least once to enable printing at all. This command specifically takes the printer out of the 1284.4 packet mode communication protocol and enables normal data transfer. Sending it multiple times is is not harmful, so it is normally sent at the beginning of each job:

    ESC 01@EJL[space]1284.4[newline]@EJL[space][space][space][space]
    [space][newline]ESC@

The proper sequence of initialization commands is:

    magic command
    ESC @
    remote mode if needed
    ESC (G
    ESC (U
    ESC (K (if appropriate)
    ESC (i
    ESC U (if needed)
    ESC (s (if appropriate)
    ESC (e
    ESC (C
    ESC (c
    ESC (S
    ESC (D (if needed)
    ESC (V (optional -- this can be accomplished with ESC (v)

For printing, the proper sequence is:

    ESC (v

and repeat for each color:

    ESC ($ or ESC (\ or ESC \
    ESC (r or ESC r (if needed---not used with "ESC i" and not needed if the color
    has not changed from the previous printed line)
    ESC . or ESC i  ...data... [return] (0A hex)

To terminate a page:

    [formfeed] (0C hex)
    ESC @

Prev | Home | Next
The driver file |  | Remote Mode Commands