当前位置: 动力学知识库 > 问答 > 编程问答 >

android - Send PCL commands to bluetooth printer

问题描述:

I make android app which will send PCL commands to BT printer (HP Officejet 100). Problem is when I send string data(PCL command) printer don't recognized these commands and print all these commands like normal strings. Any idea why printer don't recognize commands? My full code here: CODE

I also try change charset to US-ASCII, UTF-8 but PCL command was not recognized.

Second question: is there any way how I can convert PDF file to PCL or how I can do way when I need print PDF files on this printer?

Now I can print strings but I cannot print pdf or images etc and I find way how do this. THX for any help.

Part of code:

 void sendCustomData() throws IOException {

try {

String msg =

"<ESC>%[email protected] COMMENT *Start Job* <CR><LF>\n" +

"@PJL JOB NAME = \"Sample Job #1\" <CR><LF>\n" +

"@PJL SET COPIES = 1 <CR><LF>\n" +

"@PJL SET RET = OFF <CR><LF>\n" +

"@PJL ENTER LANGUAGE = PCL <CR><LF>\n" +

"<ESC>E. . . . PCL job . . . .<ESC>E\n" +

"~<ESC>%[email protected] <CR><LF>\n" +

"@PJL EOJ<CR><LF>\n" +

"<ESC>%-12345X";

mOutputStream.write(msg.getBytes("ASCII"));

tvStatus.setText("Custom data sent");

} catch (NullPointerException e) {

e.printStackTrace();

} catch (Exception e) {

e.printStackTrace();

} finally {

closeBT();

Toast.makeText(this, "BT conn closed", Toast.LENGTH_SHORT).show();

}

}

网友答案:

You shouldn't be using the string literal "<ESC>" because it is expecting the ASCII/UTF-8 escape character (Decimal 27, or Hex 1B). Rather, you should declare a char variable:

public final static char CHAR_ESC = 0x1B;

and use that instead

String msg = CHAR_ESC + "%[email protected] COMMENT Start Job \n" + ...

分享给朋友:
您可能感兴趣的文章:
随机阅读: