AbobosSoftware / cordova-plugin-brother-label-printer

Cordova and Capacitor plugin for Bother Label Printers
MIT License
10 stars 16 forks source link

TD Series, plugin part missing ? #45

Closed TristanGodal closed 2 years ago

TristanGodal commented 2 years ago

Hello,

I am trying to print a label on a TD2120N model.

However, when trying to print I get this error: ERROR_WRONG_CUSTOMINFO

After researching the documentation, I came across this: https://support.brother.co.jp/j/s/support/html/mobilesdk/reference/ios/brptouchprinter.html#connection_type

So the problem is "Incorrect custom paper settings". I started to try to find by myself where the problem comes from and I have the impression that the plugin does not embed the part that allows to define a custom paper (I specify that I have changed the paperLabelName to "CUSTOM").

Do you have any ideas for me as to the additional parameters to be entered as well as the type of value to give to these parameters?

Thank you !

Regards.

arcadius commented 2 years ago

I remember having seen that message before. The error may be a bit vague ...

Please make sure you are using the correct paper/label config as the one installed in the printer (I wish the SDK could detect the label).

The only way I know of is to debug the code and trying various settings until it works.

TristanGodal commented 2 years ago

I think I'm using the correct paper/label config, the thing is that in documentation it says that this is required : https://support.brother.com/g/s/es/htmldoc/mobilesdk/reference/ios/brptouchprinter.html#setcustompaperinfocommand

I don't find anything on this inside the plugin code, do you think I need to develop it ?

arcadius commented 2 years ago

You are right, the link you provided says

This is required for RJ/TD series printer.

So yes @TristanGodal , you may have to implement that CustomPaperInfo

robr2112 commented 2 years ago

With TD2 models, and RJ2/RJ3 models as well, it’s required to use setCustomPaperFile method to provide a model-appropriate paper BIN file. A different BIN is required for each paper size you will need to use, and each different printer model must have their own BIN files because they are “coded” for a specific model. The BIN file(s) can be generated with the Windows driver (or Printer Setting Tool). And as you already mentioned the strPaperName must be set to “CUSTOM”

The “custom paper” option that allows building the paper data via SDK on the fly (not using BIN files) is only available with the 4” printer models. Sadly, this is still true even with the new v4 SDK APIs as well (and its a different API compared to the v3 SDK). I’ll keep pestering BIL SDK team to fix this in the future.

-Rob

TristanGodal commented 2 years ago

Thanks very much for this precision, I'm gonna take a look on this.

TristanGodal commented 2 years ago

Hello, so I achieved to make it work on iOS, I'll request a PR asap. But I'm facing problem with Android, actually, a method exists in BasePrint.java :

    /**
     * set custom paper for RJ and TD
     */
    private BasePrintResult setCustomPaper() {
        BasePrintResult result;
        switch (mPrinterInfo.printerModel) {
            case RJ_4030:
            case RJ_4030Ai:
            case RJ_4040:
            case RJ_3050:
            case RJ_3150:
            case TD_2020:
            case TD_2120N:
            case TD_2130N:
            case TD_4100N:
            case TD_4000:
            case RJ_2030:
            case RJ_2140:
            case RJ_2150:
            case RJ_2050:
            case RJ_3050Ai:
            case RJ_3150Ai:
            case RJ_4230B:
            case RJ_4250WB:
            case TD_4410D:
            case TD_4420DN:
            case TD_4510D:
            case TD_4520DN:
            case TD_4550DNWB:
                if (manualCustomPaperSettingsEnabled) {
                    result = setManualCustomPaper(mPrinterInfo.printerModel);
                } else {
                    mPrinterInfo.customPaper = Common.CUSTOM_PAPER_FOLDER + customSetting;
                    result = setManualCustomPaper(null);
                }
                break;
            default:
                result = BasePrintResult.success();
                break;
        }
        return result;
    }

So I'm trying to give a good path replacing "mPrinterInfo.customPaper = Common.CUSTOM_PAPER_FOLDER + customSetting;" by "mPrinterInfo.customPaper = "www/" + customSetting;" for the moment to give the right path to my bin file in assets folder.

But now, with this method, nothing append, I think that the plugin isn't loading the bin file at all. Do you have any idea ?

Regards.

brotherMobileDev commented 2 years ago

You can't point customPaper at a file in assets. The Brother Print SDK for Android doesn't know how to read assets or res/raw. You have to copy the bin file to the file system, and then point customPaper at that copy.

From Android 10 on (SDK v3.5.1 on) you probably have to write that copy to app-private storage. That would mean using Context.getExternalFilesDir() or something similar, rather than Environment.getExternalStorageDirectory() as Common does now.

TristanGodal commented 2 years ago

Thanks very much, that works. I'm gonna clean a bit the code and then propose a pull request.

MicaelMnl69 commented 3 weeks ago

Hello @TristanGodal , i'dont know why it still doesn't work i have read this PR(https://github.com/AbobosSoftware/cordova-plugin-brother-label-printer/pull/46) and i have add a customPaperFilePath to my printer obj like that without success (I have the same label printer TD-2120N)

setPrinter: function (printer: any, onSuccess: any, onError:any) {
        if (cordova.platformId == 'ios' && printer['paperLabelName'] && printer['paperLabelName'].startsWith('W')) {
            var iosLabelName = IOS_PAPER_LABEL_MAP[printer['paperLabelName']];
            if (iosLabelName) {
                //console.log('Converting paperLabelName to ' + iosLabelName + ' for ios ');
                printer['paperLabelName'] = iosLabelName;
            }
        }

        if (printer['paperLabelName'] == 'CUSTOM') {
            printer.customPaperFilePath ='/public/media/brother/51x26/51x26.bin';
        }

        cordova.exec(onSuccess, onError, 'BrotherPrinter', 'setPrinter', [printer]);
    },

logs

To Native Cordova ->  BrotherPrinter setPrinter BrotherPrinter1723215947 ["options": [{
    customPaperFilePath = "public/media/brother/51x26/51x26.bin";
    ipAddress = "192.168.0.109";
    macAddress = "00:80:77:4d:e7:88";
    modelName = "Brother TD-2120N";
    orientation = LANDSCAPE;
    paperLabelName = CUSTOM;
    port = NET;
    serialNumber = B3G233707;
}]]

Thanks