Android Example Bluetooth Printing to HP Deskjet 100 Mobile

I took the BTPrint.zip and modified it to print to my HP Deskjet 100 Mobile using Bluetooth

Attached find a new Zip BTPrint-2.zip (did not want to confuse it with the other one) and a PNG files showing what it would output if attached to a HP Deskjet 100 Mobile

I've written enough routines that I should be able to write my app and print to the printer.

I am sure that there are probably better ways to do things (I am all ears).

Hope this makes someone's life easier

NOTE: Had to delete the Objects directory - got a message too large when trying to upload

NOTE2: The attached print page was scanned in (so it doesn't look as good as it really does)


BobVal
 

Attachments

  • BTPrint-2.zip
    6.9 KB · Views: 893
  • PrintOutExample.png
    PrintOutExample.png
    38.1 KB · Views: 806

Theera

Well-Known Member
Licensed User
Longtime User
Hi Robert,
Could you guide me to do as same as yours,I use Canon ip2770 printer which wired printer(I 've used NjDude's strategy via cloud printing,but I cann't fix the position(x,y) for printing ),How do I edit your coding? Thank you in advance.
 
Last edited:

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I am surely confused when you say "How do I edit your coding", If you open the application in Basic4Android IDE everything should be editable
 

Theera

Well-Known Member
Licensed User
Longtime User
Hi Robert,
I'm sorry for my question make you terrible,I need to ask you that if I use Canon ip2770 instead,I must see where is the part of the codes. (I think that you use HP Deskjet 100 Mobile using Bluetooth,you must have specifically coding.)

Example In cPCL3 and cBTPrinter as class modules ,I must change any codes in them,don't I?
 
Last edited:

Robert Valentino

Well-Known Member
Licensed User
Longtime User
If your devices is a blue tooth device it should work as is for the device.

NOW will the printing characters work? You need to just download BTPrint-2.zip file and run it and see what happens. If everything prints fine you can go from there.

If your device is not blue tooth then I am not sure how you are going to print to it. Also you may have to Pair your Printer with your Android.

There is a place in the code BTPrint.b4a
B4X:
 '-----------------------------------------------------------------
 '  This is my Printers Mac Address by passing it I do not have
 '       select which device I want to use each time
 '-----------------------------------------------------------------
 BTPrinter.Connect("2C:27:D7:A2:8B:50")

This is the ONLY line I believe that is specific to my Printer / Android.

I knew/know the Mac Address of my printer and by passing it I did not have to select the printer from a list each time.

if you just do:
B4X:
BTPrinter.Connect("")

And not pass a Mac Address (just an empty string) then you will get a list of devices and have to select one to print to.

Hope this helps. Won't be able to reply for a while have some important business to take of.

Good luck.
 

Theera

Well-Known Member
Licensed User
Longtime User
Hi Robert again,
Have you read this? Perhaps help you some codes. I'll try to do as your guide,Thank you.
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I updated BTPrint-2.zip

Fixed some of the errors that occur if Bluetooth printer is disconnected in print process and made it a complete demo app with buttons and messages

This is a complete app with print out example.

See JPG file attached to see what the print out looks like

Have fun

BobVal
 

Attachments

  • BTPrint-2.zip
    68.5 KB · Views: 640
  • PrintOutExample.jpg
    PrintOutExample.jpg
    73.6 KB · Views: 644

swarupsengupto

Member
Licensed User
Longtime User
I get an error "System.OutOfMemoryException" as soon as I run the code from your BTPrint-2. where am I wrong? I am using b4a version 2.52, Library:Core ver-2.47, Serial ver-1.21, ToggleLibrary ver-1.00.


The Error shown is:

Parsing code. 0.13
Compiling code. Error
Exception of type 'System.OutOfMemoryException' was thrown.
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
The only things I see different from what I am running is Library Core is 3.41, Serial 1.23

Not sure why you Library core and serial versions are so far behind.

Maybe you should upgrade them and try again.

Bob
 

Krammig

Member
Licensed User
Longtime User
Trying to compile the app in B4A 6.0 and I get the following error, hope you can assist please.

B4A version: 6.00
Parsing code. Error
Error parsing program.
Error description: 'End Sub' is missing.
Occurred on line: 251 (cPCL3)
Sub EjectPaper: SendESCBytes("&l0H") : End Sub

thanks
 

Krammig

Member
Licensed User
Longtime User
SOLVED

B4A does not like all the code on one line separated by :

Sub FontCourier : mMaxCols = 80 : SendESCBytes("(s3T") : End Sub

Changed all these lines to the following format

Sub FontCourier
mMaxCols = 80
SendESCBytes("(s3T")
End Sub
 
Top