Data Characters and Escape Sequences

The default character set of all POS printers is assumed to support at least the ASCII characters 0x20 through 0x7F, which include spaces, digits, uppercase, lowercase, and some special characters. If the printer does not support lowercase characters, then the Service may translate them to uppercase.

Every escape sequence begins with the escape character ESC, whose value is 27 decimal, followed by a vertical bar ( | ). This is followed by zero or more digits and/or lowercase alphabetic characters. The escape sequence is terminated by an uppercase alphabetic character.

If a sequence does not begin with ESC "|", or it begins with ESC "|" but is not a valid UnifiedPOS escape sequence, the Service will make a reasonable effort to pass it through to the printer. However, not all such sequences can be distinguished from printable data, so unexpected results may occur.

Starting with Release 1.11, the application can use the ESC|#E escape sequence to ensure more reliable handling of the amount of data to be passed through to the printer. Use of this escape sequence will make an application non-portable. The application may, however, maintain portability by performing Embedded Data Escape sequence calls within conditional code. This code may be based upon the value of the DeviceServiceDescription, the PhysicalDeviceDescription, or the PhysicalDeviceName property.

NOTE: This command sequence definition and the corresponding definition in the Point Card Reader Writer Chapter, are the only known deviations from preserving the interchangeability of devices defined in this specification. If an application finds it necessary to utilize this command sequence, please inform the UnifiedPOS Committee (www.nrfarts. org) with the details of its usage, so that a possible standard/generic Application Interface may be incorporated into a future release of the UnifiedPOS Standard. In order to preserve peripheral independence and interoperability at the Application level, it is the Committee's position that this command sequence should be used only as a "last resort".

The following escape sequences are recognized. If an escape sequence specifies an operation that is not supported by the printer station, then it is ignored.

Commands - Perform indicated action.

Name                                                       Data                                       Remarks

Paper Cut                                              ESC |#P                      Cuts receipt paper. The character # is replaced by an ASCII

                                                                                                      decimal string telling the percentage cut desired. If # is

                                                                                                      omitted, then a full cut is performed. For example: The C string

                                                                                                       "\x1B|75P" requests a 75% partial cut.


Feed and Paper cut                              ESC |#fp                    Cuts receipt paper, after feeding the paper by the

                                                                                                      RecLinesToPaperCut lines. The character # is defined by

                                                                                                      the "Paper cut" escape sequence.


Print bitmap                                            ESC |#B                    Prints the pre-stored bitmap. The character # is replaced by

                                                                                                     the bitmap number. See setBitmap method.


Print top logo                                          ESC |tL                     Prints the pre-stored top logo.


Print bottom logo                                   ESC |bL                    Prints the pre-stored bottom logo.


Feed lines                                               ESC |#lF                   Feed the paper forward by lines. The character # is replaced by

                                                                                                     an ASCII decimal string telling the number of lines to be fed. If #

                                                                                                      is omitted, then one line is fed.


Feed units                                               ESC |#uF                 Feed the paper forward by mapping mode units. The character #

                                                                                                     is replaced by an ASCII decimal string telling the number of

                                                                                                     units to be fed. If # is omitted, then one unit is fed.


Pass through embedded data (See   ESC |#E                   Send the following # characters of data through to the hardware

 "a" below)                                                                                without modifying it. The character '#' is replaced by an ASCII

                                                                                                     decimal string telling the number of bytes following the escape

                                                                                                     sequence that should be passed through as-is to the hardware.

                                                                                                     Restriction:

                                                                                                     Due to implementation details the amount of data passed to the

                                                                                                     printer through this escape sequence is limited to 3.5K. In order

                                                                                                     to reach this maximum, this escape sequence must be the only

                                                                                                     command in the print request. If the amount of data exceeds

                                                                                                     3.5K, then the data maybe corrupted by the JavaPOS Service Object

                                                                                                     inserting a buffered status request into the data stream.          


a. This escape sequence is only available in version 1.7 and later.


Print Mode - Characteristics that are remembered until explicitly changed.

Name                                                      Data                                       Remarks


