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,081
  • sample_bt_ble.zip
    11.3 KB · Views: 619
  • SD_BT_Printer 0.21.zip
    21.2 KB · Views: 696
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Hello is there any improvement?
After doing a search I found how to print the characters of different sets. I attach the example of Chinese:

Initialize the printer with this encoding
B4X:
Printer.Initialize(Me,"Printer","GB2312")

Precede the Chinese text with chr (27) + chr(64)
B4X:
Printer.AddBuffer_WriteLine(Chr(27) & Chr(64) & "艾德蒙 AOC E2450SWH 23.6吋")

see this link
 

Ertan

Active Member
Licensed User
After doing a search I found how to print the characters of different sets. I attach the example of Chinese:

Initialize the printer with this encoding
B4X:
Printer.Initialize(Me,"Printer","GB2312")

Precede the Chinese text with chr (27) + chr(64)
B4X:
Printer.AddBuffer_WriteLine(Chr(27) & Chr(64) & "艾德蒙 AOC E2450SWH 23.6吋")

see this link
6447a0b7-9f35-4c13-bcfd-cf78e10c24f5.jpg


Hello, I am having this problem too. It doesn't print all Turkish characters. Only ( Ç , ü , Ö , Ü ) printing these characters.
I want to write in the first line ( Çilek , Ördek , Ağaç ) but does not print ( Ç Ö ğ)
"Ş, İ, Ö, Ç, Ü, Ğ, ş, ı, ö, ç, ü, ğ" I want to print these letters. I've been researching for this for a few months but I couldn't figure it out.

Can you help me to solve this event?

B4X:
Printer.Initialize(Me,"Printer","iso-8859-9")
 
Last edited:

Ertan

Active Member
Licensed User
After doing a search I found how to print the characters of different sets. I attach the example of Chinese:

Initialize the printer with this encoding
B4X:
Printer.Initialize(Me,"Printer","GB2312")

Precede the Chinese text with chr (27) + chr(64)
B4X:
Printer.AddBuffer_WriteLine(Chr(27) & Chr(64) & "艾德蒙 AOC E2450SWH 23.6吋")

see this link
WhatsApp Image 2020-07-02 at 17.13.16.jpeg


I choose Turkish option in the settings section of this application. It's using TrueTpye font.
The printer prints these characters. How can we activate this event in the library?
 

Star-Dust

Expert
Licensed User
Longtime User
Hi @Ertan ,
The problem is probably related to your printer. I did the tests with mine and here are the results

B4X:
Printer.Initialize(Me,"Printer","GB2312")

B4X:
Printer.ClearBuffer
    Printer.AddBuffer_Writeline(ESC_POS.BoldOn & "Hallo dear" & ESC_POS.DoubleOff)
    Printer.AddBuffer_Writeline("How are you?")
    Printer.AddBuffer_Writeline("Fine thank's")
 
    Printer.AddBuffer_WriteLine("打印中文")
    Printer.AddBuffer_WriteLine("艾德蒙 AOC E2450SWH 23.6吋")


PS: Chinese = "GB18030"; Turkish = "GB2312"

1594099458640.png
 
Last edited:

asales

Expert
Licensed User
Longtime User
I am trying you lib, but I get this missing properties in the demo:
Unknown member: flushAllAndClose
Unknown member: Preview.Height, Panel.Height

sd_printer1.jpg
 

Star-Dust

Expert
Licensed User
Longtime User
Hi, How can print Greek Characters ?
It all depends on whether the printer contains this character set.
If the manual supports it, you must select the CODCE PAGE to activate the chosen character set
 

Ertan

Active Member
Licensed User
View attachment 96512

I choose Turkish option in the settings section of this application. It's using TrueTpye font.
The printer prints these characters. How can we activate this event in the library?
I tested it for a project today and it worked.
The problem is all about the character set of the printer.
if you too " ğ, Ğ, ş, Ş, ı, İ , ü, Ü, ö, Ö, ç, Ç " you want to print letters;
B4X:
Printer.Initialize(Me,"Printer","IBM857")
You should use IBM857.
Remember, if your printer still doesn't print these characters, you should correct this in your printer settings.
 

Star-Dust

Expert
Licensed User
Longtime User
Update Rel.0.18
  • Add event: DataReceived(Buffer() As Byte)
  • Add new ESC_POS command: QueryPrinterStatus, QueryOfflineCauses, QueryErrorCauses, QueryPaperStatus
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Hi:

DataReceved() is use in which cases???

Thanks!
Some printers if you send certain commands tell you the status of the printer or if it is out of paper or other errors
 

Tico.13

Member
Is there a way to set paper size, my app works fine but if i send to print more than 2 labels(paper) it starts to jump spaces
 

Star-Dust

Expert
Licensed User
Longtime User
Each label sends to the printer. It could be a buffer problem
 

Star-Dust

Expert
Licensed User
Longtime User
How to center a writeline?
See this post

or use CenterJustify method
 

Bob Spielen

Active Member
Licensed User
To speed up processing I just placed the command: Printer.SelectFromMac("00:08:1B:95:42:BD") in B4A and the flow goes to Printer_ConnectedToPrint (Success As Boolean) as true.

1. In B4J (Printer.SelectFromMac("00081B9542BD")) it doesn't work, I have to search first. Is it possible to connect directly without have to search the device?
2. Is it possible to keep printing from both devices -Mobile and PC? . Do I have to logout the printer with "close" and search the printer again when I change the sender?

Tks a lot for the reply
 
Top