title: How to send ESC/POS commands to thermal printer in Linux
body: <p>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.</p>
  
  <p>I tried following method to write ESC/POS command in .prn file :</p>
  
  <pre><code>1) PRINT #1, CHR$(&amp;H1D);"h";CHR$(80);
     PRINT #1, CHR$(&amp;H1D);"k";CHR$(2);
     PRINT #1, "48508007";CHR$(0);
     PRINT #1, CHR$(&amp;HA);
     PRINT #1, CHR$(&amp;H1D);"k";CHR$(67);CHR$(12);
     PRINT #1, "48508007";
  
  2) &lt;ESC&gt;(0x1B) &lt;L&gt;(0x4C)
     &lt;GS&gt;(0x1D) &lt;k&gt;(0x6B) 73 2 4 5 6 7 8 9 NUL
     &lt;FF&gt;(0x0c)
  
  3) &lt;ESC L&gt;
     &lt;GS k 73 2 4 5 6 7 8 9 NUL&gt;
  </code></pre>
  
  <p>4) "ESC L"
        "GS k 73 2 4 5 6 7 8 9 NUL"
        "FF"
  I also tried sending ESC/POS command using C program as:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;fcntl.h&gt;
  
  int main() {
     int fd,ret;
     char buf[] = "HELLO"
  
     fd = open("/dev/bus/usb/003/007",O_WRONLY);
     if(fd &lt; 3) {
        perror(open failed);
     }
  
     ret = write(fd,&amp;buf,sizeof(buf));
     if(ret == -1) {
        perror("write failed");
     }
  }
  </code></pre>
  
  <p>Upon execution the above code gives error as:</p>
  
  <pre><code>write failed: invalid arguments
  </code></pre>