AbobosSoftware / cordova-plugin-brother-label-printer

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

ERROR_WRONG_CUSTOM_INFO -> TD-2120N #67

Open MicaelMnl69 opened 1 week ago

MicaelMnl69 commented 1 week ago

Hello, 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 this issue (https://github.com/AbobosSoftware/cordova-plugin-brother-label-printer/issues/45) 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

arcadius commented 1 week ago

What err are you getting @MicaelMnl69 ?

MicaelMnl69 commented 1 week ago

ERROR_WRONG_CUSTOM_INFO @arcadius

kSelectedDevice             = Brother TD-2120N
kIPAddress                  = 192.168.0.111
kSerialNumber               = 0
==== in printViaSdk with callback id                = BrotherPrinter1812653357 ...  operation: <BRWLANPrintOperation: 0x157213360>
==== in printViaSdk with callback id                = BrotherPrinter1812653357 ...  operation adding to que: <BRWLANPrintOperation: 0x157213360>
==== in printViaSdk with callback id                = BrotherPrinter1812653357 ...  operation: <BRWLANPrintOperation: 0x157213360>  END
Communication Result: 1
Error Code in BrotherPrinter is: 0
==== in main error code in instance is -34
isFinishedForWLAN ....
Error Code in BrotherPrinter is: -34
arcadius commented 1 week ago

Hello @MicaelMnl69 , I do not have access to the TD-2120N, so I am not sure I can help. However, the line modelName = "Brother TD-2120N"; does not look right as usually, there is no "Brother" or space in model names.

Maybe @TristanGodal can help?

robr2112 commented 1 week ago

Assuming that the "51x26.bin" file was generated using the TD-2120N Windows Driver (if not, then that's the problem)....

I would guess the problem is that the customPaperFilePath is not a FULL path to the file, since you have only specified a partial path. Assuming the file is located inside your App Documents Directory at this partial path, try prepending the app directory path.

MicaelMnl69 commented 1 week ago

Hello, thank you for your answers,

I have tried with modelName = "TD-2120N" @arcadius but it does not work either. And, @robr2112 , yes the file is generated by the Windows Driver and the path corresponds to the root path of my React Capacitor project

robr2112 commented 1 week ago

@MicaelMnl69 OK thanks for clarifications.

What I meant by "full path" is that when your app is installed onto an iOS device, it will live inside a "sandbox" path in the iOS device file system.

While your path to the paper BIN file may be at the root level of your APP, it is NOT at the root level of the device.

For example, here is a path to a bin file (included inside the app bundle) that works for one of my Swift apps:

Everything before and including "MyApp.app" is the path to your app on the device. Together, it provides the "full path" to the BIN file.

In Swift, there are methods available to get this path. For a Bundle Resource, I use this one:

For the app documents folder, you may do something like this (in Swift):

I suspect Capacitor provides similar APIs to get these paths.

Anyway, I cannot say with certainty that the "relative path" you are using will fail in a Cordova/Capacitor app. It depends on whether Capacitor does something in the compiler to resolve your partial path into the full path that the SDK requires. But, this is my best guess for why the SDK is failing with that specific error.

MicaelMnl69 commented 1 week ago

Yes I thought that too before but there the user copy file into capacitor sandbox (https://github.com/AbobosSoftware/cordova-plugin-brother-label-printer/pull/46/files#diff-902704a5811b4169ac0309a24c3e7c09c9099b9f0613e3e3ae34f9cf00d38981R597)

Even if it was a path error I should get this error?

https://github.com/AbobosSoftware/cordova-plugin-brother-label-printer/pull/46/files#diff-902704a5811b4169ac0309a24c3e7c09c9099b9f0613e3e3ae34f9cf00d38981R620