CodeMinion / another_brother

Another Brother Flutter SDK
BSD 3-Clause "New" or "Revised" License
21 stars 21 forks source link

Unable to set labelNameIndex = 8 (W62H29) with a Brother QL-810W printer #78

Closed HCKUO1117 closed 8 months ago

HCKUO1117 commented 8 months ago

In my case,I need to print a 62mm X 29mm label with QL-810W.I have tried to set labelNameIndex to 8,but it return following error (labelNameIndex = 17 is OK,but I need to set the height to 29mm):

{labelType: -1, maxOfBatteryResidualQuantityLevel: -1, labelId: -1, isACConnected: {id: -1, name: Unknown}, batteryResidualQuantityLevel: -1, isBatteryMounted: {id: -1, name: Unknown}, batteryLevel: -1, errorCode: {name: ERROR_WRONG_LABEL, id: -1}}

Here is how I set the PrinterInfo:

void printResult(
 BuildContext context, {
 required PrintModel model,
}) async {
 if (selectedPrinter.value == null) {
   ToastUtils.show(StringStyles.printerNotReady.tr);
 }
 EasyLoading.show(status: StringStyles.printing.tr);
 var printer = Printer();
 var printInfo = PrinterInfo();
 printInfo.printerModel = Model.QL_810W;
 printInfo.printMode = PrintMode.FIT_TO_PAGE;
 printInfo.isAutoCut = false;
 printInfo.port = Port.NET;
 printInfo.paperSize = PaperSize.CUSTOM;
 // printInfo.customPaperLength = 29;
 // printInfo.customPaperWidth = 62;
 printInfo.printQuality = PrintQuality.HIGH_RESOLUTION;
 printInfo.labelNameIndex = 8;

 // Set the printer info so we can use the SDK to get the printers.
 await printer.setPrinterInfo(printInfo);

 // Get a list of printers with my model available in the network.
 List<NetPrinter> printers =
     await printer.getNetPrinters([Model.QL_810W.getName()]);

 if (printers.indexWhere((element) =>
         element.macAddress == selectedPrinter.value?.macAddress) ==
     -1) {
   EasyLoading.dismiss();
   ToastUtils.show(StringStyles.printerDisconnected.tr);
   getMyNetworkPrinters();

   return;
 }
 // Get the IP Address from the first printer found.
 printInfo.ipAddress = printers.single.ipAddress;

 printer.setPrinterInfo(printInfo);

 var totalNum = 0;
 for (var element in model.products) {
   var num = int.parse(element.num);
   totalNum += num;
 }

 var index = 1;

 for (var element in model.products) {
   var num = int.parse(element.num);
   for (int i = 0; i < num; i++) {
     final ui.ParagraphBuilder paragraphBuilder = ui.ParagraphBuilder(
       ui.ParagraphStyle(
         textAlign: TextAlign.left,
         fontSize: 20,
         textDirection: TextDirection.ltr,
       ),
     )
       ..pushStyle(ui.TextStyle(color: Colors.black, fontSize: 16))
       ..addText('James ${model.phoneNumber}\n')
       ..pushStyle(ui.TextStyle(color: Colors.black, fontSize: 16))
       ..addText('App Order\n')
       ..pushStyle(ui.TextStyle(color: Colors.black, fontSize: 20))
       ..addText('To-Go #${model.orderNumber} ($index of $totalNum)\n')
       ..pushStyle(ui.TextStyle(color: Colors.black, fontSize: 20))
       ..addText('${element.title}\n')
       ..pushStyle(ui.TextStyle(color: Colors.black, fontSize: 16))
       ..addText(element.tag);

     final ui.Paragraph paragraph = paragraphBuilder.build()
       ..layout(ui.ParagraphConstraints(
           width: MediaQuery.of(context).size.width - 8));

     await printer.printText(paragraph);
     index++;
   }
 }
 EasyLoading.dismiss();
}

Here is what PrinterInfo show after I setting:

