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

Theera

Well-Known Member
Licensed User
Longtime User
Thank you so much,Timwil @Erel, I think that we have to need some library to manage these codes about printing,don't you?
 
Last edited:

Gabino A. de la Gala

Well-Known Member
Licensed User
Longtime User
By default, I only get a blank screen.

To get the printer prints, I had to modify like this:

B4X:
Sub Activity_Resume
    Toggla.TurnBluetoothOn
    PrintBuffer="Hola Mundo!"
    StartPrinter
End Sub
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Hello:

I have an HP OfficeJet (shows up as DeskJet in the Bluetooth print program given here) 100 Mobile that I want to start printing to.

Has anyone done anything with the HP Mobile?

Thanks in advance

BobVal
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Is it some how possible to treat a Bluetooth device like a canvas and draw to it?

I am using an HP Mobile 100 and was wondering if I could just treat it like a graphics monitor and draw to it?

If so how?
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
OK, I found out my HP Mobile uses the HP PCL 3 codes to control the printer

I found a PCL 3 manual here: http://www.service.belhard.com/documentation/PCL3_developers_guide.pdf

If you modify the BTPrint program that I found in this Thread with this code:

B4X:
printer.WriteLine(Chr(27) &"E" &Chr(27) &"&l2a0O" &Chr(27) &"&k1w5W" &Chr(27) &"&" &"l1l8d88p6e72F" &Chr(27) &"(s0p12H" &Chr(27) &"&a6l90M" 	_
		 	 &Chr(27) &"*p-95y+475X" &Chr(27) &"(12U" &Chr(27) &"(s6h12v0s3b6TDeskJet printer Family" &Chr(27) &"(& l9C" &Chr(13) &Chr(10))
						 
printer.WriteLine(Chr(27) &"(s1p12v0s0b4101TIn February 1988, HP introduced the original DeskJet printer at a U.S." 				_
		 	  &"List price of $995. The DeskJets market position was Laser Quality Output for Under $1,000" 					_
		 	  &"AND offered a superior print quality alternative For users intending To upgrade To 24 wire dot" 				_
		 	  &"matrix printers.")
						  
printer.WriteLine("In April 1989...")
		
printer.WriteLine("...support For MS Windows 3.0. " 									 											_
		 	  &Chr(27) &"*p2875y1800X" &Chr(27) &"(s0p24h6v0s0b6TCopyright 1990 Hewlett-Packard Co. " &Chr(27) &"E")
						  
printer.WriteLine("")

This will print a Header in a large font and some text then print a Footer in the bottom right corner (very small font)

I copied this example from the manual in the link above (page 116 - Section 14)

Well this at least proves to me, that we can completely control the printer (printing full pages, different texts, etc)

So now I got my work cut out for me writing a PCL driver to makes printing for me easy.

Off to do some coding


BobVal
 

AndrewF

Member
Licensed User
Longtime User
Thanks for your sample app. Got me printing in no time at all! Also some useful use cases that I hadn't considered.

Just to let you know it works with an MTP58 - Chinese Printer. This also uses the same code set as the MTP80 if you need a wider print roll. This also has ESC/POS.
 

metzeller_2013

Member
Licensed User
Longtime User
Hi,
Good day, is there a way to detect if the printer successfully printed? A form o feed back so that the app would know if printing is successful? I was using this code for receipt printing then saving data to a database. Sometimes I'm experiencing miss prints but how do i detect miss prints, hope you can help me. Thanks in advance
 

timwil

Active Member
Licensed User
Longtime User
Don't know - this is why i put in a reprint loop, just in case something happened to the printing.
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I have been printing to my printer using then basic example I put here: http://www.b4x.com/android/forum/threads/bluetooth-printing-to-hp-deskjet-100-mobile.36089/

And as long as I wait for the connected sub to be called I never miss a print. Now one of the problems I can see happening is that the Bluetooth Printer has gone to sleep. Maybe you need to reestablish the connection to wake it up? This is just a guess, because I know my printer goes to sleep and then powers down after a while (if running on battery).

Something to think about.
 

timwil

Active Member
Licensed User
Longtime User
This is why I put the printing in a loop and ask the operator to reprint if necessary

The printer could be off

The paper could be out

The transmission could be corrupted or lost

....and so on
 

metzeller_2013

Member
Licensed User
Longtime User
Good day,
Has anyone tried this code on Bixolon Printers? E.g SPP-200 model, TIA

Updated: Confirmed working via old post
 
Last edited:

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Most printers support some form of PCL (Printer Control Language) I geared most of the functions in this toward PCL3 because that is what the HP Mobile Jet has, but they should work on almost anything.

Bob
 

microbox

Active Member
Licensed User
Longtime User
Hello... does anyone had played with datamax-oneil bluetooth thermal printer? It has a different set of printer commands...can you please share a example code how to print double height/width text?
 

timwil

Active Member
Licensed User
Longtime User
You will have to get the command reference or programmer reference. That will tell you what you have to send to the printer.
 

microbox

Active Member
Licensed User
Longtime User
You will have to get the command reference or programmer reference. That will tell you what you have to send to the printer.
Hi timwil...thank you for replying. I got the manual... first I'm interested with bigger character size to print. So I'm focusing(not really sure) with set commands below
fromManual.png
Escape Sequence: ESC K 1 CR
Hexadecimal: 1B 4B 31 0D
Decimal: 27 75 49 13
Just to to have a test print...is the following command correct?
PrintBuffer = Chr(27) & Chr(75) & Chr(49)& Chr(13) & PrintBuffer
 

timwil

Active Member
Licensed User
Longtime User
That looks about right

Give it a try - what the worse that can happen? :)
 

microbox

Active Member
Licensed User
Longtime User
That looks about right

Give it a try - what the worse that can happen? :)
I was able to make a test print with this code
Decimal: 85 & 49 ' Bold ON
Decimal: 14 ' double wide ON
Decimal: 28 ' doubel height ON
PrintBuffer = Chr(27) & Chr(85)& Chr(49)& Chr(14) & Chr(28) & PrintBuffer & Chr(10)&Chr(13)

Textprint.jpg
But I need to make the font larger(twice the height).. from the manual I post #76 I should able to create big font
Example 2: The following escape sequence set the pitch to 25 CPI Verin Font:
Escape Sequence: ESC K 1 1 CR
Hexadecimal: 1B 4B 31 31 0D
Decimal: 27 75 49 49 13
But it's not printing the to a bigger font size when including them in line command.
 
Top