Android Tutorial BlueTooth Printing via SPP

I finally have reliable, stable printing to a blue tooth printer (Citizen CMP-10 and CMP-20) from my Samsung 5570L Galaxy Mini Android Device running v2.3.6

Attached is a skeleton project (based on the Serial example posted here) in Basic4Android v1.8 that requires the following libraries

Core v1.77
Serial v1.20
ToggleLibrary 1.00

It may work with other versions but this is what works for me in my specific situation


To print you must first pair the phone/device to the printer

In the program you must place what you wish to print in PrintBuffer (string) variable and call StartPrinter (sub)

If the printer is not turned on it returns an error message and allows you to reprint

Hope this helps someone :)

Tim
 

Attachments

  • BTPrint.zip
    8.7 KB · Views: 5,657
Last edited:
Hi Timwil/ everybody,

I am working with the DATEC DPP 350. I have it hooked up to a serial window on my P.C over bluetooth and in normal protocol mode I can write text to it and with a line feed and carraige return get it to print successfully. THe problem is when I enter protocol mode to try and gain full control over the unit nothing seems to work. Bluetooth connection is still good. Is it the ay I am writing the data.? For example I want the buzzer to sound. In the manual it says ESC RS to activate this. I type this into my terminal with a carraige return and line feed and send. Nothing happens, I have tried to send it many different ways, E.G no CR no LF etc. I do get a response back to my terminal wondow of C5 04 00 00 when I send ESC RS.

Can anyone shed some light on this. I am hoping to integrate this into a project using an STM32 so I want to prototype it on my desktop to see ease of use first.

Thanks in advance.
 

luke2012

Well-Known Member
Licensed User
Hi @timwil / everybody,
about ESC / POS commands I'm dealing with the justification commands.

For example:

For left justification I'm using the command "ESC a 0" successfully.
For right justification I'm using the command "ESC a 2" successfully.

B4X:
dim rightJust as string = Chr(27) & "a" & 2
dim LeftJust as string  = Chr(27) & "a" & 0
dim Str1 as string = "abc"
dim Str2 as string = "cde"

'to print a line with Left justification
dim Str1Left as string = LeftJust & Str1

'to print a line with Right justification
dim Str2Right as string = rightJust & Str2

In this way all works fine.
But how to align some text left and some text right within the same line ?

If a send the following commands to the printer the line is right justify (the last command overwrite the first line command?)

B4X:
dim rightJust as string = Chr(27) & "a" & 2
dim LeftJust as string  = Chr(27) & "a" & 0
dim Str1 as string = "abc"
dim Str2 as string = "cde"

'to print a line with Left justification for the first word and right just. for the second word
dim StrLeftAndRight as string = LeftJust & Str1 & rightJust & Str2
 
Last edited:

timwil

Active Member
Licensed User
Whatever justification you use is for the whole line - you cannot mix align left and align right on the same line

My solution to that problem is as follows

Count the number of character locations per line - they are fixed width and it is usually 32 or 42 depending on the font used

if the one on the left is 8 characters and the one on the right is 10 pad the middle with the difference in size. That is 32 - (8 + 10) = 14 so Print Left Information + 14 spaces plus right information
 

timwil

Active Member
Licensed User
Hi Timwil/ everybody,

I am working with the DATEC DPP 350. I have it hooked up to a serial window on my P.C over bluetooth and in normal protocol mode I can write text to it and with a line feed and carraige return get it to print successfully. THe problem is when I enter protocol mode to try and gain full control over the unit nothing seems to work. Bluetooth connection is still good. Is it the ay I am writing the data.? For example I want the buzzer to sound. In the manual it says ESC RS to activate this. I type this into my terminal with a carraige return and line feed and send. Nothing happens, I have tried to send it many different ways, E.G no CR no LF etc. I do get a response back to my terminal wondow of C5 04 00 00 when I send ESC RS.

Can anyone shed some light on this. I am hoping to integrate this into a project using an STM32 so I want to prototype it on my desktop to see ease of use first.

Thanks in advance.
I have NO idea about protocol mode

sorry
 

luke2012

Well-Known Member
Licensed User
Whatever justification you use is for the whole line - you cannot mix align left and align right on the same line

My solution to that problem is as follows

Count the number of character locations per line - they are fixed width and it is usually 32 or 42 depending on the font used

if the one on the left is 8 characters and the one on the right is 10 pad the middle with the difference in size. That is 32 - (8 + 10) = 14 so Print Left Information + 14 spaces plus right information

Yes. this is the smarter way to avoid the problem. Thanks @timwil :)
 

luke2012

Well-Known Member
Licensed User
Hi to all,
is there a standard ESC / POS command that tell to the printer to auto feed after the print session (buffer to print) ?

In my case I leave some blank lines after the last printed row, but this is OK only for specific (tested) printers (ex. RONGTA RPP02N printers) not for others (to view all the rows printed the user must push many times the feed button on some printers different from RONGTA RPP02N).
 

DonManfred

Expert
Licensed User

Mikel Huerta

Member
Licensed User
Very Very thanks Timwil !!, u save my project !!
Very good job, it works with Samsung galaxy tab2 7" and a 58-II thermal printer
 

infow

Member
Licensed User
Hello,
Anyone feed up the logo on Bluetooth printers with B4A and ESC?
In DPP 250 we have this instructions it seems 1 bit .bmp format:

(GS *) Defining a Downloaded Bit Image (logo) Code [1Dh] + [2Ah] + n1 + n2 + D1 + … + Dn
Description The command defines a bit image that contains number of dots, defined by n1 and n2.
Image is stored and after the printers is switched off.
The so defined bit image is printed with command GS /.
n1 Between 0 and 127. It defines the horizontal size of the downloaded image.
n2 Between 0 and 248. It defines the vertical size of the downloaded image.
Di The data for the bit image. This data consist of n1*n2 bytes, from left to right and from top to bottom, but n1 bytes in each horizontal line (n1*8 dots) and n2 lines. Each bit defines a dot, 1 corresponds to black. Total number of bytes cannot be bigger than 16 kB. The command defines a bit image that contains number of dots, defined by n1 and n2. Image is stored and after the printers is switched off. Selececting value 0 for n1 and/or n2 deactivates (deletes) the logo. By default there is no logo image in the printer. The so defined bit image is printed with command GS /
 
Last edited:

infow

Member
Licensed User
I get something like it, but can´t get work:

x=16: y=5
PRINT #1, CHR$(&H1D);"*";CHR$(x);CHR$(y);
For i=1 To x*y*8
READ a$: d=VAL("&H"+a$)
PRINT #1, CHR$(d);
Next i
PRINT #1, CHR$(&H1D);"/";CHR$(0);CHR$(&HA);¬ Normal
 

Bright

New Member
Licensed User
Can someone please assist me . I have paire the bluetooth Printer to my phone. I run the sample provided the Printer_Connect event doesnt fire.
The application just stay bank.
 

Bright

New Member
Licensed User
Can someone please assist me . I have paire the bluetooth Printer to my phone. I run the sample provided the Printer_Connect event doesnt fire.
The application just stay bank.

Solved----Sorry i had not called the StartPrinter Function
 
Top