{printerModel: {id: 52, name: QL_810W}, port: {id: 4, name: NET}, ipAddress: , macAddress: , localName: , lastConnectedAddress: , paperSize: {id: 1, name: A4}, orientation: {id: 1, name: PORTRAIT}, numberOfCopies: 1, halftone: {id: 2, name: PATTERNDITHER}, printMode: {id: 4, name: FIT_TO_PAPER}, align: {id: 1, name: LEFT}, valign: {id: 1, name: TOP}, margin: {top: 0, left: 0}, pjCarbon: false, pjDensity: 5, pjFeedMode: {id: 2, name: PJ_FEED_MODE_FIXEDPAGE}, customPaperWidth: 0, customPaperLength: 0, customFeed: 0, rjDensity: 0, rotate180: false, peelMode: false, mirrorPrint: false, paperPosition: {id: 2, name: CENTER}, isAutoCut: false, isCutAtEnd: true, mode9: true, skipStatusCheck: false, checkPrintEnd: {id: 3, name: CPE_CHECK}, rollPrinterCase: {id: 1, name: PJ_ROLLCASE_OFF}, pjSpeed: 2, thresholdingValue: 127, timeout: {processTimeoutSec: -1, sendTimeoutSec: 90, receiveTimeoutSec: 180, closeWaitMSec: 500, connectionWaitMSec: 500, closeWaitDisusingStatusCheckSec: 3}, dashLine: false, savePrnPath: , overwrite: true, isHalfCut: false, isSpecialTape: false, labelNameIndex: 8, customPaper: , binCustomPaper: null, customPaperInfo: null, isLabelEndCut: false, printQuality: {id: 2, name: NORMAL}, labelMargin: 0, scaleValue: 1.0, isCutMark: false, softFocusing: false, trimTapeAfterData: false, enabledTethering: false, rawMode: false, workPath: , pjPaperKind: {id: 2, name: PJ_CUT_PAPER}, useLegacyHalftoneEngine: false, banishMargin: false, useCopyCommandInTemplatePrint: false, labelName: {id: 16, name: W62, model: QL700}}

Is it possible to print a W62H29 label in flutter?If it can,what is the correct setting(Sorry,I can't find the document about how to setting it)?

By the way,here is the label type I want to print: WechatIMG188

CodeMinion commented 8 months ago

Hi @HCKUO1117 ,

Thanks for reaching out about this. When it comes to the QL-800 the label settings are a bit counter intuitive. In that case you need to specify the label from the QL-700 (https://github.com/CodeMinion/another_brother/blob/main/lib/label_info.dart#L427) .

So in your case the setting would look something like:

printInfo.labelNameIndex = QL700.ordinalFromID(QL700.W62H29.getId());

Hopes this helps but don't hesitate to reach out if you still run into any trouble,

HCKUO1117 commented 8 months ago

Thank you for your response. Unfortunately, the solution did not work for me. The value of QL700.ordinalFromID(QL700.W62H29.getId()) is 8, which is consistent with my previous settings.

We have ordered a new labels(DK-11209), size 62mm x 29mm, which is currently being delivered. We plan to conduct tests with this labels upon its arrival and I will share the results afterwards.

CodeMinion commented 8 months ago

Hi @HCKUO1117 ,

Sorry to hear it did not work for you. One thing to note is that QL700.W62H29.getId() is 9 rather than the 8 you have mentioned above. But if it's not working the label you are using might not be a 62mmx29mm.

Looking forward to your results once you receive the DK-11209.

HCKUO1117 commented 8 months ago

Hi @CodeMinion ,

I'm pleased to inform you that after switching to the 62mmx29mm label and configuring the "printInfo.labelNameIndex" with "QL700.ordinalFromID(QL700.W62H29.getId())", everything works perfectly. My apologies for any confusion earlier; it appears I misunderstood how the "labelNameIndex" should be set based on the label in use. There is no issue after all.

Thank you for your assistance!

CodeMinion commented 8 months ago

Hi @HCKUO1117 ,

No apologies necessary! The whole label index is as intuitive as it could be. Glad you were able to print.

Don't hesitate to reach out anytime if there is anything else we can help with,