B4A Library SD: BT Printer Bluetooth

ANNOUNCEMENT
Starting today, this library will be abandoned and will no longer be distributed.
A new, more comprehensive Android library for ESC/POS thermal printers will be released. (BT, BLE, LAN, USB) (here
)



(No WRAP, No Java Only B4A)
BT_Printer
library allows you to print text and image to a
thermal printers (Bluetooth and BLE) with ESC/POS language
(For B4J versione see Here, for B4i versione see Here, for ZEBRA printer Here)

To print the QR CODES with your BT thermal printer you can create an image containing the QR code with the help of the @Erel library (here) or can use library of @Johan Schoeman (here)

WARNING: Make sure the library meets all your needs, is compatible with the printer you need to use.
To try print with the demo version (rel. 0.21) you can only use the FlushAndClose command which lasts 14 days and then disables.
The full version of the library will be issued to those making a donation (Contact me in private before making a donation). In the donation indicate the library you want and your NickName. Those requesting the full version will receive updates for 3 months.



Video1.gif
upload_2018-9-2_17-24-41.png



SD_BT_Printer

Author:
Star-Dust
Version: 1.00
  • BLE_Printer
    • Events:
      • Connected (services As List)
      • Disconnected
      • ImageWriteComplete
      • PrinterFound (Name As String, ID As String)
      • StateChanged (msg As String)
      • WriteComplete (Characteristic As String, Success As Boolean)
    • Fields:
      • CharatteristicName As String
      • currentState As Int
      • ServiceName As String
    • Functions:
      • AddTab (ArrayTab As Int()) As String
        Add Tab
        eg. PrinterBLE.AddTab(Array As Byte(100,150,121))
      • CenterJustify As String
        after this command calls SendBufferToPrinter
      • Class_Globals As String
      • Connect (ID As String) As String
      • Initialize (CallBack As Object, EventName As String, EncodingType As String) As String
        Initializes the object. You can add parameters to this method if needed.
      • InitializePrinter As String
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • LeftJustify As String
        after this command calls SendBufferToPrinter
      • PrintBitmap (bmp As Bitmap)
      • RightJustify As String
        after this command calls SendBufferToPrinter
      • ScanPrinter As String
      • SetCodePage (Code As Byte) As String
        es. Printer.SetCodePage(06) for umlauts char
      • Write (Text As String) As String
        Write (Print) a Text
      • Write_ArrayByte (B As Byte()) As String
        Write (Send to Printer) a Array of Byte
        eg. PrinterBLE.Write_ArrayByte(Array As Byte(0x1D,150,23))
        eg. PrinterBLE.Write_ArrayByte("Text".GetBytes("UTF8"))
      • WriteBarCode (Code As String) As String
      • WriteLine (Text As String) As String
        Write (Print) a Text + CHLF
      • WriteList (list As List) As String
        Write (Print) a List
    • Properties:
      • CodeTable
        es. printer.setCodeTable(Ecoding.Code_WPC1252)
        aftet this command calls SendBufferToPrinter
      • isConnect As Boolean [read only]
      • isScanning As Boolean [read only]
      • Spacing
        after setSpacing command calls SendBufferToPrinter
  • BT_Printer
    Note: AddPermission(android.permission.ACCESS_COARSE_LOCATION)
    • Events:
      • BluetoothIsDisabled
      • ConnectedToPrint (Success As Boolean)
      • DataReceived (Buffer() As Byte)
      • DisconnectToPrint (Mac As String)
      • DiscoveryComplete (Printers As Map)
      • DiscoveryFinished
      • DiscoveryNewPrinter (PrintedFound As Map, DeviceClass As Int)
      • DiscoveryNoDeviceFound
      • ErrorDiscovery
      • ListPrinterAssociated (ListNameAndMac As Map)
      • SendingError (Mac As String)
      • SendTerminated
    • Fields:
      • Const_AUDIO_VIDEO As Int
      • Const_COMPUTER As Int
      • Const_HEALTH As Int
      • Const_IMAGING As Int
      • Const_MISC As Int
      • Const_NETWORKING As Int
      • Const_PERIPHERAL As Int
      • Const_PHONE As Int
      • Const_TOY As Int
      • Const_UNCATEGORIZED As Int
      • Const_WEARABLE As Int
    • Functions:
      • AddBuffer_ArrayByte (B As Byte()) As String
      • AddBuffer_BarCode (Code As String) As String
      • AddBuffer_Bitmap (Bmp As Bitmap, ShiftLeft As Int) As String
      • AddBuffer_BitmapAlternativeCoding (Bmp As Bitmap) As String
      • AddBuffer_List_Write (list As List) As String
      • AddBuffer_List_WriteLine (list As List) As String
      • AddBuffer_Tab (ArrayTab As Int()) As String
      • AddBuffer_Write (Text As String) As String
      • AddBuffer_WriteLine (Text As String) As String
      • AddPrintDefineImage As String
      • CenterJustify As String
        after this command calls SendBufferToPrinter
      • ChangeEncoding (EncodingType As String) As String
      • Class_Globals As String
      • ClearBuffer As String
      • Close As String
      • Connected As Boolean
      • DefineImage (Image As Bitmap)
      • flushAllAndClose
      • Initialize (CallBack As Object, EventName As String, EncodingType As String) As String
        Initializes the object. You can add parameters to this method if needed.
      • InitializePrinter As String
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • LeftJustify As String
        after this command calls SendBufferToPrinter
      • Preview As Bitmap
      • ResetPreViewWidth (NewWidth As Int) As String
      • RightJustify As String
        after this command calls SendBufferToPrinter
      • SearchNewPrinter As String
        select --------------------------------------------
      • SelectFromAssociatedPrinter As String
      • SelectFromMac (Mac As String) As String
      • SendBufferToPrinter
      • SetCodePage (Code As Byte) As String
        es. Printer.SetCodePage(06) for umlauts char
    • Properties:
      • CodeTable
        es. printer.setCodeTable(Ecoding.Code_WPC1252)
        aftet this command calls SendBufferToPrinter
      • Spacing
        after setSpacing command calls SendBufferToPrinter
  • ESC_POS
    Code module
    Subs in this code module will be accessible from all modules.
    • Fields:
      • BoldOff As String
      • BoldOn As String
      • DoubleOff As String
      • DoubleOn As String
      • FontA_Bold As String
      • FontA_DoubleHight As String
      • FontA_DoubleWide As String
      • FontA_DoubleWideHeight As String
      • FontA_Normal As String
      • FontB_Bold As String
      • FontB_DoubleHeight As String
      • FontB_DoubleWide As String
      • FontB_DoubleWideHeight As String
      • FontB_Normal As String
      • Horizzontal As String
      • InitializePrinter As String
      • ItalicFontOff As String
      • ItalicFontOn As String
      • NoUnderline As String
      • QueryErrorCauses As String
      • QueryOfflineCauses As String
      • QueryPaperStatus As String
      • QueryPrinterStatus As String
      • Underline1 As String
      • Underline2 As String
      • Vertical As String
    • Functions:
      • Process_Globals As String
  • Encoding
    Code module
    Subs in this code module will be accessible from all modules.
    • Fields:
      • Chinese As String
      • ChineseS As String
      • Code_PC437 As Int
      • Code_PC850 As Int
      • Code_PC857 As Int
      • Code_PC858 As Int
      • Code_PC860 As Int
      • Code_PC863 As Int
      • Code_WPC1252 As Int
      • DOS_Latin_1 As String
      • IBM_PC As String
      • ISO8859 As String
      • UTF8 As String
      • Windows1252 As String
    • Functions:
      • Process_Globals As String
 

