Android Question BrotherSDK2B4A problem

mc73

Well-Known Member
Licensed User
Longtime User
I really don't know what's going on, though I suspect I did something wrong with the placement of 'so' files.

I used 'simpleLibraryCompiler (1.01)' and then I added just a void to perform printing. Lib is loaded, but upon run I get
B4X:
java.lang.UnsatisfiedLinkError: Couldn't load createdata from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/b4a.example-2.apk"],nativeLibraryDirectories=[/data/app-lib/b4a.example-2, /vendor/lib, /system/lib]]]: findLibrary returned null
   at java.lang.Runtime.loadLibrary(Runtime.java:358)
   at java.lang.System.loadLibrary(System.java:526)
   at com.brother.ptouch.sdk.PrinterModel.<clinit>(PrinterModel.java:30)
   at com.brother.ptouch.sdk.Communication.createPrinterModel(Communication.java:275)
   at com.brother.ptouch.sdk.ComNet$CommunicationThread.run(ComNet.java:473)

Seems that a lib is missing, though I've added the brotherLib to both the additional folder of b4a and of my workspace. Yet, I'm not sure about the 'so' files.

The code of void goes like this, just in case anyone sees something wrong:

B4X:
package biz.logismic;
import com.brother.ptouch.sdk.*;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.*;

@Version(3.0f)
@ShortName("BrotherPrintSDK")
@DependsOn(values={"BrotherPrintLibrary"})
public class brotherSDK {
   
   public void print(String filePath,String printerIP,String macAddress){
     
     Printer myPrinter = new Printer();
     PrinterInfo myPrinterInfo = new PrinterInfo();
     PrinterStatus printResult = new PrinterStatus();
     LabelInfo mLabelInfo=new LabelInfo();
     try{
     
       myPrinterInfo = myPrinter.getPrinterInfo();
       myPrinterInfo.printerModel=PrinterInfo.Model.QL_710W;
       myPrinterInfo.printMode=PrinterInfo.PrintMode.FIT_TO_PAGE;
       myPrinterInfo.port=PrinterInfo.Port.NET;
       myPrinterInfo.paperSize = PrinterInfo.PaperSize.CUSTOM;
       myPrinterInfo.orientation = PrinterInfo.Orientation.PORTRAIT;
       myPrinterInfo.numberOfCopies = 1;
       myPrinterInfo.ipAddress=printerIP;
       myPrinterInfo.macAddress=macAddress;
     
       mLabelInfo.labelNameIndex=LabelInfo.QL700.valueOf("W62").ordinal();
       mLabelInfo.isAutoCut = true;
       mLabelInfo.isEndCut =true;
       
       myPrinter.setPrinterInfo(myPrinterInfo);
       myPrinter.setLabelInfo(mLabelInfo);
       printResult=myPrinter.printFile(filePath);
     } catch(Exception e){   
     }}}

I'm almost sure, there is a simple solution, but can't figure it out :)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Remove this empty catch block. Throw the error instead.
2. Open the jar file with 7zip. The so file should be located under lib\armeabi. See the DropboxSync.jar for example:
SS-2014-10-19_08.00.38.png
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Ty Erel. The problem was with the location of 'so' file. I had it under 'additional', but I had to add the 'lib' subdirectory under 'additional' first.
Why not placing an 'so' file browser in simpleLibraryCompiler and then let it add the files for us? Just a suggestion :)
 
Upvote 0

takacsic

New Member
Licensed User
Longtime User
Hello mc73. Has succeeded in creating the B4A library for this printers? Because I try but not working.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Hello mc73. Has succeeded in creating the B4A library for this printers? Because I try but not working.
Yes, I did it, though I have to search a bit, in order to find the small lib I created. I remember it worked well for my puproses, but it was very basic, I didn't wrap the whole sdk. If interested, I can try to find it and upload it here.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Hello, I upload the lib's files.
Usage:
B4X:
Dim brt As BrotherPrintSDK
Dim err As String =brt.print(yourFilePath,yourPrinterIP)
If err.ToLowerCase.StartsWith ("error_none") Then
     log("print ok")
Else
    log("print error")
End If

This thing prints png files. For me this was enough and I never got into wrapping more methods of the original SDK unfortunately so it is rather incomplete.
 

Attachments

  • BrotherPrintSDK.jar
    10.9 KB · Views: 335
  • BrotherPrintSDK.xml
    777 bytes · Views: 445
  • BrotherPrintLibrary.jar
    189.9 KB · Views: 371
Upvote 0

buras3

Active Member
Licensed User
Longtime User
Tank you very much

I getting ERROR_COMMUNICATION_ERROR
I can print from the Brother app so I know it's not the problem

Do you know what can be the cause?
maybe it's the model
can I change it ? and where ?
 
Last edited:
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
There may be more than one problems. Using another model is probably one of them, since I used a specific model (ql 710w). Unfortunately I don't really have the time to rebuild the library and to make it more generic. But here's the java code of the library, which you can tweak and recreate the lib. I hope this helps.
B4X:
package biz.logismic;
import com.brother.ptouch.sdk.*;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.*;

@Version(3.0f)
@ShortName("BrotherPrintSDK")
@DependsOn(values={"BrotherPrintLibrary"})
public class brotherSDK {
   
