Android Code Snippet Wangpos Printer SDK not using bluetooth

Hi guys I though I would publish this if anyone is ever stuck with a wangpos printer add this your main



Public Sub StartActivityForResult(i As Intent)
Dim jo As JavaObject = GetBA
ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
jo.RunMethod("startActivityForResult", Array As Object(ion, i))
End Sub

Sub GetBA As Object
Dim jo As JavaObject
Dim cls As String = Me
cls = cls.SubString("class ".Length)
jo.InitializeStatic(cls)
Return jo.GetField("processBA")
End Sub

Sub InitPrinter()
NativeMe.RunMethod("_initprint",Null)
End Sub

Sub PrintStringLeft(s As String)
NativeMe.RunMethod("_printLeft",Array As Object(s,FontSize,Bold))
FontSize = 22
Bold = False
End Sub


Sub PrintStringLeftFontAndBold(s As String)
FontSize = 26
Bold = True
NativeMe.RunMethod("_printLeft",Array As Object(s,FontSize,Bold))
FontSize = 22
Bold = False
End Sub


Sub PrintStringRight(s As String)
NativeMe.RunMethod("_printRight",Array As Object(s,FontSize,Bold))
FontSize = 22
Bold = False
End Sub

Sub PrintStringCenter(s As String)
NativeMe.RunMethod("_printCenter",Array As Object(s,FontSize,Bold))
FontSize = 22
Bold = False
End Sub

Sub EndPrinter()
NativeMe.RunMethod("_postprint",Null)
Reprint = "Reprint"
End Sub

#if Java

import android.content.Context;
import android.os.RemoteException;


import wangpos.sdk4.libbasebinder.Printer;
import wangpos.sdk4.libbasebinder.Printer.Align;





Printer mPrinter;

public void init()
{
new Thread()
{
@override
public void run()
{

BA.Log("Printer A");
mPrinter = new Printer(getApplicationContext());
BA.Log("Printer B");
}
}.start();
}

public void _initprint()
{
try
{
mPrinter.printInit();
mPrinter.clearPrintDataCache();
}
catch (RemoteException e)
{
e.printStackTrace();
}
}

public void _printLeft(String _text,int _fontsize ,boolean _bold)
{
try
{
mPrinter.printString(_text, _fontsize, Printer.Align.LEFT, _bold, false);
}
catch (RemoteException e)
{
e.printStackTrace();
}
}

public void _printRight(String _text,int _fontsize ,boolean _bold)
{
try
{
mPrinter.printString(_text, _fontsize, Printer.Align.RIGHT, _bold, false);
}
catch (RemoteException e)
{
e.printStackTrace();
}
}

public void _printCenter(String _text,int _fontsize ,boolean _bold)
{
try
{
mPrinter.printString(_text, _fontsize, Printer.Align.CENTER, _bold, false);
}
catch (RemoteException e)
{
e.printStackTrace();
}
}

public void _postprint()
{
try
{
mPrinter.printPaper(100);
mPrinter.printFinish();
}
catch (RemoteException e)
{
e.printStackTrace();
}
}

#End If
#End Region

'Program code should go into B4XMainPage and other pages.
'Program code should go into B4XMainPage and other pages.


If you ever stuck call me + 27 84 944 6808
 

Attachments

  • mainpage.bal
    5.8 KB · Views: 87
  • reprint.bal
    3.3 KB · Views: 83
Sub PrintDailyCash

Main.FontSize = 22
Main.Bold = True
Main.Alignment = 2

CallSub(Main,"InitPrinter")

Dim Desc As String = ""
DateTime.DateFormat="yyyy-MM-dd HH:mm:ss"

Dim strdatenow As String = DateTime.Date(DateTime.now)

'Printer1.AddBuffer_Bitmap(LoadBitmap(File.DirAssets,"LoginScreenLogo.png"),0)

CallSub2(Main,"PrintStringLeft", strdatenow )
CallSub2(Main,"PrintStringLeft", "Cash Up Summary for " & Main.CashUpDate )
CallSub2(Main,"PrintStringLeft", "Cash Up Info " )
CallSub2(Main,"PrintStringLeft", "User " & Main.UserLogin )
CallSub2(Main,"PrintStringLeft", "_________________________________" )
CallSub2(Main,"PrintStringLeft", " " )
CallSub2(Main,"PrintStringLeft", "Card Count=" & Main.CountCardInvoice )
CallSub2(Main,"PrintStringLeft", "Cash Count=" & Main.CountCashInvoices )

CallSub2(Main,"PrintStringLeft","Card Total=" & Main.TotalCardInvoice & " " )
CallSub2(Main,"PrintStringLeft","Cash Tend=" & Main.TotalCashTendered & " " )

CallSub2(Main,"PrintStringLeft","OverUnder=" & Main.OverAndUnders )
Main.Bold = True
CallSub2(Main,"PrintStringLeft","************************" )
Main.Bold = False


If Main.Reprint ="" Then

CallSub2(Main,"PrintStringLeft","Finalized" )
Else

CallSub2(Main,"PrintStringLeft","Not Finalized" )
End If
Main.Bold = True
CallSub2(Main,"PrintStringLeft","************************" )
Dim total As Double = 0
CalcTotal
'For i = 0 To Main.invoicelist.Size - 1

CallSub2(Main,"PrintStringLeft","* = Cash" )

For Each c As CashOffType In Main.CashOffList


If c.PaymentType.ToUpperCase = "Cash".ToUpperCase Then
Desc = "*" & c.CustomerRef & " " & c.TransRef.Replace(" Payment","") & " AmT=" & c.Amount
Else
Desc = c.CustomerRef & " " & c.TransRef.Replace(" Payment","") & " AmT=" & c.Amount

End If




If c.Amount = 0 Then
Else


CallSub2(Main,"PrintStringLeft", Desc )


'Printer1.AddBuffer_Writeline(ESC_POS.BoldOn & desc2 & ESC_POS.DoubleOff)

'Printer1.AddBuffer_Writeline(Desc)
End If

Next

CallSub2(Main,"PrintStringLeft", "--------------------------------" )

CallSub2(Main,"PrintStringLeft", "" )
CallSub2(Main,"PrintStringLeft", " " )
CallSub2(Main,"PrintStringLeft", " " )
CallSub2(Main,"PrintStringLeft", " " )

CallSub2(Main,"PrintStringLeft", "SIGNATURE_______________________" )
CallSub2(Main,"PrintStringLeft", "" )
CallSub2(Main,"PrintStringLeft", " " )
CallSub2(Main,"PrintStringLeft", " " )
CallSub2(Main,"PrintStringLeft", " " )
CallSub2(Main,"PrintStringLeft", "HANDED OVER BY___" & Main.UserLogin & "_______" )
CallSub2(Main,"PrintStringLeft", "" )
CallSub2(Main,"PrintStringLeft", " " )
CallSub2(Main,"PrintStringLeft", " " )
CallSub2(Main,"PrintStringLeft", " " )

CallSub(Main,"EndPrinter")

'

End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Please use CODE Tags when posting Code.
Best is to upload a small project (File-Export as ZIP)
 
Top