B4A Library SD: BT Printer (Bluetooth)

(No WRAP, No Java Only B4A)

BT_Printer
library allows you to print text and image to a bluetooth thermal printers with ESC/POS language
(Here for B4J, Here for B4i)

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)

Required: B4A 8.8+ and Serial Library 1.30+
Make sure the library meets all your needs, is compatible with the printer you need to use.


To try print with the demo version 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
  • 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,329
  • SD_BT_Printer 0.18 DEMO.zip
    21.5 KB · Views: 707
Last edited:

aviario

Active Member
Licensed User
Longtime User
Hello, I tested your library with an Intermec Pr3 printer and it does not print the bitmap

Thank
 

Star-Dust

Expert
Licensed User
There are 2 methods of printing. The former is compatible with most printers. The second with some models.

Try both. There is a third method, but I still have to experiment with it, and it is not included in the library
 

Star-Dust

Expert
Licensed User
I'm sorry. On the forum you will find many similar libraries for Bluetooth, try them and see the compatible one for your printer.
 

rkmoray

Active Member
Licensed User
Longtime User
I am trying you lib on a bt printer,but cannot figure out how to cut the paper after the printing is complete
 

Star-Dust

Expert
Licensed User
I am trying you lib on a bt printer,but cannot figure out how to cut the paper after the printing is complete
You need to know the command for cutting the paper. I do not know if it is the same for all printers
 

rkmoray

Active Member
Licensed User
Longtime User
According to the document for the printer,
"• Paper cut by GS V m n."

but I do not know how to convert that to run with your library.
 

Star-Dust

Expert
Licensed User
According to the document for the printer,
"• Paper cut by GS V m n."

but I do not know how to convert that to run with your library.
Tomorrow I'll take a look and let you know
 

Star-Dust

Expert
Licensed User
try this
B4X:
PrinterBT.AddBuffer_ArrayByte(Array As Byte(29,86,0,48))
or
B4X:
Dim N as int = 10 ' n × vertical motion unit
PrinterBT.AddBuffer_ArrayByte(Array As Byte(29,86,65,n))
 
Last edited:

rkmoray

Active Member
Licensed User
Longtime User
Thank you for the conversion. Unfortunately neither of them cut the paper as needed.
Any other ideas would be appreciated
 

Star-Dust

Expert
Licensed User
Try adding a zero after the command

PrinterBT.AddBuffer_ArrayByte(Array As Byte(29,86,0,48,0))
 

rkmoray

Active Member
Licensed User
Longtime User
So there is no misunderstanding, this is what my code is, and it still does not cut the paper.

B4X:
Stampa.Initialize(Me,"Stampa",Encoding.Windows1252)
Stampa.AddBuffer_Writeline("How are you?")
Stampa.AddBuffer_ArrayByte(Array As Byte(29,86,0,48,0))
Stampa.SendAllAndClose
 

Star-Dust

Expert
Licensed User
GS V m n
29=GS, 86 = V, m=56, n= (any number)
 

rkmoray

Active Member
Licensed User
Longtime User
I changed the arraybyte to read
Stampa.AddBuffer_ArrayByte(Array As Byte(29,86,56,10))
but it still does not cut.
 

Star-Dust

Expert
Licensed User
You need to find the right code for your printer, and sometimes the commands close with zero
 

Star-Dust

Expert
Licensed User
Is right,but no space. N = vertical motion

B4X:
Dim N as int = 10 ' n × vertical motion unit
PrinterBT.AddBuffer_ArrayByte(Array As Byte(29,86,65,n))
 
Last edited:

rkmoray

Active Member
Licensed User
Longtime User
I appreciate all the help you are giving me,and if this ever completely works, there is a pot of coffee ion it for you, not just a cup.

I have the line
B4X:
        PrintBuffer=ESC_POS.BoldOn  & ESC_POS.FontA_Bold &  ESC_JUSTIFY_LEFT & TicketCatName   & ESC_JUSTIFY_RIGHT & SellingPrice
        Starter.Printer.WriteLine(PrintBuffer)

What I am trying to do is have the first variable (TicketCatName ) on the left justified and the second variable(SellingPrice) Right justified

But what I get is basically both variables printer as if it were concatenated.
 

vecino

Well-Known Member
Licensed User
Longtime User
Hi, I am testing your library and I see that there is no example Send_Buffer_to_Print_flush.
It's a mistake?
Regards.
 
Top