Reputation: 177
My product is an industrial measurement instrument that uses embedded Android. The instrument needs to print results to a pre-selected network printer or to a USB printer. The instrument operator cannot be burdened with the standard Android printer interface, and Cloud printing is not acceptable. I would think this situation is fairly common in products with embedded Android (e.g., POS thermal printers)
I have code which can find the available printers on the network and return the IP address and port numbers, and I can write plain ANSI text to the printer. However, Unicode characters do not print correctly. A few other non-ANSI characters also print (some European letter variants). I believe this is because of the default "symbol set".
My expectation is that I will use PCL or IPP to control the printer. All text starting with "@PCL" is printed as plain text. All text started with ESC is not printed, but I don't have any reason to believe that such commands are being processed.
Searching the 'web, I see this question has been asked a few times, but not well answered.
I am wondering whether there is something wrong with my Socket/InputStream/BufferedReader usage.
Has anyone designed a solution for this usage?
final char ESC = 0x1b;
final String UEL = ESC + "%-12345X";
final String CRLF = "\r\n";
Socket socket = new Socket(printer.getIpAddr(), 9100);
InputStream inputStream = socket.getInputStream();
DataOutputStream oStream = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
write(oStream, UEL + "@PJL" + "\r\n");
write(oStream, "@PJL COMMENT some comments" + CRLF);
write(oStream, "@PJL ECHO RRE" + CRLF);
write(oStream, UEL + "\r\n");
oStream.flush();
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
int count = bufferedInputStream.available();
The local 'write' method creates a byte array in UTF-8 from the Java String and writes the bytes to the stream. Note that for these characters, UTF-8 is ANSI
Upvotes: 0
Views: 541
Reputation: 3756
Firstly, are you sure the printer speaks PJL and PCL ? Some special printers have their own languages.
Secondly, I think your PJL has an extra newline. It seem that the First PJL command has no newline from the PJL escape.
Sample PJL from the HP PJL reference manual.
%–12345X@PJL COMMENT *Start Job* @PJL JOB NAME = "Sample Job #1" @PJL SET COPIES = 3 @PJL SET RET = OFF @PJL ENTER LANGUAGE = PCL E. . . . PCL job . . . .E ~ %–12345X@PJL @PJL EOJ %–12345X
Upvotes: 1