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: 0.21
  • 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: 2,061
  • sample_bt_ble.zip
    11.3 KB · Views: 596
  • SD_BT_Printer 0.21.zip
    21.2 KB · Views: 672
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
With the new versions of B4A and the recent bluetooth library, the flush command was no longer needed. When sending data, it flushes and closes the connection
 

vecino

Well-Known Member
Licensed User
Longtime User
B4X:
AddBuffer_Write (Text As String) As String
AddBuffer_WriteLine (Text As String) As String
Hi again, what's the difference between AddBuffer_Write and AddBuffer_WriteLine?
Thank you.
 

Star-Dust

Expert
Licensed User
Longtime User
B4X:
AddBuffer_Write (Text As String) As String
AddBuffer_WriteLine (Text As String) As String
Hi again, what's the difference between AddBuffer_Write and AddBuffer_WriteLine?
Thank you.
In Basic WriteLn or WriteLine it has always added the CRLF carriage return at the end of the send. :)
 

Star-Dust

Expert
Licensed User
Longtime User
ciao a tutti, sto utilizzando la libreria di Star-dust per stampare con una stampantina bluetooth pos (POS-5802DD). il mio problema è il dover stampare un immagine e sto abbastanza impazzendo per riuscire a farlo nel modo corretto.
Utilizzando la libreria SD_BT_PRINTER_7 e la funzione AddBuffer_Bitmap l'immagine mi risulta sempre spostata verso destra di quasi un centimetro.... (inoltre spesso non stampa o si incasina....) qualcuno ha qualche suggerimento o consiglio?
ho provato anche ad utilizzare l'sdk fornito con la stampante per generare un array di byte da passare tramite AddBuffer_ArrayByte ma in questo caso stampa delle righe grafiche senza molto senso...
PS versione b4a 8.30 Beta #1
Grazie
Hi everyone, I'm using the Star-dust library to print with a bluetooth pos printer pos (POS-5802DD). my problem is having to print an image and I'm just going crazy to be able to do it correctly.
Using the SD_BT_PRINTER_7 library and the AddBuffer_Bitmap function the image is always shifted to the right of almost a centimeter .... (also often does not print or gets messed up ....) does anyone have any suggestions or advice?
I also tried to use the sdk supplied with the printer to generate an array of bytes to be passed through AddBuffer_ArrayByte but in this case it prints the graphic lines without much sense ...
PS version b4a 8.30 Beta # 1


AddBuffer_Bitmap (Path As String, Filename As String, LeftSpace As Int) As String

In the AddBuffer method you find a LeftSpace field, used to move the image starting from the left margin.

If you have problems with some printers, this may be because not all printers use the same method / command for images, in fact you also find the AddBuffer_Bitmap2 command. Make sure the image is not too large or the distance is not such that it loses the connection from the printer.

the sdk should not be sent to ArrayByte. the SDK is already a library, you should eventually connect it to your B4X code and recall the methods if you have the sdk documentation.
ArrayByte is used to send raw data (images, text or other) to the printer without the filter of my library, so as to add missing methods, or specific methods for certain printer models
 

zenlab

Member
Licensed User
Longtime User
mmmm. with your library version 0.04 (sd_bt_printer_7 and sd_bt_printer_ba7) if I add a parameter after the Path and the filename, return error for too many parameters
 

Star-Dust

Expert
Licensed User
Longtime User
mmmm. with your library version 0.04 (sd_bt_printer_7 and sd_bt_printer_ba7) if I add a parameter after the Path and the filename, return error for too many parameters
A solution would be, go to the first post of this thread and download the latest version
 

zenlab

Member
Licensed User
Longtime User
I've download the first post library and b4a give me always the same problem....and always the same version: 0.0.4
(in IT: ho scaricato la versione del primo post fin dall'inizio ma non c'è la versione 0.05....prova anche tu a verificare.... questo è un pezzo dell'xml: <version>0.04</version>)
 

Star-Dust

Expert
Licensed User
Longtime User
I've download the first post library and b4a give me always the same problem....and always the same version: 0.0.4
(in IT: ho scaricato la versione del primo post fin dall'inizio ma non c'è la versione 0.05....prova anche tu a verificare.... questo è un pezzo dell'xml: <version>0.04</version>)
Update to 0.05
 

zenlab

Member
Licensed User
Longtime User
OK, now is ok the version but I have the same problem....the image always start from 1cm to the left....in all of this function:
B4X:
Stampa.AddBuffer_Bitmap(File.DirAssets,"printtest.bmp",10)
Stampa.AddBuffer_Bitmap(File.DirAssets,"printtest.bmp",0)
and if I use this:
B4X:
Stampa.AddBuffer_Bitmap(File.DirAssets,"printtest.bmp",1)
the printer make only lot of charaters but not image
 

Star-Dust

Expert
Licensed User
Longtime User
Usually I do not, but exceptionally I have added a new method AddBuffer_Bmp()
Use a different system to move the image to the left. I hope it works, otherwise I can not help you further.

If you get ASCII characters instead of the image probably your printer is not compatible with this method, maybe you could have better results with AddBuffer_Bitmap2. If this is not the case, you will need to see the printer's instruction manual and enter the codes with AddBuffer_ArrayByte.

In addition, the bitmap if it is too large generates errors with the printer. Try reducing with
B4X:
Stampa.AddBuffer_bmp(LoadBitmap(path, file).Resize (width, Heigth, True),0)
 
Last edited:

zenlab

Member
Licensed User
Longtime User
One last thing ... it would be possible to add the flushall function without the close ....
 

Star-Dust

Expert
Licensed User
Longtime User
One last thing ... it would be possible to add the flushall function without the close ....
Sorry it's not possible. To send data in bluetooth my library uses the ASyncStream class of the RandomAcessFile library (rel 2.32).
The submission procedure ends with the Send and Close command
See the documentation here
 

zenlab

Member
Licensed User
Longtime User
OK, but there is a function that permit to remain connected after print? Now whenever I send a print, the printer need to reconnect for send another print...in the version 0.04 sd_bt_printer_ba7 the printer remain connected after a print until I call close...
 

Star-Dust

Expert
Licensed User
Longtime User
OK, but there is a function that permit to remain connected after print? Now whenever I send a print, the printer need to reconnect for send another print...in the version 0.04 sd_bt_printer_ba7 the printer remain connected after a print until I call close...
No. The old version used a previous version of RandomAcessFile that allowed flushing without closing.
With B4A 7+ the library has been updated and the flush command is mesos together with close, as you will have read in the tutorial I have indicated to you.

At the end of printing, try to reconnect to the printer using the ID code of the printer. Better if after a 10/20 second pause.

In the future I will implement SendBuffer, to send the buffer to the printer. But I do not know if it will solve the question because it is sent into the system buffer. The flush empties intermanete system buffers.
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Update rel. 0.07

Add this method
  • AddBuffer_Bmp (bmp As Bitmap, ShiftLeft As Int) As String
  • SendBufferToPrinter
If you want to make a donation click on the DONATE button at the bottom of this Post
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Update to release 0.08
  • Change methods of inserting images
  • Fixed Bugs on the image shift system on the left
  • Improved sending to print (SendBufferToPrint)
The next update will provide for the library to preview a print by generating an image or a view
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Preview announcement.

The new 0.09 version will be released in days.
I have eliminated some non-working printing methods and added a graphic preview of the print.

Here's what the new version will allow
Video1.gif
upload_2018-9-2_17-23-30.png


In the meantime you can try the DEMO version that you find in post#1

PS. 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 that you can find here
Or can use this library of @Johan Schoeman
 
Last edited:
Top