I'm using the Brother Print SDK for Android. My code is based on the example code as shown in the manual:
void printTemplate(int templateKey, String newText) {
// Specify Printer
final Printer printer = new Printer();
PrinterInfo settings = printer.getPrinterInfo();
settings.printerModel = Model.QL_1110NWB;
settings.ipAddress = "your-printer-ip";
// Connect, then print
new Thread(new Runnable() {
@Override
public void run() {
if (printer.startCommunication()) {
// Specify the template key and the printer encode
if (startPTTPrint(templateKey, null)) {
// Replace text object with new text
replaceText(newText);
// Start print
PrinterStatus result = printer.flushPTTPrint();
if (result.errorCode != ErrorCode.ERROR_NONE) {
Log.d("TAG", "ERROR - " + result.errorCode);
}
}
printer.endCommunication();
}
}
}).start();
}
When the printer has its cover open, the flushPTTPrint() function does immediately return with a status of ERROR_COVER_OPEN. That is great.
When the printer is out of paper, the flushPTTPrint() function only returns after about three minutes with a status of ERROR_COMMUNICATION_ERROR. Not so great.
QUESTION: how can I detect when the printer is out of paper? Any method would be fine, either be getting flushPTTPrint() to return immediately with a out of paper staus or by querying the printer actively beforehand.
EDIT (in response to Matt Clark's suggestion)
One can set a handler to process status messages from the printer. On a regular printout (and also on the last printout before the paper is empty) the following messages arrive in this order:
- MESSAGE_START_COMMUNICATION
- MESSAGE_START_CONNECT
- MESSAGE_END_CONNECTED
- MESSAGE_START_SEND_STATUS_REQUEST
- MESSAGE_END_READ_PRINTER_STATUS
- MESSAGE_START_SEND_DATA
- MESSAGE_END_SEND_DATA
When the last paper was used, the printer immediately turns a red led on and shows on its display the out of paper notice. When trying to print in this situation, the following messages arrive:
- MESSAGE_START_COMMUNICATION
- MESSAGE_START_CONNECT
- MESSAGE_END_CONNECTED
- MESSAGE_START_SEND_STATUS_REQUEST
...about three minutes later...
- MESSAGE_START_SOCKET_CLOSE
- MESSAGE_END_SOCKET_CLOSE
The out of paper message (MESSAGE_PAPER_EMPTY) is never seen.
EDIT 2
I just figured out that this problem only happens when connecting via Bluetooth. When using WiFi the above mentioned function immediately returns with an error code ERROR_PAPER_EMPTY.