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
The example (Post#1) has been modified to illustrate how to print characters of a different font transformed into an image
 

vvg

Member
Licensed User
Longtime User
The example (Post#1) has been modified to illustrate how to print characters of a different font transformed into an image
I checked your new sample1.
1. It gives result (print) with some garbage values as shown in attachment.
2. When I replaced your code line with mine i.e. .... Printer.AddBuffer_Bitmap(CreateImage("श्री गणेश",xui.CreateFontAwesome(16)),0)
It converted that font into image properly & shown in preview too. But it printed blank.
 

Attachments

  • print1.jpeg
    print1.jpeg
    43.5 KB · Views: 364

Star-Dust

Expert
Licensed User
Longtime User
I checked your new sample1.
1. It gives result (print) with some garbage values as shown in attachment.
2. When I replaced your code line with mine i.e. .... Printer.AddBuffer_Bitmap(CreateImage("श्री गणेश",xui.CreateFontAwesome(16)),0)
It converted that font into image properly & shown in preview too. But it printed blank.
  1. Your printer may not be fully compatible. Or the Bluetooth connection between the device and the printer is weak and loses the connection.

  2. you have to use your Fonts, CreateFontAwesone generates characters with the Font "Awesone".Use the xui.CreateFont("NAME TTF",SizeFont) command .....
For the rest you have to do it yourself, I have the impression that you lack the basic knowledge to develop the project you have in mind.

Please do not fill out the thread with continuous requests for assistance. Open a separate thread for your requests
 

vvg

Member
Licensed User
Longtime User
  1. Your printer may not be fully compatible. Or the Bluetooth connection between the device and the printer is weak and loses the connection.

  2. you have to use your Fonts, CreateFontAwesone generates characters with the Font "Awesone".Use the xui.CreateFont("NAME TTF",SizeFont) command .....
For the rest you have to do it yourself, I have the impression that you lack the basic knowledge to develop the project you have in mind.

Please do not fill out the thread with continuous requests for assistance. Open a separate thread for your requests
Ok
Sorry for trouble.
I will try...
I knew my mistake. Firtstly I should hv known about 'what is font awasome'. & How is it used.
I think you hv given enough hints for me.
I do not think i will require help further but if required a littlebit, i will ask on different thread.
Or personally i will message you.
Please tell there how much donation should i give for your library.
Regards...
 

vvg

Member
Licensed User
Longtime User
Latest update:
Issue resolved.
Many many thanks to star-dust.
Also many thanks to other members like erel, don manfred, ilan, klaus, moster67, lucas, somed who shown interest in my issue.
 

ekologi

New Member
Licensed User
Longtime User
Hi, all.
Just jumped to this forum try to find printing QRCodes using bluetooth printer and get stuck with the sample from https://www.b4x.com/android/forum/threads/sd-bluetooth-printer.85750/

Does anyone have same problem while compiling the sample code ?
"Error description: Unknown member: createfontawesome" , anyone has solution or be kind to share some 'working' sample, TIA

I'm using b4a 8.5 and XUI 1.72, please help, TIA
 

Star-Dust

Expert
Licensed User
Longtime User
Copy the error exactly as it appears. so I can understand also which line gives you the error.
 

abilio486software

Active Member
Licensed User
How to send an ESC/POS in the library for:

- Right / left / center alignment;
- Printer setup for Portuguese codepage

Thanks,
Abilio
 

Star-Dust

Expert
Licensed User
Longtime User
How to send an ESC/POS in the library for:

- Right / left / center alignment;
- Printer setup for Portuguese codepage

Thanks,
Abilio
Left ESC a 0 (Byte: 27 97 48)
Center ESC a 1 (Byte: 27 97 49)
Right ESC a 2 (Byte: 27 97 50)
 

aviario

Active Member
Licensed User
Longtime User
Hello, I am interested in buying this library, can you advise me which printer should I buy to work with this library?

Thank you
 

Star-Dust

Expert
Licensed User
Longtime User
Hello, I am interested in buying this library, can you advise me which printer should I buy to work with this library?

Thank you
From the messages you sent me in January 2018, I thought you already had a printer to test.
Hello, I tested your library with an Intermec Pr3 printer and it does not print the bitmap

Thank
In any case, I use a Chinese printer, it costs around € 30
s-l640.jpg
 

aviario

Active Member
Licensed User
Longtime User
Thanks for the information, what are you telling me is 58mm and I need an 80mm one of the picture that is of the same brand would also work?

Greetings

upload_2019-9-17_12-41-30.png
 

Star-Dust

Expert
Licensed User
Longtime User
Thanks for the information, what are you telling me is 58mm and I need an 80mm one of the picture that is of the same brand would also work?

Greetings
I think so.

Any printer that supports ESC POS works, make sure it is compatible with ESC POS.
 

By-Cod3rs

Member
Licensed User
Will "Turkish language support" be added to your library? or do you have?

"Ş,İ,Ö,Ç,Ü,Ğ , ş, ı , ö , ç , ü , ğ" - letters such as.
 

Star-Dust

Expert
Licensed User
Longtime User
Will "Turkish language support" be added to your library? or do you have?

"Ş,İ,Ö,Ç,Ü,Ğ , ş, ı , ö , ç , ü , ğ" - letters such as.
You can see the Character Set with this code. Send a photo of what you print.
B4X:
Dim S As String =""
For i= 32 To 255
     S= S & Chr(i)
Next
Printer.AddBuffer_WriteLine(S)
 

By-Cod3rs

Member
Licensed User
You can see the Character Set with this code. Send a photo of what you print.
B4X:
Dim S As String =""
For i= 32 To 255
     S= S & Chr(i)
Next
Printer.AddBuffer_WriteLine(S)

" ISO8859-9 " no format.

Since it does not have a format, it prints Chinese letters.
 

Attachments

  • karakter.jpeg
    karakter.jpeg
    106.1 KB · Views: 306

abilio486software

Active Member
Licensed User
My customers use some printers exactly like that model and you will need a command to switch off the "chinese mode". Check the printer CD and ESC/POS manual.
 
Top