Font typeface selection                     ESC |#fT                      Selects a new typeface for the following data. Values for the

                                                                                                     character # are:

                                                                                                    0 = Default typeface.

                                                                                                    1 = Select first typeface from the FontTypefaceList property.

                                                                                                    2 = Select second typeface from the FontTypefaceList property. And so on.


Print Line - Characteristics that are reset at the end of each print method or by a "Normal" sequence.

Name                                                     Data                                        Remarks


Bold                                                      ESC |bC                     Prints in bold or double-strike.


Underline                                            ESC |#uC                   Prints with underline. The character # is replaced by an ASCII

                                                                                                   decimal string telling the thickness of the

                                                                                                   underline in printer dot units. If # is omitted, then a

                                                                                                   printer-specific default thickness is used.


Italic                                                     ESC |iC                       Prints in italics.


Alternate Color (Custom)                ESC |#rC                   Prints using an alternate custom color. The character # is

                                                                                                  replaced by an ASCII decimal string indicating the desired color.

                                                                                                  The value of the decimal string is equal to the value of the

                                                                                                  cartridge constant used in the printer device properties. If # is

                                                                                                  omitted, then the secondary color (Custom Color 1) is selected.

                                                                                                  Custom Color 1 is usually red.


Reverse Video                                   ESC |rvC                    Prints in a reverse video format.

Single high & wide                            ESC |1C                    Prints normal size.


Double wide                                      ESC |2C                     Prints double-wide characters.


Double high                                       ESC |3C                     Prints double-high characters.


Double high & wide                          ESC |4C                     Prints double-high/double-wide characters.


Scale horizontally                              ESC |#hC                  Prints with the width scaled # times the normal size,

                                                                                                  where # is replaced by an ASCII decimal string.


Scale vertically                                   ESC |#vC                   Prints with the height scaled # times the normal size, where #

                                                                                                  is replaced by an ASCII decimal string.


Center                                                 ESC |cA                      Aligns following text in the center.


Right Justify                                       ESC |rA                      Aligns following text at the right.


Normal                                               ESC |N                       Restores printer characteristics to normal condition.


a. These escape sequence are only available in version 1.5 and later.

Escape Sequences to Control the Two-Sided Functionality within a Mode


The following escape sequences are used to control the two-sided functionality through JavaPOS. These escape sequences take advantage of the JavaPOS "Pass through embedded data" escape sequence. All of these escape sequences must be wrapped by this "Pass through embedded data ESC|#E" to be recognized.


The values set by these escape sequences are only valid for the current instance of the JavaPOS service. If the device is set to disabled, then the configured settings are restored on the next enable.

The functionality provided by these escape sequences depends on the current TST2SideMode configuration setting. For some settings, they may be ignored and have no effect. All numeric parameters are ASCII characters for numeric values.

