B4A Library SD: BT Printer Bluetooth

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
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


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
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
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


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:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…