Kamis, 28 Oktober 2010

Controlling an Epson compatible printer directly with EscP2 codes

It seems that many people find it hard to configure DOS programs such as Sage, banking programs etc. to print in a sensible format to laser printers (or line / dot matrix ones for that matter).
The following codes can be used in DOS batch files or within an application's configuration program for controlling an Epson  or compatible EscP2 printer.  There are many different combinations for different printers but these are fairly standard ones:
 
Characters ASCII codes Effect
[ESC] @ 27 64 Reset printer
[ESC] x 1
27 120 49 'Near Letter Quality' On
[ESC] x 0
27 120 48 'Near Letter Quality' Off
[ESC] 4
27 52 Italics On
[ESC] 5
27 53 Italics Off
[ESC] G
27 71 Double Strike On
[ESC] H
27 72 Double Strike Off
[ESC] M
27 77 Elite (12 chars per inch) font size
[ESC] P
27 80 Pica (10 chars per inch) font size
[ESC] [SI]
[SI]
27 15
15
Condensed Print
[DC2]
18 Cancel Condensed Print
[ESC] [SO]
[SO]
27 14
14
Enlarged (one line)
[DC4]
[LF]
20
10
Cancel Enlarged
[ESC] W l
27 87 49 Enlarged (more than one line)
[ESC] W 0
27 87 48 Cancel Enlarged (more than one line)
[ESC] - 1
27 45 49 Underline On
[ESC] - 0
27 45 48 Underline Off
[ESC] E
27 69 Bold On
[ESC] F
27 70 Bold Off
[ESC] S 1
27 83 49 Subscript (e.g. x1)
[ESC] S 0
27 83 48 Superscript (e.g. x2)
[ESC] T
27 84 Cancel Super/Subscript
[ESC] R n
27 82 n Select different foreign character set
[ESC] % 0 n
27 37 n Select internation character set n
[ESC] ! n
27 33 n Change print mode
[ESC] 0 27 48 1/8" line spacing
[ESC] 1 27 49 7/9" line spacing
[ESC] 2 27 50 1/6" line spacing
[ESC] 3 n 27 51 n n/216" line spacing
[ESC] A n 27 65 n n/72" line spacing
[ESC] T n 27 84 n n/216" line feed
[ESC] C n 27 67 n Page length (n = no. of lines)
[ESC] C 0 n 27 67 48 n Page length (n = no. of inches)
[ESC] N n 27 78 n Perforation skip (n = no. of lines)
[ESC] 0 27 48 Cancel peforation skip
[ESC] D n n n n 27 68 Set tab stops to n n n n
[ESC] B n n n n 27 66 Set vertical tab stops to n n n n
[ESC] Q n 27 81 n Set right margin
[ESC] l n 27 108 n Set left margin
[BEL] 7 Sound bell
[BS]
8 Backspace
[HT] 9 Horizontal Tab
[LF] 10 Line Feed
[VT] 11 Vertical Tab
[FF] 12 Form Feed (new page)
[CR]
13 Carriage Return
[DC1] 17 Printer Enable
[DC3] 19 Printer Disable
[CAN] 24 Cancel last line
[DEL] 127 Delete last character
[ESC] < 27 60 Home Print head
[ESC] U 1 27 85 49 Undirectional printing on
[ESC] U 0 27 85 48 Undirectional printing off
[ESC] s 1 27 115 49 Half speed printing on
[ESC] s 1 27 114 48 Half speed printing off
[ESC] 8 27 56 Ignore paper empty
[ESC] 9 27 57 Cancel ignore paper empty
[ESC] K n1 n2 27 75 n1 n2 Single density graphics no. of data = n2 * 256 + n1
[ESC] L n1 n2 27 76 n1 n2 Double density graphics no. of data = n2 * 256 + n1
[ESC] Y n1 n2 27 89 n1 n2 Double speed, Double density graphics.
[ESC] Z n1 n2 27 90 n1 n2 Quad density graphics
[ESC] * m n1 n2 27 42 m n1 n2 8 dot graphics modes, m = mode
[ESC] ? n m 27 63 n m Change graphics mode n to work as m. n is K, L, Y, or Z
[ESC] & 0 n m a p1 ... p11 27 38 48 n m a p1 ... p11 Redefine character. p1..p11 = character data. a = attribute, n+m characters to change.
From a DOS batch file you can often send codes to a printer using ECHO commands which have been entered using EDIT.  This could be to a local printer or captured to a network printer, eg:
ECHO ~x1~M > LPT1:  to put the printer into NLQ elite pitch.
where ~ is the [ESC] character which in edit can be entered with Control P then Control [ and shows as an arrow pointing to the left.
Note in Windows 2000 and XP the & symbol is used to run two or more commands from the same command line therefore if an & symbol is required you need to add a ^ before it to pass the & symbol directly rather than Windows interpreting it. Another alternative is to add the codes to a text file using EDIT then sending the text file to the printer with a line such as:
COPY textfile.txt LPT1:
or COPY textfile.txt \\server\share
or TYPE textfile.txt > LPT1:
or PRINT textfile.txt
or NPRINT textfile.txt (for Novell systems)

From a simple DOS based BASIC such as Quick Basic 4.5 (QB45) you can send codes in a number of ways.  The easiest is to assign some codes to variables and use those in print # or lprint statements to the printer port.  You use the chr$() function to send unprintable codes such as Escape and Form Feed or those difficult to enter such as the double quote " which is chr$(34) i.e.:
esc$=CHR$(27)
boldon$=esc$+"E"
boldoff$=esc$+"F"formfeed$=chr$(12)

filenum=FREEFILE
OPEN "lpt1:" FOR OUTPUT AS filenum
   PRINT #filenum, boldon$ + "This is in bold" + boldoff$
CLOSE #filenum

LPRINT boldon$ + "This is in bold" + boldoff$
[ESC] is ascii 27, Control [.  Enter in EDIT using Control P, Control [.

Tidak ada komentar:

Posting Komentar