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: 6,400
Last edited:

Theera

Well-Known Member
Licensed User
Longtime User
Fix position of print out on paper

Hi Tim
Sub Printer_Connected (Success As Boolean)
If Success Then
printer.Initialize(cmp20.OutputStream)
printer.WriteLine(PrintBuffer) <==This Line ,Could I fix @row,col?
printer.Flush
.....

End If
End Sub

p.s. I'm not good at English.

Best Regards
Theera
 

timwil

Active Member
Licensed User
Longtime User
Theera

The printers I use are all in Line Mode. This means it prints one line at a time. So you cannot print on line #5 then go back and print on line #2. You would have to print Line #2, 3 , 4 then 5.

Some printers have Page mode that would allow you to specify exactly where on the page you want to print.

The code I have provided only allows you to send something to the printer. What you send to the printer is determined by placing that string of command codes and text into the variable PrintBuffer and sending it to the printer which produces the output.

You would have to choose the printer that you were working with first.

Is that any clearer? Hope that helps.

Tim
 

mrjaw

Active Member
Licensed User
Longtime User
Hi!
I am testing this example with chinese printer TIII Bluetooh, this printer works so fine for WinMobile using B4PPC.
1-i turn on the bluetooth to my phone
2-paired from SO the device I get the messane "Sincronized but without conection"

When I run the app in the phone just I get a blank screen. Nothing happens.

Any cluees?
 

mrjaw

Active Member
Licensed User
Longtime User
The Sub Printer_Connected (Success As Boolean) can receive another parameter to print.
I have to print different tickets and reports and I dont want to repeat. I want to send the data to print as "PrintTicket(data)" , PrintReport(data).
 

mrjaw

Active Member
Licensed User
Longtime User
These are the specifications for the printer mini printer SPIII

Print
Printing Method
Thermal Line

Printing Speed
50mm/s(average), 65mm/s(max)

Resolution
8 dots/mm, 384 dots/line

Effective Printing Width
48mm

Character
Character Set
ASCII,GB2312-80(Chinese)

Print Font
ANK: 12 x24 Chinese: 24 x 24

Character per Line
32/42

Paper Spec
Paper Type
Thermal paper

Paper Width
57.5± 0.5mm

Paper Roll Diameter
Max: 40.0mm

Roll Core Inner Diameter
13mm(min.)

Paper Thickness
0.06 to 0.07mm

Paper Supply Method
Drop-in Easy loading

Reliability
MCBF
15 million lines

TPH
50km
Barcodes
EAN-13, EAN-8, UPC-A, UPC-E, CODE39, CODE93, CODE128, CODABAR, INTERLEAVED 25

Emulation
ESC/POS

Sensor
Paper End Sensor
 

mrjaw

Active Member
Licensed User
Longtime User
Again here...Better.....
 

Attachments

  • esp.JPG
    esp.JPG
    95.2 KB · Views: 830

timwil

Active Member
Licensed User
Longtime User
What is the price like on it?

Where can it be purchased from?
 

iliberis

Member
Licensed User
Longtime User
Well, we can add another printer to the list. SPIII BT it is a chinese printer so cheaper.
Now , m y problem is to use ESC/POS command in this page there is an example using basic somebody can translate this to use with B4A?

Here is the table and exmaple

http://postechgroup.com/updata/suppo...FAQ_ESCPOS.pdf

In BASIC, we used "Print#1" for sending text (and codes) to the printer port. In B4A, this is not necessary. When we want to print codes, we'll put it in the PrintBuffer variable:

B4X:
PrintBuffer=PrintBuffer & Chr(27) & Chr(69) & "Bold text sample"

This code should activate bold text.
 

mrjaw

Active Member
Licensed User
Longtime User
I bougth from China supplier. The price is around 200usd in your country. I guess
 

jjmairena

Member
Licensed User
Longtime User
Hi Timwil,
I downloaded your BTPrint.zip file for my test. I need to learn it. after exacted BTPrint.zip ,and then test with emulator ,it has error occurred.

P.s. I 'm not good at English

Best Regards
Theera
:sign0098:

hello how are you excuse my bad English, step or tell you that I understand this example because I run priate download and I do not see anything on your screen, then what I did was add a EditText and a button to link them but I press send cuendo tells me put the device key and then throws me an error.
 

jjmairena

Member
Licensed User
Longtime User
hello how are you excuse my bad English, step or tell you that I understand this example because I run priate download and I do not see anything on your screen, then what I did was add a EditText and a button to link them but I press send cuendo tells me put the device key and then throws me an error.
 

timwil

Active Member
Licensed User
Longtime User
hello how are you excuse my bad English, step or tell you that I understand this example because I run priate download and I do not see anything on your screen, then what I did was add a EditText and a button to link them but I press send cuendo tells me put the device key and then throws me an error.

I do not understand what you are asking. You were not able to compile the example?
 

Joggi

New Member
Licensed User
Longtime User
btprint error

Hi timwil,

I encounter an error in the source code you give. Do i nid to add permission in the manifest file for bluetooth? The problem is toogle.turnbluetoothon and off. it might be that the problem is the toggle library or whatever. I'm just new in b4a. I hope you can help me with this.
 

timwil

Active Member
Licensed User
Longtime User
The toggle library is not absolutely essential. I just use this for my own convenience. You can take that code out but you must be sure to have bluetooth enabled otherwise you will not connect to the printer.
 

radmk

New Member
Licensed User
Longtime User
Hai timwil,
could you elaborate the usage of your code. as when we try to run your application, it is showing a blank screen.
regards,
Murali.
 
Top