2012-03-16 89 views
1

我使用Zebra QL320 plus打印機。字體從Win7(系統編碼CP1251)加載。 當我從Android的通過藍牙在俄羅斯LNG文本發送到打印機:通過藍牙打印來自Android的Zebra打印機的數據

! 0 200 200 200 1 
ENCODING UTF-8 
TEXT 14 0 20 80 Привет мир 
PRINT 

我對結果是這樣的:

РџСЂРёРІРμС,РјРёСЂ

我怎麼能解決這個問題?

+0

更改打印機語言 – Lucifer 2012-03-16 05:48:14

+0

Lucifer,我該怎麼做? – smie 2012-03-16 05:57:47

+0

P.S.當我通過USB從Label_Vista發送這個命令時,俄文文本打印很好。 – smie 2012-03-16 05:58:28

回答

0

這裏是工作示例:

public void bluetoothSendData(String text){ 
    bluetooth_adapter.cancelDiscovery(); 
    if (socket_connected) { 
     try { 
      OutputStream o_stream = socket.getOutputStream();    
      o_stream.write(decodeText(text, "CP1251")); 
      Log.i("emi", "Data was sended."); 
     } catch (IOException e) { 
      bluetoothCloseConnection(); 
      Log.i("emi", "Send data error: " + e); 
     } 
    } else { 
     Log.i("emi", "Bluetooth device not connected."); 
    } 
} 

private byte[] decodeText(String text, String encoding) throws CharacterCodingException, UnsupportedEncodingException{ 
    Charset charset = Charset.forName(encoding); 
    CharsetDecoder decoder = charset.newDecoder(); 
    CharsetEncoder encoder = charset.newEncoder(); 
    ByteBuffer bbuf = encoder.encode(CharBuffer.wrap(text)); 
    CharBuffer cbuf = decoder.decode(bbuf); 
    String s = cbuf.toString(); 
    return s.getBytes(encoding); 
} 

如何understend,這examle會以字體工作從編碼CP1251的操作系統加載的內容。

+0

你好,我面臨同樣的問題。我正在使用android sdk ZebraPrinterConnection和ZebraPrinter對象。我看不到任何打開OutputStream的方法。你的例子中的套接字是什麼類型的對象? – momo 2012-05-25 07:26:44

+3

我不使用ZebraPrinterConnection。只有android BluetoothSocket - http://developer.android.com/guide/topics/wireless/bluetooth.html。 – smie 2012-05-25 08:43:25

+0

感謝隊友,我用藍牙API做了連接,現在它正在工作。我也對Zebra的SDK進行了反編譯,他們只是忽略了與編碼相關的所有內容:-( – momo 2012-05-25 09:23:29

1

俄羅斯的編碼是什麼?你是否將它作爲Java中的字符串發送?你必須用正確的編碼形成你的字符串。嘗試從您要發送的字符串調試應用程序,並獲得字節,並確保字節是正確的

Check out the Sun encoding stuff here

+0

不幸的是,這不是編碼。我下載Zebra Android應用程序(http://www.zebra.com/android/ZebraUtilities.apk)並嘗試打印俄文文本。結果相同。 – smie 2012-03-19 09:24:11

+0

Zebra Android應用程序不一定會以適當的編碼包裝字符串。你如何在Android上面發送字符串?使用Zebra SDK for android?或者作爲字節?如果你在上面的字符串上使用getBytes(),你是否將正確的編碼傳遞給getBytes(「utf-8」)?它可能會在編碼進入打印機之前對其進行爆破。 – 2012-03-19 13:28:12

+0

我嘗試使用getBytes(「UTF-8」),但它沒有幫助。下一步是使用CharsetDecoder和CharsetEncoder進行更改編碼及其幫助。俄文文本是打印正確的。 – smie 2012-03-19 15:29:45

1

我已經解決了它在BluetoothSocket的OutputStream中使用ISO-8859-1編碼打印西班牙字符的問題。

 outputStream.write(cpclData.getBytes("ISO-8859-1")); 

也許你必須使用一個特殊的俄羅斯ISO字符集

0
BServico.write(new byte[] { 28, 46 }); //Cancels Chinese character mode 

//TEST 
for (int i = 0; i < 20; i++) { 
    String text = String.format("%d - %s - çüáéíóúñåæø\n", i, Integer.toHexString(i)); 

    BServico.write(new byte[] { 0x1B, 0x74, (byte)i }); 

    try { 
     BServico.write(text.getBytes("ISO-8859-1")); 
    } catch (Exception ex) { 
     // 
    } 
} 

enter image description here 正確的代碼頁對我來說 BServico.write(新的byte [] {0x1B,0x74,0x10的}) ;