Writing correct ESC/POS commands for POS printer

user2498887 picture user2498887 · Jun 21, 2013 · Viewed 24.6k times · Source

I'm trying to write proper ESC/POS commands for 58mm POS thermal printer. I tried to input this commands as ASCII text and also converted it to HEX, but in both cases printer print just this code, not receipt output. Something wrong is with code, can no find examples of working code(not commands).

ESC @
ESC a SOH
ESC ! NUL
ESC t 25 (select character code table)
ESC a 1.49 (centering text)
ESC E 1
Bold text
ESC E 0
Text line 1
Text line 2
Text line 3
ESC a 0
Date/Time: January 14, 2002 15:00

ESC d &H03
ESC a 0
ESC! 1
TM-U210B $20.00
&H0A
Item 1 $20.00
&H0A
Item 2 $10.00
&H0A
&H0A
ESC ! D
TOTAL $30.00
LF
ESC! NUL
------------------------------
LF
PAID $30.00
LF
CHANGE $ 0.00
LF

Thank you!
GS k m d...dk  NUL

I want get printed receipt like this sample. The available commands for printer commands is here. Can someone show me the proper code for this?

Answer

sweetlilmre picture sweetlilmre · Aug 13, 2013

Are you actually sending "ESC" as three separate characters?

If so, you need to send the ESC ASCII code: ASCII code 27. Similarly for NUL, SOH and other non printable characters.

See this: http://en.wikipedia.org/wiki/ASCII_code

You will need to do this via code as you need to send the BYTE value of 27 for ESC. You might be able to put those characters into a text file and send this to the printer, if you have a suitable text editor.

Also you will need to send the HEX value for &H03 etc, not the characters '&', 'H', '0', '3'


EDIT: this link might be helpful: https://www.sparkfun.com/datasheets/Components/General/Driver%20board.pdf

This is an cheap ESC/POS thermal printer board manual that explains the idea behind what you want to achieve.


-(e)