title: ESC / POS printing ignores the first few commands. Using nodeJS
body: <p>I've been struggling with this for a while.</p>
  
  <p>I'm trying to print using ESC / POS commands directly to a thermal printer.</p>
  
  <p>I'm sending the data from node, using either the node-printer module:</p>
  
  <p><a href="https://www.npmjs.com/package/printer" rel="nofollow noreferrer">https://www.npmjs.com/package/printer</a></p>
  
  <p>or the ipp module</p>
  
  <p><a href="https://www.npmjs.com/package/ipp" rel="nofollow noreferrer">https://www.npmjs.com/package/ipp</a></p>
  
  <p>Both give me the exact same behaviour, which is that the first few commands that I send seem to be completely ignored.</p>
  
  <p>For the sake of testing, I used commands from this tutorial:</p>
  
  <p><a href="https://www.neodynamic.com/articles/How-to-print-raw-ESC-POS-commands-from-Javascript/" rel="nofollow noreferrer">https://www.neodynamic.com/articles/How-to-print-raw-ESC-POS-commands-from-Javascript/</a></p>
  
  <p>So for example, in my node program I could have:</p>
  
  <pre><code>        let esc = '\x1B'; //ESC byte in hex notation
          let newLine = '\x0A'; //LF byte in hex notation
  
          let cmds = esc + "@"; //Initializes the printer (ESC @)
          cmds += esc + '!' + '\x38'; //Emphasized + Double-height + Double-width mode selected (ESC ! (8 + 16 + 32)) 56 dec =&gt; 38 hex
          cmds += 'BEST DEAL STORES'; //text to print
          cmds += newLine + newLine;
          cmds += esc + '!' + '\x00'; //Character font A selected (ESC ! 0)
          cmds += 'COOKIES                   5.00'; 
          cmds += newLine;
          cmds += 'MILK 65 Fl oz             3.78';
          cmds += newLine + newLine;
          cmds += 'SUBTOTAL                  8.78';
          cmds += newLine;
          cmds += 'TAX 5%                    0.44';
          cmds += newLine;
          cmds += 'TOTAL                     9.22';
          cmds += newLine;
          cmds += 'CASH TEND                10.00';
          cmds += newLine;
          cmds += 'CASH DUE                  0.78';
          cmds += newLine + newLine;
          cmds += esc + '!' + '\x18'; //Emphasized + Double-height mode selected (ESC ! (16 + 8)) 24 dec =&gt; 18 hex
          cmds += '# ITEMS SOLD 2';
          cmds += esc + '!' + '\x00'; //Character font A selected (ESC ! 0)
          cmds += newLine + newLine;
          cmds += '11/03/13  19:53:17';
  </code></pre>
  
  <p>Then send those commands directly to the printer. Using node-printer (taken straight from their print_raw example):</p>
  
  <pre><code>let printer = require("printer");
  this.printer.printDirect({data: cmds
      , type: 'RAW' // type: RAW, TEXT, PDF, JPEG, .. depends on platform
      , success:function(jobID: any){
          console.log("sent to printer with ID: "+jobID);
       }
      , error:function(err: any){console.log(err);}
  });
  </code></pre>
  
  <p>Or using ipp:</p>
  
  <pre><code>const ipp = require('ipp');
  const uri = "ipp://localhost/printers/myPrinter";
  
  let msg = {
         "operation-attributes-tag": {
         "requesting-user-name": "William",
         "job-name": "My Test Job",
         "document-format": "text/plain"
      },
      data: new Buffer(cmds)
  };
  
  const rawPrinter = ipp.Printer(uri);
  rawPrinter.execute("Print-Job", msg, function(err: any, res: any){
      console.log(res);
  });
  </code></pre>
  
  <p>With both of these techniques, for some reason printing only begins at 'FL oz' (the milk item on the fake receipt). Any commands before that (including alignment or font selection) are completely ignored.</p>
  
  <p>Now if I add a bunch of commands before that, using something like</p>
  
  <pre><code>let stupid = 40;
  while (stupid &gt; 0) {
      cmds += esc;
      stupid--;
  }
  </code></pre>
  
  <p>Then I do get the whole receipt printed. But this feels reeeeeeeaaaaaally hacky and will almost definitely come back to haunt me. Is there some other message I need to send to the printer for it to read the commands from the beginning? Maybe I need to format the commands in a better way?</p>
  
  <p>I'm running this on Ubuntu, and the printer is a Bixolon thermal printer 350III, whose commands can be found here:</p>
  
  <p><a href="http://www.bixolon.com/upload/download/unified%20command%20manual_rev_1_01.pdf" rel="nofollow noreferrer">http://www.bixolon.com/upload/download/unified%20command%20manual_rev_1_01.pdf</a></p>
  
  <p>Obviously I'm pretty new to this, and I'm desperately hoping that I'm missing something obvious.</p>