B4A Class Bluetooth ESC/POS Printer Class

For the last couple of weeks I have been playing with an 80mm Bluetooth ESC/POS thermal printer I bought off eBay, new and delivered, for the ludicrously cheap price of £20. While the print quality, particularly of images with large areas of black (they are gray due to power supply or thermal dissipation limitations probably), is not great it is adequate. The printer itself seems to be a generic Chinese unit (no surprise there then!) which is re-badged by all and sundry and sold at a remarkably wide range of prices.

Here then is a Printer class that will connect by Bluetooth to the printer and enable access to most of the printer functions, including barcodes and image preparation and printing. The included demo shows the capabilities that are available. To run the demo you will need a paired Bluetooth printer that is switched on. The Printer class uses the BitmapCreator, RandomAccessFile and Serial libraries.

On my printer the only thing that doesn't seem to work properly is QR code generation. Small QR codes don't seem to be able to be decoded by scanners and larger ones look obviously wrong with part of the top of the code replicated at the bottom when printed.

The obvious capabilities missing (so far!) are user defined characters and non-volatile bit images. Also not implemented are some codes that are either duplicates of available commands or ones whose functions I don’t understand.

The class module is included as source code in the demo so you can add any missing capabilities you need. If you add a significant one then please post it for others to play with.

EDIT: Version 2 now posted includes support for creating custom characters. See post #5 for details
 

Attachments

  • BluetoothPrinter_v2.0.zip
    298.6 KB · Views: 1,546
Last edited:

agraham

Expert
Licensed User
As I say in the comment to setCodePage
"You need to look at the printer documentation to establish which code pages are supported"
You then need to match the encoding used in WriteString to the printer code page so that the UTF16 characters used internally by B4X are correctly translated to the 8bit code page of the printer. IBM437 does not include the Euro character so it will be ignored by WriteString. UTF8 does include it but WiteString is translating it to a Chinese character as the code page selected on the printer is not UTF8 compatible.
 

lelelor

Member
Licensed User
As I say in the comment to setCodePage
"You need to look at the printer documentation to establish which code pages are supported"
You then need to match the encoding used in WriteString to the printer code page so that the UTF16 characters used internally by B4X are correctly translated to the 8bit code page of the printer. IBM437 does not include the Euro character so it will be ignored by WriteString. UTF8 does include it but WiteString is translating it to a Chinese character as the code page selected on the printer is not UTF8 compatible.

good morning, thanks 1000, it works!
 
Top