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: 671
Last edited:

zenlab

Member
Licensed User
Longtime User
Hi, the demo app when i press on "Scan Print Bluetooth" return this error:
java.lang.RuntimeException: Field: LastDiscoveredDevice not found in: anywheresoftware.b4a.objects.Serial$BluetoothAdmin
 

Star-Dust

Expert
Licensed User
Longtime User
Have you updated the Serial library?
 

Star-Dust

Expert
Licensed User
Longtime User
yes! Version 1.26
Serial 1.30 is last version
I had given you the link in private when I sent you the library.

It is also written in the first post. Please follow the instructions that are indicated carefully.
 

zenlab

Member
Licensed User
Longtime User
Hallo, there is any function to check if the printer is realy connected to device? My printer after a few seccond autoclose the connection and if I send another print I can't check if i may do
 

Star-Dust

Expert
Licensed User
Longtime User
The connection to the BT printer is different from a classic printer and does not return information about the status of the printer.

If an associated printer could not be reached, the library after a few attempts generates an error MessageBox. In the next update it will raise a ConnectedToPrint(Success As Boolean) event.
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
BT_Printer 0.13 update

The event has been modified ConnectToPrint now returns a Boolean parameter so as to check if the device has connected to the printer,
B4X:
ConnectToPrint (Success As Boolean)

Also you can change the Width size of the PreView with
B4X:
ResetPreViewWidth (NewWidth as int)
By default, the value is 320dip, but you can change it for different paper sizes.

The examples have been updated
 

Star-Dust

Expert
Licensed User
Longtime User
I answer a question that has been proposed to me in private.
How can I use other ESC commands with my library?
The library is already equipped with a series of ESC commands, you can use them by listening to ESC_POS.

For example, if you would like to reset the printer:
B4X:
Printer.AddBuffer_ArrayByte(ESC_POS.InitializePrinter.GetBytes("UTF8"))
'or
Printer.AddBuffer_Write(ESC_POS.InitializePrinter)

Other commands are qiesti (you can find them also in the first post in the description of the library)
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_DoubleWideHight As String
    • FontA_Normal As String
    • FontB_Bold As String
    • FontB_DoubleHight As String
    • FontB_DoubleWide As String
    • FontB_DoubleWideHight As String
    • FontB_Normal As String
    • InitializePrinter As String
 
Last edited:

infow

Member
Licensed User
Longtime User
Keep the good work!

__________________________________
You sent R$ 100,00 to Salvatore Montoro



Transaction Details

Transaction ID: 3PU7342970565931T

19 de novembro de 2018



Money sent

R$ 100,00
 

Star-Dust

Expert
Licensed User
Longtime User
Thank you for the suggestion. I had already considered this possibility, but I did not consider it necessary.

But if you need to insert it.
 

infow

Member
Licensed User
Longtime User
It´s very userful. I have a header in any print I did, with the header in memory I can send only text... Becames a lot faster print.
 

virpalacios

Active Member
Licensed User
Longtime User
Hi Star-Dust, I tried your library but I got a toastmessage Demo Library - Sorry Not Available. Thanks very much for your help
 

Star-Dust

Expert
Licensed User
Longtime User
Hello @virpalacios, as you read in post#1, I attached a demo version to try the library, several methods are disabled except FlushAndClose that allows you to print.

You can keep the full version by making a donation, if you are interested you can get information by contacting me in private
 

vvg

Member
Licensed User
Longtime User
(No WRAP, No Java Only B4A)

BT_Printer library allows you to print text and image to a bluetooth thermal printers

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+ and Serial Library 1.30+ (here)

To try print with the demo version you can only use the FlushAndClose command which lasts 7 days and then disables.
The full version of the library will be issued to those making a donation. In the donation indicate the library you want and your NickName


View attachment 71755 View attachment 71781

SD_BT_Printer

