Android Question I have a popular POS printer SDK,how to use it ?

hears

Active Member
Licensed User
Longtime User
I have tried The printer library, but it is can not print directly In app .
and I have tried "b4a server ",print in server side.but it is slowly,cannot use in quickly bussiness.

this SDK code is in java,used in andriod studio.
I only can use B4A make app now ,don't know JAVA. I need study more without your help.

how to use this code ,can you give me a help ? change this for b4a use ?
or anyone have some advise for use this java SDK ? simply...



this sdk can download from here :
https://www.dropbox.com/s/yew6lzfgxwyhgsz/printerSDK.zip?dl=0
 
Last edited:

hears

Active Member
Licensed User
Longtime User
if i want write this B4X library by my self, have anyone give me a advise ? how to start ? today i have study JAVA ,it is not very diffcult,i can understand java code now.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

inakigarm

Well-Known Member
Licensed User
Longtime User
if i want write this B4X library by my self, have anyone give me a advise ? how to start ? today i have study JAVA ,it is not very diffcult,i can understand java code now.

Maybe you want to try for yourself but have you search on forum for existing code,class,Library for ESC/POS printer ?
 
Upvote 0

hears

Active Member
Licensed User
Longtime User
Upvote 0

hears

Active Member
Licensed User
Longtime User

Attachments

  • 1545354607.jpg
    1545354607.jpg
    91.2 KB · Views: 298
Upvote 0

hears

Active Member
Licensed User
Longtime User
not very diffulcut,i do not knwo JAVA, but i finished make this libary in 1 week..
 
Upvote 0

Lee Gillie CCP

Active Member
Licensed User
Longtime User
I use the StarIoExtension.jar and StarIOPort3.1.jar for the Star Micronics WSP i350. I wrote some B4A modules to interop with the SDK. Not hugely well tested, but the basics seem to work fine for me over bluetooth. Hope this helps.

First some notes found atop StarPort.bas, which is found in the attache ZIP:
' Supporting Android StarPRNT SDK Version 5.3.0
' http://www.starmicronics.com/pages/StarPRNT-SDK
' StarPort and related modules provide B4A a wrapper to the Star SDK.
'
' 1. Be sure StarSDK files are found here: D:\ODPMOBILE\B4A\AdditionalLibraries
' a) StarIOPort3.1.jar
' b) starioextension.jar
' 2. Add these lines to Project Attributes in Main:
' #AdditionalJar: StarIOPort3.1
' #AdditionalJar: starioextension
' 3. Add this line to your manifest (menu: Project / Manifest Editor)
' AddPermission(android.permission.BLUETOOTH)
' 4. Add existing modules from here: D:\ODPMOBILE\B4A\SharedModules
' a) StarPort.bas
' b) StarCommandBuilder.bas
' c) StarAlignmentPosition.bas
' d) StarBarcodeSymbology.bas
' e) StarBarcodeWidth.bas
' f) StarBitmapConverterRotation.bas
' g) StarBlackMarkType.bas
' h) StarCharacterCode.bas
' i) StarCodePage.bas
' j) StarCutPaper.bas
' k) StarEmulation.bas
' l) StarFontStyle.bas
' m) StarInitializationType.bas
' n) StarInternationalType.bas
' o) StarPDF417SecurityLevel.bas
' p) StarPortInfo.bas
' q) StarPrinterStatus.bas
' r) StarQRCodeLevel.bas
' s) StarQRCodeModel.bas
' t) StarSoundChannel.bas
' 5. On Libraries tab add ByteConverter
' 6. You are now ready to write code and use the SDK.
' 7. Review Star SDK documentation found here: D:\ODPMOBILE\B4A\Documentation
' a) StarIO_StarPRNT_Android_SDK.pdf
' b) StarIO_ESCPOS_PortablePrinter_Android_SDK.pdf
'
' This wrapper class was designed and written by Lee Gillie, CCP - April 28, 2017

