smie
smie

Reputation: 622

Print data on Zebra printer from Android via bluetooth

I use Zebra QL320 plus printer. Fonts was loaded from Win7(sys. encoding CP1251). When I send text from Android via bluetooth to printer in russian lng:

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

I have in result something like this:

Привет мир

How I can fix this?

Upvotes: 2

Views: 9357

Answers (4)

Caronte
Caronte

Reputation: 139

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 Correct Code Page for me BServico.write(new byte[] { 0x1B, 0x74, 0x10 });

Upvotes: 0

Jose A Lopez Pastor
Jose A Lopez Pastor

Reputation: 347

I have solved it using in the OutputStream of BluetoothSocket an encodint to ISO-8859-1 for printing Spanish characters.

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

Maybe you have to use a special russian ISO charset

Upvotes: 3

smie
smie

Reputation: 622

Here is working example:

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);
}

How I understend, this examle will be work in Fonts what was loaded from OS with encoding CP1251.

Upvotes: 0

Ovi Tisler
Ovi Tisler

Reputation: 6473

What encoding is Russian in? Are you sending this as a String in Java? You have to form up your string with the right encoding. Try debugging the app and getting the bytes from the string you are sending and make sure the bytes are correct

Check out the Sun encoding stuff here

Upvotes: 1

Related Questions