   public String print(String filePath,String printerIP){
     
     Printer myPrinter = new Printer();
     PrinterInfo myPrinterInfo = new PrinterInfo();
     PrinterStatus printResult = new PrinterStatus();
     LabelInfo mLabelInfo=new LabelInfo();
     
     
       myPrinterInfo = myPrinter.getPrinterInfo();
       myPrinterInfo.printerModel=PrinterInfo.Model.QL_710W;
       
       myPrinterInfo.printMode=PrinterInfo.PrintMode.FIT_TO_PAGE;
       myPrinterInfo.port=PrinterInfo.Port.NET;
       myPrinterInfo.paperSize = PrinterInfo.PaperSize.CUSTOM;
       myPrinterInfo.orientation = PrinterInfo.Orientation.PORTRAIT;
       myPrinterInfo.numberOfCopies = 1;
       myPrinterInfo.ipAddress=printerIP;
       //myPrinterInfo.macAddress=macAddress;
     
       mLabelInfo.labelNameIndex=LabelInfo.QL700.valueOf("W62").ordinal();
       mLabelInfo.isAutoCut = true;
       mLabelInfo.isEndCut =true;
       
       myPrinter.setPrinterInfo(myPrinterInfo);
       myPrinter.setLabelInfo(mLabelInfo);
       printResult=myPrinter.printFile(filePath);
       return printResult.errorCode.toString();
     }}
 
Upvote 0

buras3

Active Member
Licensed User
Longtime User
Tank you
All I need to do is change the code and create a class file yes?
how can i do it without eclipse ?
I have notepad++ but no .class there when saving
 
Upvote 0

buras3

Active Member
Licensed User
Longtime User
I get error
C:\Users\Michael\Cellular\B4A\SimpleLibraryCompiler\test\src\com\example\BrotherPrintSDK.java:10: error: class brotherSDK is public, should be declared in a file named brotherSDK.java
public class brotherSDK {
^
1 error
 
Upvote 0

buras3

Active Member
Licensed User
Longtime User
now i get
C:\Users\Michael\Cellular\B4A\SimpleLibraryCompiler\BrotherSDK\src\biz\logismic\BrotherPrintSDK.java:2: error: package com.brother.ptouch.sdk does not exist
import com.brother.ptouch.sdk.*;

i put BrotherPrintLibrary.jar in \SimpleLibraryCompiler\BrotherSDK\libs\com\brother\ptouch\sdk

and sometime i get
javac: directory not found: bin\classes
Usage: javac <options> <source files>
use -help for a list of possible options

i added new folder bin\classes
and still the same
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
You should place BrotherPrintLibrary.jar under ...\BrotherPrintSDK\libs.
Anyway, you should really create a new thread to get help on creating a library. There are much more experienced users in this field than me and you'll surely get the help needed.
 
Upvote 0

buras3

Active Member
Licensed User
Longtime User
sorry to bother you so much :)
But you did wrote this lib

I have succeeded to make the lib
but still same error
all i changed was
myPrinterInfo.printerModel=PrinterInfo.Model.QL_720NW;
mLabelInfo.labelNameIndex=LabelInfo.QL700.valueOf("W29H90").ordinal();

i even unremed macAdress to see if it will help but the same


the strange thing is when i print from "brother print sdk demo" app with the same settings i can print
 
Upvote 0

buras3

Active Member
Licensed User
Longtime User
package biz.logismic;
import com.brother.ptouch.sdk.*;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.*;

@Version(3.0f)
@ShortName("BrotherPrintSDK")
@DependsOn(values={"BrotherPrintLibrary"})
public class BrotherPrintSDK {

public String print(String filePath,String printerIP){

Printer myPrinter = new Printer();
PrinterInfo myPrinterInfo = new PrinterInfo();
PrinterStatus printResult = new PrinterStatus();
LabelInfo mLabelInfo=new LabelInfo();


myPrinterInfo = myPrinter.getPrinterInfo();
myPrinterInfo.printerModel=PrinterInfo.Model.QL_720NW;

myPrinterInfo.printMode=PrinterInfo.PrintMode.FIT_TO_PAGE;
myPrinterInfo.port=PrinterInfo.Port.NET;
myPrinterInfo.paperSize = PrinterInfo.PaperSize.CUSTOM;
myPrinterInfo.orientation = PrinterInfo_Orientation.PORTRAIT;
myPrinterInfo.numberOfCopies = 1;
myPrinterInfo.ipAddress=printerIP;


mLabelInfo.labelNameIndex=LabelInfo.QL700.valueOf("W29H90").ordinal();
mLabelInfo.isAutoCut = true;
mLabelInfo.isEndCut =true;

myPrinter.setPrinterInfo(myPrinterInfo);
myPrinter.setLabelInfo(mLabelInfo);
printResult=myPrinter.printFile(filePath);
return printResult.errorCode.toString();
}}

the error : ERROR_COMMUNICATION_ERROR
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I don't see something wrong, unfortunately. Perhaps they have a newer com.brother.ptouch.sdk and some commands are not properly recognized.
 
Upvote 0

buras3

Active Member
Licensed User
Longtime User
I have tried with your BrotherPrintLibrary.jar 192k file and from brother site 152k

maybe the problem with the "so files" like you had ?
I don't know if i need them
 
Last edited:
Upvote 0
Top