PrimaelQuemerais / brother_label_print_dart

A dart plugin implementing the Brother Label Print SDK
https://pub.dev/packages/brotherlabelprintdart
Apache License 2.0
8 stars 4 forks source link

Error: ERROR_TEMPLATE_NOT_PRINT_MODEL #2

Open rapPayne opened 4 years ago

rapPayne commented 4 years ago

When printing to an RJ-2150, I get this...

D/BROTHER LABEL PRINT( 5457): Printing on : 192.168.68.128
D/BROTHER LABEL PRINT( 5457): Thread started
I/.pricetag_make( 5457): The ClassLoaderContext is a special shared library.
I/System.out( 5457): port:9100
E/BROTHER PRINTER ERROR( 5457): ERROR_TEMPLATE_NOT_PRINT_MODEL
D/BROTHER LABEL PRINT( 5457): Print finished

So maybe your library doesn't support an RJ-2150?

PrimaelQuemerais commented 4 years ago

Hi, did you load a template onto the printer using the brother utility tool?

Sending a template to the printer isn't support by the plugin yet so the template needs to be imported manually

PrimaelQuemerais commented 4 years ago

Actually I've just checked out the brother documentation, RJ-2150 does indeed not support template printing.

But that doesn't mean this plugin can't support it, do you usually use pdf, images or text to print using your printer?

rapPayne commented 4 years ago

In this POC I am just printing text. The example you have on https://pub.dev/packages/brotherlabelprintdart#-example-tab- is perfect.

PrimaelQuemerais commented 4 years ago

We're going to need to develop a new functionnality to support text print. I checked out the Brother SDK, it doesn't seem to support text print natively, we could auto convert text into either an image or a pdf. I'll take a futher look at it to see which one is the more suitable.

Unfortunatly I don't have the printer anymore, will you be able to test ?

rapPayne commented 4 years ago

I sure do. I'm happy to work with you on this. I can for sure test and I'll be glad to work with the Dart and Flutter side. It's the android side of the Method Channels that I'm weaker on.

PrimaelQuemerais commented 4 years ago

Great! Thanks for the help

I will make a first commit to support pdf and images print (I'm unable to test so it will be very experimental). If you can test it and maybe fix the issues you can find, we should be able to have it working without doing too many revisions.

I'll keep you up to date ;)

PrimaelQuemerais commented 4 years ago

I've pushed a new version into the experimental branch.

It should add image and pdf support, it is untested so it's pretty likely to fail. Example has been updated aswell.

Please let me know if you tested it :slightly_smiling_face:

rapPayne commented 4 years ago

Getting closer. Please accept my PR. After my changes there's an error returning from android. Whether printing an Image in BrotherLabelPrintDart.printLabelFromImage or BrotherLabelPrintDart.printLabalFromPdf, the error is

"An error occured : PlatformException(error, byte[] cannot be cast to java.util.List, null)"

Could it be in your Kotlin code that the private fun printLabelFromPdf(printerIp: String, printerModel: Int, data: List<Int>, numberOfPages : Int) : String{ ... should be ... private fun printLabelFromPdf(printerIp: String, printerModel: Int, data: Int[], numberOfPages : Int) : String{ or something? ¯_(ツ)_/¯

Or maybe it's in the onMethodCall? call.argument<List<Int>>("data") might should be call.argument<Int[]>("data")?

I'm totally guessing here.

PrimaelQuemerais commented 4 years ago

Thanks ! Your changes have been merged

I've converted List into Array for both printLabelFromPdf() and printLabelFromImage()

If you can try it out :slightly_smiling_face:

rapPayne commented 4 years ago

Tested it out. Again, closer. I tried a bunch of stuff but in the end couldn't get it to work on the Android side. The error is:

java.lang.ClassCastException: byte[] cannot be cast to java.lang.Byte[]

We're passing an Array to the printLabelFromImage channel method but on line 45 of BrotherlabelprintdartPlugin.kt, we're converting to Array. Dart doesn't understand 'byte' nor 'Byte'. But when Kotlin receives the Array, it tries to convert an array of what it thinks are bytes into an array of Bytes.

I don't know for sure, but I'm about 60% confident that Kotlin can convert an int to a Byte. So maybe iterate through the list of ints and put them in a list of Bytes? Maybe .map() it?

PrimaelQuemerais commented 4 years ago

Haha 60% is good enough, let's try it ! :smile:

What I don't get is when we are passing a strong typed List<int> on dart's side we get a byte[] on Kotlin's side, meanwhile passing a List<String> gets us a List<String>. Maybe it is just the error interpreting the List<int> as byte[], I'll give Int[] a try.

PrimaelQuemerais commented 4 years ago

It's not working, still got a type cast error

PrimaelQuemerais commented 4 years ago

Finally got it to work, at least until "Printing on $ip_addresse". I can't test further. In the documentation you have a table of how types get passed through channel : https://flutter.dev/docs/development/platform-integration/platform-channels?tab=android-channel-kotlin-tab

Solution was Uint8List -> ArrayByte

Let me know if it does print something :wink:

rapPayne commented 4 years ago

Progress! When printing the image, we get ...

D/BROTHER LABEL PRINT(10681): Printing on : 192.168.68.128 D/BROTHER LABEL PRINT(10681): Thread started W/System.err(10681): java.lang.RuntimeException: Buffer not large enough for pixels W/System.err(10681): at android.graphics.Bitmap.copyPixelsFromBuffer(Bitmap.java:625) W/System.err(10681): at com.reefind.brotherlabelprintdart.BrotherlabelprintdartPlugin$printLabelFromImage$thread$1.run(BrotherlabelprintdartPlugin.kt:84) W/System.err(10681): at java.lang.Thread.run(Thread.java:764) D/BROTHER LABEL PRINT(10681): Print finished

When printing the PDF we get:

E/BROTHER PRINTER ERROR(10681): ERROR_OS_VERSION_NOT_SUPPORTED

p.s. I talked to some people from Brother last night. I may be able to get us some support from the company itself. I'll let you know.

PrimaelQuemerais commented 4 years ago

Okay, I'll try to increase the buffer size for the image print.

The PDF error is kinda odd, what device are you testing on ?

That would be awesome ! Please let me know if you have any more info on that :smiley:

PrimaelQuemerais commented 4 years ago

Notice

This issue is still open and the related features are not working yet. If you need these features and are willing to help with testing feel free to contact me.