B4X:
Sub btnPrint_Click
    Dim cmd As String
    Dim crs As Cursor
    Dim row As Int
    Dim dline As OpenOrderLine
  
    btnPrint.Enabled = False
    btnPrint.Visible = False
  
    Dim printer As StarPortInfo
    Try
        Dim printers As List = sPort.SearchPrinter("BT:")
        If printers.Size < 1 Then
            Msgbox("There are currently no printers available.","PRINT")
            btnPrint.Enabled = True
            btnPrint.Visible = True
            Return
        End If
  
        Dim lst As List
        lst.Initialize
        lst.Add("Cancel Printing")
      
        For Each ptr As StarPortInfo In printers
            lst.Add((ptr.PortName & " (" & ptr.MacAddress & ") " & ptr.ModelName).trim)
        Next
  
        If printers.Size > 0 Then
            Dim x As id
            Dim m As Int = x.InputList1(lst,"Select Printer")
            If m <= 0 Then
                btnPrint.Enabled = True
                btnPrint.Visible = True
                Return
            End If
            printer = printers.Get(m-1)
        End If
  
        sPort.Open( printer.PortName,";l;d10",10000)
      
    Catch
        Log(LastException)
        Msgbox("Printer Not Currently Available." & CRLF & LastException.Message,"PRINT")
        btnPrint.Enabled = True
        btnPrint.Visible = True
        Return
    End Try
  
    Try
        Dim ap As StarAlignmentPosition
        ap.Initialize
        Dim fs As StarFontStyle
        fs.Initialize
      
        SCmdB.beginDocument
  
        SCmdB.appendBitmap(LoadBitmap(File.DirAssets,"eljayposbanner.png"),False)
      
'        SCmdB.appendEmphasis(True)
'        SCmdB.appendAlignment(ap.Center)
'        SCmdB.append("DELIVERY")
'        SCmdB.appendAlignment(ap.Left)
'        SCmdB.appendEmphasis(False)
        SCmdB.append(CRLF)
      
        DateTime.DateFormat="MM/d/yy hh:mm a"
        If GlobalModule.CurrentOrder.ReceivedBySigned = 0 Then
            SCmdB.append("      Date: " & DateTime.Date(DateTime.Now) & CRLF)
        Else
            SCmdB.append(" Delivered: " & DateTime.Date(GlobalModule.CurrentOrder.ReceivedBySigned) & " (signed)" & CRLF)
        End If

        SCmdB.append("   Invoice: " & GlobalModule.CurrentOrder.OrderNumber & CRLF)

        SCmdB.append("   Account: " & GlobalModule.CurrentOrder.CustomerNumber & CRLF) 
        SCmdB.append("            " & GlobalModule.CurrentOrder.CompanyName & CRLF)
        SCmdB.append(CRLF)
  
        Dim sb As StringBuilder
        Dim sf As StringFunctions
      
      
        sb.Initialize
        sb.Append(sf.Pad("Qty"," ",5,False))
        sb.Append(" ")
        sb.Append(sf.Pad("Kind"," ",6,True))
        sb.Append(" ")
        sb.Append("Description")
        sb.Append(CRLF)
        SCmdB.append(sb.ToString)
      
        cmd = "SELECT * FROM OpenOrderLine WHERE OrderNumber=? ORDER BY LineNumber"
      
        crs = GlobalModule.Delivery.ExecQuery2( cmd, Array As String (GlobalModule.CurrentOrder.OrderNumber) )
  
        For row = 0 To crs.RowCount - 1
            crs.Position = row

            Dim dline As OpenOrderLine
            dline.Initialize
            dline.fromcursor(crs)
      
            sb.Initialize
            sb.Append(sf.Pad(dline.QDelivered," ",5,False))
            sb.Append(" ")
            sb.Append(sf.Pad(dline.Kind," ",6,True))
            sb.Append(" ")
            sb.Append(dline.Description)
            sb.Append(CRLF)
          
            SCmdB.append(sb.ToString)
        Next
      
        crs.Close 

        SCmdB.append(CRLF)

        SCmdB.append("     Total: " & GlobalModule.CurrentOrder.TotalOrder & CRLF)
        SCmdB.append("        PO: " & GlobalModule.CurrentOrder.CustPONumber & CRLF )

        SCmdB.append("" & CRLF)
        SCmdB.append("" & CRLF)
        SCmdB.append("-------------------------------------------------------------" & CRLF)
        SCmdB.append("" & CRLF)

        SCmdB.endDocument

        ' Get the bytes from the command builder, and write them to the port
        Dim bytes() As Byte
        bytes = SCmdB.Commands
      
        sPort.WritePort(bytes,0,bytes.Length)
      
    Catch
        Log(LastException)
        Msgbox(LastException.Message,"PRINT")
    End Try
  
    ' All done
    btnPrint.Enabled = True
  
    Dim st As Long = DateTime.Now
    Do While DateTime.Now - st < 2000
        DoEvents
    Loop
  
    sPort.Close

    btnPrint.Visible = True
  
End Sub

Also... in activity globals...

B4X:
    Private sPort As StarPort
    Private SCmdB As StarCommandBuilder

In Activity_Create...
B4X:
    Dim emu As StarEmulation
    emu.Initialize
  
    sPort.Initialize()
    SCmdB.Initialize(emu.EscPosMobile)
 

Attachments

  • B4AStarSDKSubs.zip
    24.1 KB · Views: 232
Last edited:
Upvote 0

hears

Active Member
Licensed User
Longtime User
Upvote 0
Top