I have trying to print using labels from my android app which using wifi commands Brother QL-720NW label printer. Since I performed factory reset on the printer , I'm getting this error
Problem: ERROR_WRONG_LABEL( means wrong roll specified in the sdk guide) error is thrown on print command, since I performed factory reset on the printer .
CODE:
void printTemplateSample()
{
Printer myPrinter = new Printer();
PrinterInfo myPrinterInfo = new PrinterInfo();
try{
// Retrieve printer informations
myPrinterInfo = myPrinter.getPrinterInfo();
// Set printer informations
myPrinterInfo.printerModel = PrinterInfo.Model.QL_720NW;
myPrinterInfo.port=PrinterInfo.Port.NET;
myPrinterInfo.printMode=PrinterInfo.PrintMode.FIT_TO_PAGE;
// :
myPrinterInfo.paperSize = PrinterInfo.PaperSize.A4;
myPrinterInfo.ipAddress="192.168.1.13";
myPrinterInfo.macAddress="00:80:92:BD:35:7D";
myPrinter.setPrinterInfo(myPrinterInfo);
// Start creating P-touch Template command print data
// myPrinter.startPTTPrint(1, null);
Boolean val= myPrinter.startPTTPrint(6, null);
Log.i("print", "startPTTPrint "+val);
// Replace text
myPrinter.replaceText("abcde");
// myPrinter.replaceText("12345");
// Trasmit P-touch Template command print data
PrinterStatus status=myPrinter.flushPTTPrint();//ERROR thrown here
Log.i("print", "PrinterStatus err"+status.errorCode);
}catch(Exception e){
e.printStackTrace();
}
}
Please help!
Thanks
I resolved this by creating a LabelInfo
object, since you have a Label Printer. It's not clear at all in the documentation. You need to set the label info after the printer info.
PrinterInfo info = myPrinter.getPrinterInfo();
info.paperSize = PrinterInfo.PaperSize.CUSTOM;
LabelInfo mLabelInfo = new LabelInfo();
mLabelInfo.labelNameIndex = 5;
mLabelInfo.isAutoCut = true;
mLabelInfo.isEndCut = true;
mLabelInfo.isHalfCut = false;
mLabelInfo.isSpecialTape = false;
myPrinter.setPrinterInfo(info);
myPrinter.setLabelInfo(mLabelInfo);
The ERROR_WRONG_LABEL
means that you have a wrong value in paperSize
or labelNameIndex
.
I have a P750W label printer with a 24'' paper. I found that value 5
is the good one for this size, but I don't know for your printer.
I had the same problem and figured out that you should specify the labelNameIndex
field to the PrinterInfo
object.
I had the QL-810W
printer. I tried many values and nothing worked until I set it to:
printerInfo.labelNameIndex = LabelInfo.QL700.W62RB.ordinal // -> 17
I figured out the correct value by making a for loop with all integers from 0 to 100 and logging the result until the printing succeeded with this value. I know this is not the optimal solution but I can't find any documentation or reference for these codes.
Here is the code I used to specify the PrinterInfo object:
val printerInfo = PrinterInfo()
printerInfo.printerModel = PrinterInfo.Model.QL_810W
printerInfo.port = PrinterInfo.Port.NET
printerInfo.orientation = PrinterInfo.Orientation.PORTRAIT
printerInfo.paperSize = PrinterInfo.PaperSize.CUSTOM
printerInfo.align = PrinterInfo.Align.CENTER
printerInfo.valign = PrinterInfo.VAlign.MIDDLE
printerInfo.printMode = PrinterInfo.PrintMode.ORIGINAL
printerInfo.numberOfCopies = 1
printerInfo.labelNameIndex = LabelInfo.QL700.W62RB.ordinal // -> 17
printerInfo.isAutoCut = true
printerInfo.isCutAtEnd = false
return printerInfo
TL;DR
I solved by setting the workPath
attribute:
printerInfo.workPath = context.cacheDir.Path
I noticed that the setPrinterInfo
was returning false and when trying to print I received the WRONG_LABEL
error code. Debugging the code I figured out that it's related to file writing permission that Brother SDK requires. The documentation is confusing and mentions about needing the WRITE_EXTERNAL_STORAGE
if workPath isn't set. Even having this permission I could not make it work. I solved by setting the workPath
attribute as shown above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With