KernelPanic
KernelPanic

Reputation: 2432

bluetooth receipt printer - cannot change codepage of printer

I have a following setup:

  1. Workstation with Ubuntu 14.04.3 LTS using kernel Linux work002 3.19.0-47-generic #53~14.04.1-Ubuntu SMP Mon Jan 18 16:09:14 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux with Qt 5.5.1 Opensource 64bit
  2. Some usb<-->bluetooth dongle, which has been working just fine
  3. Bluetooth based noname 48mm receipt printer from China, which was shipped to me without any documentation (assuming ESC/POS command set).

Now, this setup seems (initial connection, pairing and once paired blue LED diode turns on on printer) to work because I can print some text on the printer via QBluetoothSocket::write method:

this->ueBtPrinterSocket()->write(QByteArray("Printer ready. @[\\]^`{|}~ ĐŠŽĆČđšžćč"));

However, I am from Slovenia and I need Slovene letters, that is why i put Slovene letters into upper write - ĐŠŽĆČđšžćč and I get some Chinese letters instead. Therefore I tried to change printer code page according to ESC t n function, but without success:

QByteArray cmdChangeCodePageToSlovene;    // ESC t n
cmdChangeCodePageToSlovene.resize(3);
cmdChangeCodePageToSlovene[0]=0x1b;
cmdChangeCodePageToSlovene[1]=0x74;
cmdChangeCodePageToSlovene[2]=0x18;
qint64 result=this->ueBtPrinterSocket()->write(cmdChangeCodePageToSlovene);

qDebug() << Q_FUNC_INFO
         << " bytes written:"
         << result;

qDebug() output notified me:

void UeBluetoothManager::ueSlotBtPrinterPairedAndConnected() bytes written: 3

which is ok. Now, the Chinese manufacturer finally sent me some code for Android, which can be hardly called SDK and there is single .jar library for working with printer. I've uploaded this .jar file to Decompilers online website and I've found following decompiled method for changing printer's codepage:

public int SetCharacterSet(int Value) {
    if (g_nConnect != 1) {
        return 101;
    }
    if (!(Value > 0 && Value < 10 || Value > 16 && Value < 19 || Value != 255)) {
        return 104;
    }
    byte[] send = new byte[]{27, 116, 1};
    send[2] = (byte)Value;
    try {
        out.write(send);
        return 0;
    }
    catch (IOException e) {
        e.printStackTrace();
        return 402;
    }
}

which is basically same as my Qt code for changing codepage of printer (and because of that I can assume with high probability that printer command set is at least basic ESC/POS), so I can assume I am on the right track. Now, I've checked bluetooth traffic using Wireshark, however, I cannot find 0x1b 0x74 18 (command to change codepage) datastream sent to printer. Is this maybe the reason the codepage is not changed or can someone give me please some guidelines? I've also tried to change codepage to Windows-1250 and ISO8859-2: Latin 2, no effect.

Upvotes: 0

Views: 1422

Answers (1)

schnere
schnere

Reputation: 186

The problem seems to be that you did not convert your UTF-8 characters to the output charset.

QByteArray cmdSetCharSet;
cmdSetCharSet.resize(3);
cmdSetCharSet[0] = 0x1b;
cmdSetCharSet[1] = 0x74;
cmdSetCharSet[2] = 0x2; //OEM850

this->ueBtPrinterSocket()->write(cmdSetCharSet);

QTextCodec *codec = QTextCodec::codecForName("IBM850");
this->ueBtPrinterSocket()->write(codec->fromUnicode(QString("ÄäÖöÜüß$€")) );

Upvotes: 1

Related Questions