2014-10-18 140 views
3

所以我一直在寫一個藍牙打印機一會兒一個Android應用程序,我已經意識到,這實際上是ESC/POS標準:http://nicholas.piasecki.name/blog/wp-content/uploads/2009/12/ESC-POS-Command-Guide.pdfAndroid的POS打印機ESC/POS

現在我使用的文檔我的打印機是這些命令的一個有限的子集,並可以在這裏找到:https://dl.dropboxusercontent.com/u/88265006/%E4%BA%A7%E5%93%81/Printer的%20user%20manual/SP-MP-300-技術%20Manual.pdf

 private void initPrinter() { 
      byte[] init = new byte[2]; 
      init[0] = 0x1B; 
      init[1] = 0x40; 
      mService.write(init); 
     } 

     private void printText(String message){ 
      byte[] send; 
      try{ 
       send = message.getBytes("UTF8"); 
      } 
      catch(UnsupportedEncodingException e){ 
       send = "Error".getBytes(); 
      } 
      initPrinter(); 
      mService.write(send); 
     } 

我可以連接到打印機,初始化它帶有一個「ESC @」命令,我可以用上面的命令編寫,但我似乎無法獲得任何類型的「視覺」效果的條形碼。這是我嘗試使用1D EAN13代碼(0000000000000):

 byte[] height = new byte[3]; 
     height[0] = 0x1D; 
     height[1] = 0x68; 
     height[2] = (byte)30; 
     //height[3] = 0; 

     byte[] width = new byte[3]; 
     width[0] = 0x1D; 
     width[1] = 0x77; 
     width[2] = (byte)3; 

     byte[] textPos = new byte[3]; 
     textPos[0] = 0x1D; 
     textPos[1] = 0x48; 
     textPos[2] = (byte)2; 

     byte[] level = new byte[3]; 
     level[0] = 0x1D; 
     level[1] = 0x51; 
     level[2] = (byte)32; 

     byte[] code = new byte[18]; 
     code[0] = 0x1D; 
     code[1] = 0x6B; 
     code[2] = 0x02; 
     code[3] = 0x0D; 
     code[4] = 0x30;//1 
     code[5] = 0x30;//2 
     code[6] = 0x30;//3 
     code[7] = 0x30;//4 
     code[8] = 0x30;//5 
     code[9] = 0x30;//6 
     code[10] = 0x30;//7 
     code[11] = 0x30;//8 
     code[12] = 0x30;//9 
     code[13] = 0x30;//10 
     code[14] = 0x30;//11 
     code[15] = 0x30;//12 
     code[16] = 0x30;//13 

     code[17] = 0x00;//end 
     mService.write(height); 
     mService.write(width); 
     mService.write(textPos); 
     mService.write(level); 
     mService.write(code); 

其中mService實際上寫入數據。我獲得的最佳輸出是0█0█0█0█0█0█0█0█0█0█0█0█0█0█ - 連續多次發送數據後。

如果我在多次發送後刪除最後的結束字節,我得到了14個0,並且我也嘗試在高度,寬度,textPosition和級別數組中添加結尾0,但沒有任何影響。

我也看了在以下位置: http://www.manualslib.com/manual/689542/Axiohm-A795.html?page=91
http://pyramidacceptors.com/phoenix-printer/esc-pos-command-set/
http://www.vbforums.com/showthread.php?754493-RESOLVED-Printing-Barcode-with-ESC-POS-on-Epson-Printers
http://www.manualslib.com/manual/753647/Axiohm-A630.html?page=51
https://www.sparkfun.com/datasheets/Components/General/Driver%20board.pdf
Where can I find a "ESC/POS" Epson Barcode Test Program?

+1

你確定你正在轉換你的字節。 Java有一種怪異的十六進制到二進制轉換(二進制轉換)的方式。這可能是導致你的問題的原因。 – SeahawksRdaBest 2014-10-20 22:10:06

+0

我最終創建了易於閱讀的常量,例如私有靜態字節GS = 0x1d;但Java的字節表示不是問題,但感謝您試圖幫助:) – 2014-10-25 20:56:38

回答

3

好了,所以事實證明,在ESC/POS打印機實際計算一些的數據給你。我不應該把校驗字節(實際條形碼的最後一位)放在我發送給打印機的數據中。

當然,這並沒有幫助我的文檔丟失了所有< =標誌。我結束了使用這個文件的幫助:http://content.epson.de/fileadmin/content/files/RSD/downloads/escpos.pdf

我仍在QR碼打印但我很確定我的問題有點類似。

+0

Tnx的幫助,但你可以分享工作代碼?我有同樣的問題,並刪除最後一位數字(代碼[17] = 0x00; //結束)沒有爲我工作...也許我失去了別的東西。 :( – 2016-03-16 09:00:24