Java Question wrappers for datecs dpp250 ???

pablovidal

Member
Licensed User
Longtime User
Hello I'm trying to do the wrapping for this library is a JAR

As I can access classes jar?

What am I doing wrong?

My code in Eclipse
B4X:
package lotenet.dpp250;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import com.datecs.api.printer.Printer;  

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

@DependsOn( values = { "datecs" } ) 

@Author( "Pablo Vidal" )
@ShortName("dpp250")
@Version((float) 0.50 )


public class dpp250 {

private Printer mPrinter;


/**
 * Inicializa la Impresora
 */
public void printSelfTest(InputStream in, OutputStream out) throws IOException {
   mPrinter = new Printer(in, out) ;
   mPrinter.printSelfTest() ;
}
 
}


My code en B4A
B4X:
Sub Process_Globals
   Dim PrintBuffer As String

   Dim btAdmin As BluetoothAdmin
   Dim cmp20 As Serial
   'Dim printer As TextWriter
   Dim oPrn As dpp250
   
End Sub

Sub Globals
   Dim Toggla As Toggle
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
      btAdmin.Initialize("BlueTooth")
      cmp20.Initialize("Printer")
   End If
   
   'Toggla.TurnBluetoothOn
   
   StartPrinter
   
End Sub

Sub Activity_Resume
   'Toggla.TurnBluetoothOn
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   'Toggla.TurnBluetoothOff
End Sub

Sub Printer_Connected (Success As Boolean)
   If Success Then
      'printer.Initialize(cmp20.OutputStream)
      'printer.WriteLine(PrintBuffer)
      'printer.Flush
   
      Msgbox("Start Printed!","")
         oPrn.printSelfTest( cmp20.InputStream, cmp20.OutputStream )
      Msgbox("Stop Printed!","")
      
      'printer.Close
      cmp20.Disconnect
   Else
      If Msgbox2("", "Printer Error","Reprint","Cancel","",Null) = DialogResponse.POSITIVE Then
         StartPrinter
      End If
   End If
End Sub

Sub StartPrinter
   Dim PairedDevices As Map
   Dim L As List
   Dim Res As Int

   ToastMessageShow("Printing.....",True)

   PairedDevices.Initialize

   Try
      PairedDevices = cmp20.GetPairedDevices
   Catch
      Msgbox("Getting Paired Devices","Printer Error")
      'printer.Close
      cmp20.Disconnect
   End Try

   If PairedDevices.Size = 0 Then
      Msgbox("Error Connecting to Printer - Printer Not Found","")
      Return
   End If

   If PairedDevices.Size = 1 Then
      Try
         cmp20.ConnectInsecure(btAdmin,PairedDevices.Get(PairedDevices.GetKeyAt(0)),1)
      Catch
         Msgbox("Connecting","Printer Error")
         'printer.Close
         cmp20.Disconnect
      End Try
   Else
      L.Initialize

      For i = 0 To PairedDevices.Size - 1
         L.Add(PairedDevices.GetKeyAt(i))
      Next

      Res = InputList(L, "Choose device", -1)

      If Res <> DialogResponse.CANCEL Then
         cmp20.Connect(PairedDevices.Get(L.Get(Res)))
      End If
   End If   
End Sub
 
Last edited:

pablovidal

Member
Licensed User
Longtime User
I can not access the original datecs.jar classes.

or rather, as I call classes from the datecs.jar B4A???

I just need access to these three classes are in the datecs.jar

B4X:
Printer

public Printer(java.io.InputStream in,
               java.io.OutputStream out)
Constructs a new instance of this class from a given InputStream and OutputStream.
If in or out is null, a NullPointerException is thrown.

Parameters:
in - the input stream.
out - the output stream.


printSelfTest

public void printSelfTest()
                   throws java.io.IOException
Prints self test receipt.
Throws:
java.io.IOException - if an I/O error occurs.


printTaggedText

public void printTaggedText(java.lang.String s)
                     throws java.io.IOException
