How to send ESC/POS commands to thermal printer in Linux

I am trying to send ESC/POS commands on a thermal printer. But whenever i send them thermal printer prints them as a text instead of executing them as commands. I am writing these commands in a .prn file and whenever i executes lp command to print a file these .prn file also get printed but as a text.

I tried following method to write ESC/POS command in .prn file :

1) PRINT #1, CHR$(&H1D);"h";CHR$(80);
   PRINT #1, CHR$(&H1D);"k";CHR$(2);
   PRINT #1, "48508007";CHR$(0);
   PRINT #1, CHR$(&HA);
   PRINT #1, CHR$(&H1D);"k";CHR$(67);CHR$(12);
   PRINT #1, "48508007";

2) <ESC>(0x1B) <L>(0x4C)
   <GS>(0x1D) <k>(0x6B) 73 2 4 5 6 7 8 9 NUL
   <FF>(0x0c)

3) <ESC L>
   <GS k 73 2 4 5 6 7 8 9 NUL>

4) “ESC L”
“GS k 73 2 4 5 6 7 8 9 NUL”
“FF”


Source: linux

Leave a Reply