CodeMinion / another_brother

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

Adding new printer TD-2125NWB #47

Closed alaindeseine closed 1 year ago

alaindeseine commented 1 year ago

Hello,

I use your package to direct print PDF to a QL-820NWBc printer from an android app. It work like a charm. Now i need to add a new Brother model to this App And the printer model is not available in the printer list. This printer is TD-2125NWD. I have try to add it in printer_info.dart, like this :

static final TD_2125NWB = Model._internal2("TD_2125NWB", 70, RJ_4030);

And add it to _values array..

This seems to wrok well as i can list printer with

 List<brother.BluetoothPrinter> printers =
        await printer.getBluetoothPrinters(
      [
        brother.Model.QL_820NWB.getName(),
        brother.Model.TD_2125NWB.getName(),
      ],
    );

But when i try to print a text or a PDF, i get this error :

Print Result: {isBatteryMounted: {name: Unknown, id: -1}, labelId: 65535, maxOfBatteryResidualQuantityLevel: -1, labelType: 65535, errorCode: {name: ERROR_NOT_SAME_MODEL, id: -1}, isACConnected: {name: Unknown, id: -1}, batteryLevel: -1, batteryResidualQuantityLevel: -1} 

Searched for ERROR_NOT_SAME_MODEL on Google but not really helped me. This just tell me that it seems to be a differnt printer than TD-2125.

I guess i missed something, can you guide through the process of adding this new printer ?

CodeMinion commented 1 year ago

Hi @alaindeseine ,

Apologies for such a reply on this. In the case of another_brother on the Android side the best way is to look at their printer info class for the configuration of the model and use that as a reference. In the case of your printer it would have been something around the lines of TD_2125NWB(82, RJ_4030) so in another_brother it looks like static final TD_2125NWB = Model._internal2("TD_2125NWB", 82, RJ_4030);

We just released 0.0.34 on GitHub with support for this printers as well as all the new printers added on the Brother Android SDK v4. We'll be releasing that later this week into pub.dev but since we don't currently own that printer we cannot verify on our end. Could we trouble you to use this latest version on main and test with your printer to double confirm the update works on it?

Thanks in advance,

alaindeseine commented 1 year ago

Hi @CodeMinion I will take a try with your new version 0.0.34. If you want me to make some test with the TD-2125NWB, no problem. It's a pleasure. Just tell me what you want me to test.

alaindeseine commented 1 year ago

@CodeMinion I give a try with 0.0.34. I get same error that i have with my fork : ERROR_WRONG_CUSTOM_INFO

Maybe it's my on my side.

I use 51X26mmm labels (2X1inch).

Here is my test code :

...
    brother.Printer printer = brother.Printer();
    brother.PrinterInfo printInfo = brother.PrinterInfo();
    printInfo.printerModel = brother.Model.TD_2125NWB;
    printInfo.printMode = brother.PrintMode.FIT_TO_PAGE;
    printInfo.isAutoCut = true;
    printInfo.port = brother.Port.NET;
    printInfo.binCustomPaper = BinPaper_TD2120N.RD_W51H26mm;
    await printer.setPrinterInfo(printInfo);
    List<brother.NetPrinter> printers = await printer.getNetPrinters(
      [
        brother.Model.TD_2125NWB.getName(),
      ],
    );

    printInfo.ipAddress = printers.first.ipAddress;
    printer.setPrinterInfo(printInfo);

    final ui.ParagraphBuilder paragraphBuilder = ui.ParagraphBuilder(
        ui.ParagraphStyle(
          textAlign: TextAlign.center,
          fontSize: 12.0,
          fontWeight: FontWeight.w500,
        ),
      )
        ..pushStyle(Theme.of(context).textTheme.headlineMedium!.getTextStyle())
        ..addText(textToPrint);

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

      await printer.printText(paragraph);

...

Here is debug informations :

