[FREE] BLE 'cat' thermal printer control extension

This Extension allows your application to control the low coast BLE ‘cat’ thermal printer:

Typically, such printers have their own official Android application. However, the printer protocol remains private, making it difficult for it to connect to a user application.

For example, you can make an application for a toy store that can scan products and print receipts. Your children will be delighted)

I used information from an article about reverse engineering and a ready-made library for Arduino to figure out how communication with the printer works.

The purpose of the extension is to connect a printer and print a canvas, which must first be created in the user application:

Properties:

pIsFound

pIsConnected

Methods:

Note: Search by name is needed in order to connect to a compatible device whose name is different to “MXxx”

mConnect

Note: The device must first be found

mDisconnect

mFeedPaper

Note: The extension automatically converts the canvas to black and white. However, to avoid unpredictable results, it is better to draw the image in black and white. If desired, the image can be converted to the width of the printer paper, or centered.

Events:


Possible error codes:
ERR_BLE_NOT_SUPORTED=1;
ERR_API_LEVEL_NOT_SUPORTED =2;
ERR_SYSTEM_NOT_SUPORTED =3;
ERR_BLE_IS_DISABLED =4;
ERR_SCANNER_ALREADY_RUNNING =5;
ERR_BLE_ALREADY_CONNECTED =6;
ERR_BLE_DISCONNECTED =7;
ERR_TPCAT_NOT_FOUND =8;
ERR_TPCAT_NOT_CONNECTED =9;
ERR_BLE_SEND=10;
ERR_TPCAT_ALREADY_PRINTING =11;
ERR_TPCAT_PRINT_ERROR =12;


Possible status codes:
ST_INIT_SCAN = 1;
ST_STOP_SCAN = 2;
ST_BLE_DEV_FOUND = 3;
ST_TPCAT_FOUND = 4;
ST_TPCAT_INIT_CONNECT = 5;
ST_TPCAT_CONNECTED = 6;
ST_TPCAT_DESCONNECTED = 7;
ST_TPCAT_PRINT_COMPLETE = 8;

Current Version:
ScBleTpCatV2.aix (38.5 KB)

Test Project :
BleTpTestV2.aia (132.4 KB)

Note: The extension was only tested on printer “MX05”. Perhaps it will work on other similar printers, with a paper width of 56mm and a resolution of 384 pixels.

8 Likes

Hi
Thanks very much for the extension i was looking for this…can you also post apk file of this project for testing? And can you also print text from textbox or do you have a tutorial video on how to use this extension? Thanks again

1 Like

Hi! I will be glad if my extension is useful to someone.
APK for testing:
BleTpTestV2.apk (3.5 MB)

Using the extension is very simple:

  1. Turn on your cat-printer. The blue LED on the device will blink.
  2. Give the command “Searh the device and then connect”.

When the printer is connected, the blue LED on the device will light continuously and the printer will feed a small amount of paper.
Note: During the first synchronization, the application may ask for ACCESS_FINE_LOCATION permission. This is due to the fact that the application, when connected to a BLE device, can read its signal level. Which, in turn, can be used to calculate the exact location of the device in the room using triangulation (there must be at least 3 connected devices). In our case, this is not used, but permission will still have to be given.
For devices with Android 12+,extension will ask for BLUETOOTH_SCAN and BLUETOOTH_CONNECT permissions too.

  1. You need to create a Canvas, load a background image on it and write something.
  2. Then give the command “Print canvas”:

    Note: The extension is not intended for printing from a text box. It prints an image obtained from Canvas, where you can change the font size and style, as well as have a final printable view.

This is all. The remaining methods, properties and events are not required to be used.

2 Likes

Hi,
I congratulate you for this the extension I was looking for…I tried to use it but I can’t connect it.I’m using Android 12+ Do you have a video tutorial on how to use this extension? Please help me

Hi,
ScBleTpCatV2 was tested on Android version 14. You must run a test project and remember the error messages during connection.

Hi,
bluetooth scan ok
connection ok
FeePaper ok
Print canvas , there is the following error


Thank you in advance for your help

The method getBitmap() appeared recently in a new version of the Canvas class. It works in MIT AppInventor, but may still not be updated in the Kodular runtime.

Thanks, it works in MIT AppInventor but we’re waiting for kodular

I can’t connect to the ESC POS printer (RPP02N), is this extension only for MX05?

This printer has the required resolution, but its communication protocol is not known. You need to know the name (or part of the name, possible RPP) of the device determined by the BLE in order to try to connect to the extension.

Well, I’m also having the same issue as @fredo mentioned. So it there any alternative way to manage the getBitmap() thing in kodular?

If I just try to save the canvas image to folder and try converting the image to bmp and passing it to .PrinhtCanvas method, will it work? Or what type of data canvas argument of .PrintCanvas method accepts?

The PrintCanvas method takes a Canvas type as an argument. It extracts a bitmap from it. Theoretically, I can make an additional method that takes a bmp right away, if needed.
But as I understand it, standard tools do not allow reading image files. And the Image element cannot share a picture.