Android Question Error accesing Wrapper Library

Juan Marrero

Active Member
Licensed User
Longtime User
Hi. I made a wrapper for printing to Star Printers in raster mode (USB and Network) which works. I then decided to integrate to this wrapper the ePos SDK which compiles OK in eclipse and compiles OK in B4A. But when I try to use the EpsonPrinter type it errors in the declaration of the variable.

Attached is the code for the wrapper (epson only).

And this is the code for B4A:
B4X:
Sub PrintEpsonDocument(tar As String)
   Try
     Dim epson As EpsonPrinter
    
     epson.Initialize(epson.TM_T20, epson.MODEL_ANK)
     epson.connect(tar, 10000)
    
     For i = 0 To PrintBuffer.Size - 1
       epson.addTextFont(epson.FONT_B)
       epson.addText(PrintBuffer.Get(i))
     Next
    
     If CASH_DRAWER_CODE <> "" Then
       epson.addPulse(0, 0)
     End If
    
     If PRINTER_CUT_CODE <> "" Then
       epson.addCut(0)
     End If
    
     epson.sendData(epson.PARAM_DEFAULT)
   Catch
     Msgbox2(LastException.Message, "Error", "OK", "", "", LoadBitmap(File.DirAssets, "error.jpg"))
   End Try
End Sub

Variable target should be: "TCP:127.0.0.1" or "USB:/dev/udev/xxxxxxxxxx".
It errors on "Dim epson As EpsonPrinter"

What am I missing?
Any help is appreciated.

Edit: Forgot to include the jar I'm using from Epson.
ePOS_SDK_Android_v2.3.0
- ePOS2.jar
And the error is that "cannot find java class "prusb.wrapper.eposprint.EpsonPrinter".
Another thing. I had to use try/catch in eclipse because if I used "throws EPos2Exception", B4A errors at "cannot connect to EPos2Exception".
Also I declared the Initialize method with BA ba as the 3rd parameter but in B4A only shows 2 parameters.
 

Attachments

  • epos.txt
    35.9 KB · Views: 836
Last edited:

Juan Marrero

Active Member
Licensed User
Longtime User
No. I added it and now it doesn't error on the variable declaration. But it errors on the Initialize method "Array not expected...".
B4X:
public void Initialize(int printerSeries, int lang, BA ba){
     try {
       printer = new Printer(printerSeries, lang, ba.context);
     } catch (Epos2Exception e) {
       e.printStackTrace();
     }
   }
Initialize has 3 parameters but in B4A only have 2 parameters.
B4X:
Dim epson As EpsonPrinter
 
 epson.Initialize(epson.TM_T20, epson.MODEL_ANK)
 
Upvote 0

Juan Marrero

Active Member
Licensed User
Longtime User
I can give you the exact error tomorrow, the printer is on my work office. On the "Don't catch erros in the Java Code" suggestion, Eclipse does not let me code epos2 without exceptions. It marks that method as an error with 2 suggestions: 1) add throws declaration or 2) surround with try/catch. I'm going to try to return the exception to B4A as a Java Object.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Juan Marrero

Active Member
Licensed User
Longtime User
Did that. Same "Array not expected..." error. I'm going to try to assign the error to a public variable and see if i can see the error in B4A.
B4X:
public Epos2Exception err = null;

public void Initialize(int printerSeries, int lang, BA ba){
     try {
       printer = new Printer(printerSeries, lang, ba.context);
     } catch (Epos2Exception e) {
       e.printStackTrace();
       err = e;
     }
   }
 
Upvote 0

Juan Marrero

Active Member
Licensed User
Longtime User
I tried 3 different epos sdks: 1) ePOS2.jar, 2) ePOS-Device.jar and 3) ePOS-Print.jar
All gave me the same "Array not expected...". All on the Initialize line.

This is for the last sdk i tried (ePOS-Print):

java.lang.ExceptionInInitializerError
at prusb.wrapper.eposprint.EpsonPrinter.InitializeBuilder2(EpsonPrinter.java:42)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:259)
at com.prusb.rpro9and.pointofsales._printepsondocument(pointofsales.java:6593)
at com.prusb.rpro9and.pointofsales._printreceiptusb(pointofsales.java:3819)
at com.prusb.rpro9and.pointofsales._btnreprint_click(pointofsales.java:4567)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:340)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:4207)
at android.view.View$PerformClick.run(View.java:17372)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load eposprint from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.prusb.rpro9and-1.apk,libraryPath=/data/app-lib/com.prusb.rpro9and-1]: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:365)
at java.lang.System.loadLibrary(System.java:535)
at com.epson.eposprint.Builder.<clinit>(Builder.java:17)
... 36 more
java.lang.NoClassDefFoundError: com/epson/eposprint/Builder
at java.lang.Class.getDeclaredFields(Native Method)
at java.lang.Class.getPublicFieldsRecursive(Class.java:846)
at java.lang.Class.getFields(Class.java:829)
at anywheresoftware.b4a.shell.Shell$FieldCache.getField(Shell.java:900)
at anywheresoftware.b4a.shell.Shell.setField(Shell.java:653)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:352)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:4207)
at android.view.View$PerformClick.run(View.java:17372)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.epson.eposprint.Builder" on path: /data/app/com.prusb.rpro9and-1.apk
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
... 24 more
 
Upvote 0

Juan Marrero

Active Member
Licensed User
Longtime User
I also wrapped the Syncotek SDK with no issues. Tested it on a Synco SP-POS88VI (USB). It's just the epos sdk that is giving me headaches.
 
Upvote 0

Juan Marrero

Active Member
Licensed User
Longtime User
One of the jars I used:

B4X:
import com.epson.epos2.Epos2Exception;
import com.epson.epos2.printer.Printer;
import com.epson.epos2.printer.PrinterStatusInfo;

import android.graphics.Bitmap;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.ShortName;

@ShortName("EpsonPrinter")
@Author("Juan Marrero")
@DependsOn(values={"ePOS2"})
@ActivityObject
 
Upvote 0

Juan Marrero

Active Member
Licensed User
Longtime User
I kind of solve my problem using this app APP WEB IMG POS PRINTER DRIVER (Play Store).
When you open this app you can set and test Network, USB and Bluetooth printers. Then with a set of instructions found here https://github.com/solyaris/posprinterdriver you can send data to print, cash drawer codes and cutter codes via intent.
Even if I "solved" my problem for the app I'm developing, I still want to make that SDK to work because Via intent you have to allow permission to use the usb device 2 times (my app and the third party app, sometimes don't print on the first try because of the permissions. It does have a "re-print" option in case didn't print the first time.
 
Upvote 0

Juan Marrero

Active Member
Licensed User
Longtime User
I solved my problem. I created my own ESC/POS library inside my PrintWrapper. I looked on the internet for writing directy to printer using ESC/POS codes and I found some code using InputStream and OutputStream classes from java to send ESC/POS commands to printers in ESC/POS mode (Epson). So based on that info, I created the ESC/POS library and then added it to PrintWrapper. As soon as I found some guys to test the wrapper with Rego, Bixolon and Citizen printers I will post it for everyone.
 
Upvote 0
Top