Author: Star-Dust
Version: 0.13
  • BT_Printer
    Note: Android 6+ add on manifest
    AddPermission(android.permission.ACCESS_COARSE_LOCATION)
    • Events:
      • BluetoothIsDisabled
      • ConnectedToPrint (Success As Boolean)
      • DisconnectToPrint (Mac As String)
      • DiscoveryFinished
      • DiscoveryNewPrinter (Print As NameAndMac, DeviceClass As Int)
      • DiscoveryNoDeviceFound
      • ErrorDiscovery
      • ListPrinterAssociated (ListNameAndMac As List)
      • PrinterSelected (Mac As String)
      • SendTerminated
    • Const:
      • 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
      • Class_Globals As String
      • ClearBuffer As String
      • Close As String
      • Connected As Boolean
      • 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.
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • Preview As Bitmap
      • ResetPreViewWidth(NewWidth As Int) As String
      • SearchNewPrinter As String
        select --------------------------------------------
      • SelectFromAssociatedPrinter As String
      • SelectFromMac (Mac As String) As String
      • 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_DoubleWideHight As String
      • FontA_Normal As String
      • FontB_Bold As String
      • FontB_DoubleHight As String
      • FontB_DoubleWide As String
      • FontB_DoubleWideHight As String
      • FontB_Normal As String
      • InitializePrinter As String
    • Functions:
      • Process_Globals As String
  • Encoding
    Code module
    Subs in this code module will be accessible from all modules.
    • Fields:
      • ISO8859 As String
      • UTF8 As String
      • Windows1252 As String
    • Functions:
      • Process_Globals As String
I hv sent donation. Kindly send me bt printer library
 

vvg

Member
Licensed User
Longtime User
(No WRAP, No Java Only B4A)

BT_Printer library allows you to print text and image to a bluetooth thermal printers

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+ and Serial Library 1.30+ (here)

To try print with the demo version you can only use the FlushAndClose command which lasts 7 days and then disables.
The full version of the library will be issued to those making a donation. In the donation indicate the library you want and your NickName


View attachment 71755 View attachment 71781

SD_BT_Printer

Author: Star-Dust
Version: 0.13
  • BT_Printer
    Note: Android 6+ add on manifest
    AddPermission(android.permission.ACCESS_COARSE_LOCATION)
    • Events:
      • BluetoothIsDisabled
      • ConnectedToPrint (Success As Boolean)
      • DisconnectToPrint (Mac As String)
      • DiscoveryFinished
      • DiscoveryNewPrinter (Print As NameAndMac, DeviceClass As Int)
      • DiscoveryNoDeviceFound
      • ErrorDiscovery
      • ListPrinterAssociated (ListNameAndMac As List)
      • PrinterSelected (Mac As String)
      • SendTerminated
    • Const:
      • 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
      • Class_Globals As String
      • ClearBuffer As String
      • Close As String
      • Connected As Boolean
      • 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.
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • Preview As Bitmap
      • ResetPreViewWidth(NewWidth As Int) As String
      • SearchNewPrinter As String
        select --------------------------------------------
      • SelectFromAssociatedPrinter As String
      • SelectFromMac (Mac As String) As String
      • 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_DoubleWideHight As String
      • FontA_Normal As String
      • FontB_Bold As String
      • FontB_DoubleHight As String
      • FontB_DoubleWide As String
      • FontB_DoubleWideHight As String
      • FontB_Normal As String
      • InitializePrinter As String
    • Functions:
      • Process_Globals As String
  • Encoding
    Code module
    Subs in this code module will be accessible from all modules.
    • Fields:
      • ISO8859 As String
      • UTF8 As String
      • Windows1252 As String
    • Functions:
      • Process_Globals As String
sir, i hv sent donation for bt library.
When and hpw u r sending it? If demo is to be downloaded, then how to register it?
My paypal tr id is

ID: 1E889382M39306932 3 February
 

kurniahenki

Member
Licensed User
Sorry sir,
when using your sample i did try run on my b4x ver 8.5 and when running on debug it's normal can show the form and printing with Printer.flushAllAndClose and it work. but when i release it to .apk and install on my samsung tab 7.0 and LG Stylus2 Dual2 and try running , it keep showing apps doesn't work and keep closing.

the message is "Unfortunately, Bluetooth Printer Sample has stopped"

any solution ?

i didn't change anything,
and my manifest editor is :
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.


and i'm using only library
Core Version 8.5
RuntimePermission version 1.10
SD_BT_Printer version 0.13




thx
 

Star-Dust

Expert
Licensed User
Longtime User
What version of Android use these devices.

Does it generate any kind of error or does the app just stop?

Try setting the target SDK to 19 in the manifest. It could be a matter of runtime permissions
 
Top