E/A-Brother(27285): Printers: [Lcom.brother.ptouch.sdk.NetPrinter;@2b705bc
E/A-Brother(27285): Printer Name: Brother TD-2125NWB
E/A-Brother(27285):  Out Printers: [{nodeName=BRWAC50DEBDB37F, modelName=Brother TD-2125NWB, macAddress=AC:50:DE:BD:B3:7F, serNo=L2G755268, ipAddress=192.168.1.96, location=}]
I/flutter (27285): ======> [{modelName: Brother TD-2125NWB, serNo: L2G755268, ipAddress: 192.168.1.96, macAddress:AC:50:DE:BD:B3:7F, nodeName: BRWAC50DEBDB37F, location: }]
I/GED     (27285): ged_boost_gpu_freq, level 100, eOrigin 2, final_idx 29, oppidx_max 29, oppidx_min 0
E/Brother (27285): Image Bytes: [B@714e945 - Size 9004
E/Brother (27285): PrintInfo: {binCustomPaper={assetPath=packages/another_brother/custom_paper/CustomTD2120NPaper/TD2120N-RD51_26mm.bin, name=TD2120N-RD51_26mm}, isSpecialTape=false, rollPrinterCase={name=PJ_ROLLCASE_OFF, id=1}, customPaperLength=0, align={name=LEFT, id=1}, pjSpeed=2, isCutMark=false, printMode={name=FIT_TO_PAGE, id=2}, isCutAtEnd=true, savePrnPath=, isLabelEndCut=false, mirrorPrint=false, customFeed=0, overwrite=true, margin={top=0, left=0}, pjFeedMode={name=PJ_FEED_MODE_FIXEDPAGE, id=2}, isHalfCut=false, ipAddress=192.168.1.96, rotate180=false, labelMargin=0, valign={name=TOP, id=1}, customPaper=, localName=, useLegacyHalftoneEngine=false, macAddress=, port={name=NET, id=4}, lastConnectedAddress=, printQuality={name=NORMAL, id=2}, pjCarbon=false, customPaperWidth=0, printerModel={name=TD_2125NWB, id=82}, labelNameIndex=-1, skipStatusCheck=false, paperPosition={name=CENTER, id=2}, mode9=true, workPath=, timeout={connectionWaitMSec=500, receiveTimeoutSec=180, processTimeoutSec=-1, sendTimeoutSec=90, closeWaitMSec=500, closeWaitDisusingStatusCheckSec=3}, pjPaperKind={name=PJ_CUT_PAPER, id=2}, rawMode=false, useCopyCommandInTemplatePrint=false, peelMode=false, thresholdingValue=127, customPaperInfo=null, numberOfCopies=1, labelName={name=UNSUPPORT, model=QL700, id=255}, orientation={name=PORTRAIT, id=1}, isAutoCut=true, dashLine=false, rjDensity=0, softFocusing=false, scaleValue=1.0, paperSize={name=A4, id=1}, halftone={name=PATTERNDITHER, id=2}, checkPrintEnd={name=CPE_CHECK, id=3}, enabledTethering=false, banishMargin=false, trimTapeAfterData=false, pjDensity=5}
E/Brother (27285): Parsed Info: com.brother.ptouch.sdk.PrinterInfo@accc1a8
I/flutter (27285): Print Result: {isBatteryMounted: {name: Unknown, id: -1}, labelId: -1, maxOfBatteryResidualQuantityLevel: -1, labelType: -1, errorCode: {name: ERROR_WRONG_CUSTOM_INFO, id: -1}, isACConnected: {name: Unknown, id: -1}, batteryLevel: -1, batteryResidualQuantityLevel: -1} 

Perharps i don't use the good bin paper ?

CodeMinion commented 1 year ago

Hi @alaindeseine ,

Thanks for your support and thanks for all the details. From the information you provided I have a feeling the error you are facing has to do with the BinPaper. Based on my limited understanding of how the Brother printers work the bin file need to be specific to the printer model and the current version of another_brother does not include the file for your printer.

I received the bin files for your printer over the weekend and I will be updating another_brother later tonight to include bin files for the TD-2125NWB.

I'll let you know through here as soon as that's merged. Thanks again for all the help.

CodeMinion commented 1 year ago

Hi @alaindeseine ,

I just released an update on main that includes some custom papers for TD2125NWB. You will find them under BinPaper_TD2125NWB.

Could I trouble to verify if you can print using those on your end?

Thanks in advance!

alaindeseine commented 1 year ago

Hi @CodeMinion

I have upgraded the package this morning with flutter pub upgrade another_brother command.

unfortunatly, i run in two problems.

First the bin label format you add does not match my label which are 51X26mm (2X1 inchs)

nevertheless, i decide to give a try with W57mm paper just to see if the ERROR_WRONG_CUSTOM_INFO dissapear or is replaced with another one.

So i replace bin paper selection line with this one :

printInfo.binCustomPaper = BinPaper_TD2125NWB.W57mm;

At run time i get this error which cause application to hang :

E/AndroidRuntime(24830): FATAL EXCEPTION: DefaultDispatcher-worker-1
E/AndroidRuntime(24830): Process: com.example.labo_brother, PID: 24830
E/AndroidRuntime(24830): java.io.FileNotFoundException: flutter_assets/packages/another_brother/custom_paper/CustomTD2125NWBPaper/TD2125NWB-57mm.bin
E/AndroidRuntime(24830):        at android.content.res.AssetManager.nativeOpenAsset(Native Method)
E/AndroidRuntime(24830):        at android.content.res.AssetManager.open(AssetManager.java:888)
E/AndroidRuntime(24830):        at android.content.res.AssetManager.open(AssetManager.java:865)
E/AndroidRuntime(24830):        at com.rouninlabs.another_brother.method.BrotherUtilsKt.binFilePathFromMap(BrotherUtils.kt:258)
E/AndroidRuntime(24830):        at com.rouninlabs.another_brother.method.BrotherUtilsKt.printerInfofromMap(BrotherUtils.kt:23)
E/AndroidRuntime(24830):        at com.rouninlabs.another_brother.method.GetNetPrintersMethodCall$execute$1.invokeSuspend(GetNetPrintersMethodCall.kt:33)
E/AndroidRuntime(24830):        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
E/AndroidRuntime(24830):        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
E/AndroidRuntime(24830):        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
E/AndroidRuntime(24830):        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
E/AndroidRuntime(24830):        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
E/AndroidRuntime(24830):        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
I/Process (24830): Sending signal. PID: 24830 SIG: 9

I have checked that both directory and bin file are where they need to be, and it's ok.

So i don't understand why i get a "File Not Foudn" about the bin file.

If you have any idea ...

CodeMinion commented 1 year ago

Hi @alaindeseine ,

Thanks for testing it out and apologies for the mixup on my part. I had neglected to add the new bin directories to the pubspec in another_brother. I have updated this and pushed the changes to main.

If you have a chance could you try with the latest changes from main?

Btw, it has been a while since I worked with the bin papers but as I recall you should be able to print without them by specifying the custom paper information directly. Since your paper is not in the list of bin files it might be worth taking a look at that approach. Here is a link to a sample for that: https://github.com/CodeMinion/Demo-Another-Brother-Prime/blob/master/lib/main.dart#L208

As I recall the bin files are preconfigured values for the specific printers in a binary format but they are not required.

Thanks again for all your support with this,

alaindeseine commented 1 year ago

Hi @CodeMinion

I have tried to print with your bin papers on my 51X26mm labels. That' not well positioned, but it print!

So from your point of view tests is ok.

I have send a mail to a man at Brother France to ask him générate bin files for labels i need.

When i will receive it i will send it to you.

For using custom paper information without using bin paper, i have tried this two weeks ago and retry when you publish the 0.0.34 version.

Here is what i do :

    CustomPaperInfo customPaperInfo = CustomPaperInfo.newCustomDiaCutPaper(
      printInfo.printerModel,
      Unit.Mm,
      51.0,
      26.0,
      0.0,
      0.0,
      0.0,
      0.0,
      0.0,
    );

    printInfo.customPaperInfo = customPaperInfo;

But this don't work.

I also try with newCustomMarkRollPaper and newCustomRollPaperbut with no chance.

alaindeseine commented 1 year ago

Hi @CodeMinion

I just receive the two bin files from Brother France.

You can get it at : https://nc.cabinfo.eu/index.php/s/mm43cCo3DzScQCW

Regards

CodeMinion commented 1 year ago

Hi @alaindeseine ,

Thanks for the files and sorry to hear the custom approach didn't work out.

I have added the two files in the folder from the link and should now appear on the latest version on main under W51_H26mm and W57_H76mm in BinPaper_TD2125NWB.

If you have a chance could you test them and let me know if it works?

Thanks again for all your support with this,

alaindeseine commented 1 year ago

Hi @CodeMinion

Unfortunatly it does not work! I get the ERROR_WRONG_CUSTOM_INFO error.

That's not you fault it is a problem with bin files i guess.

These bin files originate from Brother France, i have send them an e-mail to try understand why these bin files generates the ERROR_WRONG_CUSTOM_INFO error message.

I will tell you what they say as soon as i receive a response.

CodeMinion commented 1 year ago

Hi @alaindeseine ,

Sorry to hear it didn't work.

Thanks! Keep me posted on what they say.

alaindeseine commented 1 year ago

Hi @CodeMinion

Sorry for the delay, but I had to have many exchanges with Brother France, and they didn't solve my problem. We just have commercial guys in France, no Techs.

However, I finally figured out what was causing the ERROR_WRONG_CUSTOM_INFO error.

It came from the tag name in the .bin file.

So I was able to generate and test two .bin files for the 21X26mm and 57X76mm labels.

They are accessible on my cloud at this address: https://nc.cabinfo.eu/index.php/s/JM7mCbPZWbrswHp

You can add them in your package with:

  static const W51H26mm = BinPaper_TD2125NWB._internal(
    "W51H26",
    "$_rootDir/w51h26cei.bin",
  );

  static const W57H76mm = BinPaper_TD2125NWB._internal(
    "W57H76",
    "$_rootDir/w57h76cei.bin",
  );

Can you add them in the package?

If you need other label formats don't hesitate, not now that I understand the process, I can generate others for you.

Thanks again for your support.

Best regards,

Alain Deseine.

CodeMinion commented 1 year ago

Hi @alaindeseine ,

Thanks for the new files. I have gone ahead and replaced the old bin files with the ones included in link and pushed the changes to main. If you have a chance could I trouble you to verify if they work for you?

If you would like to include support for other labels don't hesitate to send me the bin file of those and I'll be happy to include them.

Thanks again for all your support,

alaindeseine commented 1 year ago

Hi @CodeMinion

I tested.

For the 57X76 format it works perfectly.

On the other hand, for the 51X26 format it prints but oddly it shifts.

I took a photo and uploaded it to my cloud in the same directory as the .bin files.

The two top labels are printed with the local .bin file

and the last two through the .bin file from the main branch of another_brother.

I don't understand why there is this difference.

alaindeseine commented 1 year ago

Hi @CodeMinion ,

I have doubled check what i copy on my cloud and i make a mistake.

I have put the W57 bin file instead of the 51X26 bin file.

I have adding the good one : w51h26cei.bin on my cloud.

Sorry for this.

Regards.

CodeMinion commented 1 year ago

Hi @alaindeseine ,

No to worry! Thank you so much for the updated file. I have added it to another_brother and pushed the latest change to main.

If you have a chance could I trouble you to try it out to double confirm it all works out?

Thanks again for all the support,

alaindeseine commented 1 year ago

Hi @CodeMinion

Everything is ok now.

Both the 57X76 and 51X26 are ok.

Regards.

CodeMinion commented 1 year ago

Hi @alaindeseine ,

Thanks for all the help with this and the papers. Version 0.0.34 is now officially in pub.dev and it includes these papers.

Thanks again,