Prints a tagged text using default charset for encoding.
The text is encode into a sequence of bytes using the default charset encoding.

Tags definition
{reset}   Reset to default settings.
{br}   Line break. Equivalent of new line.
{b}, {/b}   Set or clear bold font style.
{u}, {/u}   Set or clear underline font style.
{i}, {/i}   Set or clear italic font style.
{s}, {/s}   Set or clear small font style.
{h}, {/h}   Set or clear high font style.
{w}, {/w}   Set or clear wide font style.
{left}   Aligns text to the left paper edge.
{center}   Aligns text to the center of paper.
{right}   Aligns text to the right paper edge.
If s if null, a NullPointerException is thrown.

Parameters:
s - the tagged text to print.
Throws:
java.io.IOException - if an I/O error occurs.
 

Attachments

  • datecs.zip
    41 KB · Views: 426
Last edited:

warwound

Expert
Licensed User
Longtime User
Here's an (untested) example that uses the B4A AbsObjectWrapper class to wrap the com.datecs.api.printer.Printer class:

B4X:
package b4a.com.datecs.api;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import anywheresoftware.b4a.AbsObjectWrapper;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

@Author("Martin Pearman")
@DependsOn(values = { "datecs" })
@ShortName("Printer")
@Version(1.0f)
public class Printer extends AbsObjectWrapper<com.datecs.api.printer.Printer> {

   public void Initialize(InputStream InputStream1, OutputStream OutputStream1){
      setObject(new com.datecs.api.printer.Printer(InputStream1, OutputStream1));
   }
   
   public void PrintSelfTest() throws IOException{
      getObject().printSelfTest();
   }
   
   public void PrintTaggedText(String TaggedText) throws IOException{
      getObject().printTaggedText(TaggedText);
   }
   
   public void PrintTaggedText2(String TaggedText, String Encoding) throws IOException{
      getObject().printTaggedText(TaggedText, Encoding);
   }
}

In B4A you'd now Initialize an instance of the new Printer object and then uses it's methods:

B4X:
Dim Printer1 As Printer
Printer1.Initialize(InputStream1, OutputStream1)
Printer1.PrintSelfTest

Eclipse project attached.

Martin.
 

Attachments

  • datecs_eclipse_absobjectwrapper.zip
    2.6 KB · Views: 413

pablovidal

Member
Licensed User
Longtime User
Warwound thank you very much, I have tested you sent me but get me the following error in b4a: java.lang.NoClassDefFoundError: com.datecs.api.printer.Printer, any way to fix this error.
 

warwound

Expert
Licensed User
Longtime User
Do you get this exception when compiling and then the compiling fails or does it occur when you run the app?

It sounds as though the datecs.jar library isn't being compiled into the APK.
Can you open your APK with WinRAR (maybe WinZIP will do it too) and look for the folder named com/datecs/api?
If the datecs.jar library isn't being compiled into your APK then that folder will not exist - and you'll get the NoClassDefFoundError exception.

If that's the case then first thing to check is that you have the datecs.jar file in your B4A additional library folder.

(You have included the annotation @DependsOn(values = { "datecs" }) in your java class source i'm assuming).

Martin.
 

warwound

Expert
Licensed User
Longtime User
The B4A Additional Libraries folder - that's the folder selected in the IDE under Tools > Configure Paths > Additional libraries.

Martin.
 

metzeller_2013

Member
Licensed User
Longtime User
Dpp 250 Sdk

Good day sir,
Also interested about this SDK from datecs, I would like to ask about the progress and development of its wrapping for B4A...
I am also to start developing an app which would require the sdk as a library
in B4A. Hoping anyone can help me. I have no further knoweldge on Java just a little bit of VB Programming. TIA:sign0104:
 

Marlon Tayag

Member
Licensed User
Longtime User
Hello can you please help me? I am also trying to use DPP 250 printer but I don't know how to use it in B4A. Do you have any sample project to test it ? I'm having a hard time. Any available library that we can use?
 
Top