Escape Sequence                           Functionality                                          Possible Values
ESC [2ST; 1; 1; n !v                         Sets the front side print                        n = 0 : No rotation of printing

                                                            orientation                                                 = 1 : 180-degree rotation (upside down)


ESC [2ST; 1; 2; n !v                         Sets the back side print                       n = 0 : No rotation of printing

                                                           orientation                                                   = 1 : 180-degree rotation (upside down)


ESC [2ST; 1; 3; n !v                         Switches Front / Back                           n = 0 : Normal (front side faces toward front of the printer)

                                                           printing                                                         = 1 : Swapped (front side faces away from the front of the printer)


ESC [2ST; 1; 4; n !v                         Enables / disables predefined            n = 0 : Disable

                                                            Reprint on Error message                   = 1 : Enable


ESC [2ST; 2; 1; n !v                         Enables / disables predefined            n = 0 : Disable

                                                            Bottom Front message                         = 1 : Enable


ESC [2ST; 2; 2; n !v                         Enables / disables predefined            n = 0 : Disable

                                                           Top Back message                                   = 1 : Enable


ESC [2ST; 2; 3; x; y; z !v                 Sets attributes for a                                 x = 0 : Front

                                                          predefined Bottom Front /                         = 1 : Back

                                                          Top Back / Reprint message                   = 2 : Reprint

                                                                                                                               y = 1 : First Line

                                                                                                                                  = 2 : Second Line

                                                                                                                                z = 0x1 : Double High

                                                                                                                                       0x4 : Double Wide

                                                                                                                                       0x10 : Emphasize Mode

                                                                                                                                       0x40 : 1 Dot Underline Mode

                                                                                                                                       0x100 : Inverse Video

                                                                                                                                       0x400 : Italic

                                                                                                                                       0x1000 : 2 Dot Underline Mode

                                                                                                                                       0x4000 : Alternate Color

                                                                                                                                Adding all attribute values together would equal to

                                                                                                                                0x5555.

                                                                                                                                NOTE: Parameter z is coded as ASCII characters, but

                                                                                                                                they represent a Hex-based number.


ESC [2ST; 2; 4; x; y !v [text]             Sets the string for a                                     x = 0 : Front

                                                            predefined Bottom Front /                            = 1 : Back

                                                           Top Back / Reprint message                      = 2 : Reprint

                                                                                                                                    y = 1 : First Line

                                                                                                                                       = 2 : Second Line

                                                                                                                                    text = ASCII character to define pre-defined lines.


ESC [2ST; 3; n !v [                         Download a specified  image                     n = 0, and the directory/filename is NULL, Clear

directory/filename]                        to back side                                                         the back side image.

                                                                                                                                    n = 0, and the directory/filename is a existed image,

                                                                                                                                        download it to the back side.


ESC [2ST; 4; n !v [text]                  Defines variable print data.                          n = 1-50 : Corresponds to the variable to define

    it allows a dynamic                                        text = ASCII string to assign to the  variable. It only

                                                         definition of predefined                                 allows a maximum of  57 characters. Characters

                                                         variables embedded in static                      beyond 57 are ignored.

                                                         images. 

                                                                                                                                   
The escape sequences defined above that set the 2ST modes and change the pre-defined text values must be sent in their own Transaction print. They should be sent either before any Receipt is printed or between Receipt Transaction prints. They should not be sent as part of a Receipt. This is because they do not take effect until the next Transaction print.


The only exception is the ESC [2ST; 4; n !v [text] which defines the dynamic data for pre-defined variables in reverse side images. This escape sequence is intended to define text to be printed as part of the current Receipt.

Special Escape Sequences to Switch between Modes


The following escape sequence is used to dynamically change the way JavaPOS handles two-sided printing. Because this sequence is changing the mode of operation, it is only valid under certain conditions. It sets the mode in the same manner as if the Claim had been performed with this mode configured in the TST2SideMode option.

Escape Sequence                                 Functionality                                                   Possible Values


ESC [2ST; 5; n !v                                  Sets the printer's mode of                             n = 0 : Single Sided Mode

                                                                operation                                                           This parameter is only valid immediately after a knife cut,                                        

                                                                                                                                             before any other print orientation is sent to the

                                                                                                                                             printer. It is ignored if the printer is already processing

                                                                                                                                             data.

                                                                                                                                              = 1 : Double Sided Mode with Single Side Command

                                                                                                                                             If in mode 0, this is valid only if there are no

                                                                                                                                             outstanding print operations. If in a two-sided mode,

                                                                                                                                             the same restrictions as listed in mode 0 apply.

                                                                                                                                             = 2 : Double Sided Mode with Double Side

                                                                                                                                             Command

       If in mode 0, this is valid only if there are no

       outstanding operations. If in a two-sided mode, the

       same restrictions in mode 0 apply.

        = 3 : Double Sided Mode with Predefined Data

        If in mode 0, this is valid only if there are no

       outstanding operations. If in a two-sided mode, the

       same restrictions in mode 0 apply.


Select Print Side Sequence
 

This special sequence is only valid when mode 2 (Double Sided Mode with Double Side Command) is selected. If any other mode is selected, it is ignored.


This escape sequence is used within a transactionPrint to designate which side of the thermal paper subsequent print operations are performed.

Escape                                             Sequence                                                             Functionality Possible Values


ESC [2ST; 6; n !v                             Selects the side to print data on                       n = 0 : Send data to front side of paper

                                                                                                                                              = 1 : Send data to back side of paper


Once this command is issued, all print operations continue to be sent to that side of the paper until the sequence is sent again to change it, or until a transactionPrint(PTR_TP_NORMAL) is issued.


After transaction printing has completed, the current side is always reset to the front side of the paper.