Attachments

  • Sample1.zip
    10.2 KB · Views: 1,541
  • sample_bt_ble.zip
    11.3 KB · Views: 103
  • SD_BT_Printer 0.21.zip
    21.2 KB · Views: 90
Last edited:

Star-Dust

Expert
Licensed User
Ops 🧐🤗 sorry
 

eelias

Active Member
Licensed User
Longtime User
1656629974866.png


Why it says there is a 0.21 and only has de 0.18 of this thread?

anyways: question:

I am trying to use it to print on a SUNMI K2 that is basically equal to others SUNMI innerprinters... it connects to the bluetooth, it does not give any errors, but nothing happens....

Using the test app supplied

Any help?
 

Star-Dust

Expert
Licensed User
Good morning,

The demo version that was released was in version 0.18 now it has been updated. I cannot assist you on SUNMI devices.
 

Star-Dust

Expert
Licensed User
Donated a little, waiting for library to do a proper one ;)
Hi Marvin,

Thanks for the donation. In the library thread I wrote this:

The full version of the library will be issued to those making a donation (Contact me in private before making a donation). In the donation indicate the library you want and your NickName.

Unfortunately, even though I appreciate your donation, the amount you donated does not correspond to my request. Then I will proceed to return the donation
 
Hi Marvin,

Thanks for the donation. In the library thread I wrote this:

The full version of the library will be issued to those making a donation (Contact me in private before making a donation). In the donation indicate the library you want and your NickName.

Unfortunately, even though I appreciate your donation, the amount you donated does not correspond to my request. Then I will proceed to return the donation
Hello, I would like to know how much I should donate, I am very interested in the SD-BT_Printer library.

Greetings.
 

Star-Dust

Expert
Licensed User
Code:

B4X:
Public NamePrinter As String

Sub ButtonScan_Click
    Ble.ScanPrinter
End Sub

Sub ButtonSendText_Click
    Ble.InitializePrinter
    Ble.RightJustify
    Ble.Writeline(ESC_POS.DoubleOn & "RIGHT PRINT" & ESC_POS.DoubleOff)
    Ble.CenterJustify
    Ble.Writeline(ESC_POS.FontA_DoubleHight & "CENTER PRINT" & ESC_POS.FontA_Normal)
    'Ble.LeftJustify
    Ble.Writeline("LEFT PRINT")
End Sub

Sub ButtonImage_Click
    Ble.PrintBitmap(LoadBitmap(File.DirAssets,"qr.jpg"))
End Sub

' ---------------------------  BLE EVENT  -----------------------
Sub Ble_PrinterFound(Name As String, ID As String)
    NamePrinter=Name
    log($"Found device: ${NamePrinter} ${CRLF}(${ID})"$)
    Ble.connect(ID)
End Sub

Sub Ble_Connected(services As List)
    log($"Connect to printer: ${NamePrinter}"$)
End Sub

Sub Ble_Disconnected
    log("Diconnect")
End Sub

Private Sub Ble_ImageWriteComplete
    LabelInfo.Text="Image Printed "
End Sub

Private Sub Ble_WriteComplete (Characteristic As String, Success As Boolean)
    LabelInfo.Text="Text Printed "
End Sub
 

Star-Dust

Expert
Licensed User
Any news about iOS version ?
I'm working on it.
By copying the identical code the result is not the correct one. In addition to the fact that the printing of the image is very slow
 

Star-Dust

Expert
Licensed User
new release 0.22, is it already available?
As you can see from the first post the new version is 1.00. It is already available. The free version will remain at version 0.21
 

Xfood

Expert
Licensed User
As you can see from the first post the new version is 1.00. It is already available. The free version will remain at version 0.21
to have an update of the library, for those who have previously made the donation?
 

Star-Dust

Expert
Licensed User
I did not foresee this because the new library does not add anything to the previous one regarding the Bluetooth class. But it adds a new class for BLE.

So who has the previous version does not need the new one to connect to the printers. BLE is slower than Bluetooth SPP
 

Star-Dust

Expert
Licensed User
ANNOUNCEMENT
I have also completed the TESTS for USB printing and it seems to work.
So you will have Bluetooth SPP, BLE (bacon), USB
 

Star-Dust

Expert
Licensed User
Currently I release the library in three versions:
  • 0.21 SPP bluetooth only.
  • 1.00 Bluetooth SPP + BLE.
  • 1.01 Bluetooth SPP + BLE + USB.
If you are interested in private I will be able to tell you the quotation of each version
 
Top