Other Direct Printing (USB, wi-fi, BT)..again!

udg

Expert
Licensed User
Longtime User
Hi all,

I've just browsed into a few threads about direct printing from an Android device to a printer (BT, wi-fi or USB). I'm also aware of manufacturer specific drivers (e.g. HP ePrint).

What I'm curious about is what am I missing when I dream of an USB printer cabled to my Android device and an app that sends its printing output direct to that printer using a simple "serial channel" and some ESCape sequences.
Yes, I understand that printers "speak" different printing languages, but there are a few well-known "standards" that should be easy to encapsulate in a generic library.

One example could be the PCL set recognized by HPs printers.
So, can you confirm we just need an appropriate USB cable, an USB communication library and a "printer language" library in order to have our apps to directly print at least some simple text and graphics?

Umberto
 
Last edited:

udg

Expert
Licensed User
Longtime User
I began some experimenting with what I have available here, an HP DJ 3520 machine reachable by my wi-fi network (not the one-to-one direct printing, just the regular router-generated wi-fi network).
Using Sockets from the net lib and AsyncStreams I managed to send data to its port 9112 (echo port) correctly resulting in that same data echo back.
But addressing port 9100 (the one where Windows programs send their printing jobs through the Windows driver) it result in .. NOTHING!
I guess that something arrives to the printer because its LCD panel lights up when sending data through port 9100, but then no feedback is provided neither in the form of the expected paper printing nor in the form of return messages.
I even tried to send escape codes to query about printer status to no avail.

If you have any suggestion or hint, please let me know. Thank you.

Umberto
 
Upvote 0

Mark Zraik

Member
Licensed User
Longtime User
Hi Umberto,

Did you make any progress in this effort?

I too, have been attempting to use a HP (a 3510) over wifi with little success so far. After reading your post, I downloaded the PCL Manual from HP which lead to cross-eyed vision. It looks monumental.

Over wifi you get successful conections on ports 80,8080,443,9100 - but not 9112. The PCL Manual has a whole section on getting feed back from the printer, just haven't figured it out yet. I'm going to keep poking at it.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi,

unfortunately no progress so far. I posted a question on HP forums time ago but received no response.
I see that you were succesful on sending data on port 9100 but not on 9112, just the opposite of what I experienced. Would you mind if we exchenge our code in order to find (hopefully) a working combination?

Umberto
 
Upvote 0

Mark Zraik

Member
Licensed User
Longtime User
Hi Umberto,

To be clear, I was able to get a connection, but not able to get the file to print, yet.
The connection may only be granted since the printer has a Web/HTTP(s) interface...???

I'm working on using PJL/PCL before and after the data, but haven't tested it yet. Short on time.
I will post/share my code on this forum thread and hopefully we can get those interested in Wifi/BT printing without the cloud to join in.
I do understand the usefulness of the cloud for printing from anywhere and use a cloud printer myself, but there is a need for a different more isolated solution in my case.
It can be a feature added to one of my current developments, but it;s not a deal breaker.

My PJL/PCL approach is influenced by this link:
http://www.devenezia.com/docs/HP/index.html?1686
which talks about the format and order of @PJL codes.

If I can first get the data to print reliably or at least reasonably reliable, then
I can move forward with plans to discover printers on the network, or even wifi direct printers.
File selection from a chooser and so on.

First things first - getting the test (text) file to print on an HP 3510 over Wifi Connection.
Currently, using Asyncstreams and Sockets, but other possibilities have to be researched.

The world of Printers and Printing also extends into having to use different PCL codes to control
text as apposed to images, pdf's and other data formats. The depth's to which we have to provide control codes I hope is minimal, but not likely.
This could be monumental and may take quite some time to develop a stable library format, so to start off with I'm going to use the code as a Code Module.
I've never compiled a library, so that will be interesting when we get there. There are lot's of things to consider as we go...

After, I test the last changes I made to the code, I'll post it.
Gotta run for now, though.

Looking forward to this project,
Mark
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi Mark,
it will be great if combined efforts could lead to any usable code.
My original interest about direct printing arose when I decided to print a barcode generated in code.
I will myself check that old attempts and publish here the source.

Anyone joining in is, as always, welcome!

Umberto
 
Last edited:
Upvote 0

Mark Zraik

Member
Licensed User
Longtime User
Hi Umberto,

It looks like our task is to create a wrapper/container based on PCL5/6 to use as the printer envelope.
Reading the Wiki on HP ePrint, it appears that this is how the ePrint system works.
http://en.wikipedia.org/wiki/HP_ePrint
There is a diagram that shows the Cloud (Print) Server encapsulating the files sent to it in PCL which is in turn sent to the printer.
Actually, the cloud printer checks it's email box for print jobs and then request the job from the server.

We don't need to recreate this entire system, but I think we are stuck with the part of encapsulating the data.
PCL to me, anyway, seems like it is what the printer is expecting. It lays out the header if there is one, same with the footer and other metrics of the print job including the Type of data (Text, PDF, HTML,JPG(Images), RTF) and so forth.

Using what seems to be a basic set of layout commands, we could put together some Letter/Portrait and Letter/Landscape settings as a starting point.

My intention is to create a basic layout (class) ?? for text using Letter/Portrait with a 1/2" margin all the way around, no header/footer and see if I can get the printer to print.
For now we will use a Code Module.
There are PCL codes to request feed back, which I will try to incorporate as well.
It will take a bit, but I will start this basic setup and post.

I've never had to work with reading and writing files using Asyncstreams (where all the data has to be binary(Byte)).
I did find where Erel had posted a response to use
B4X:
Dim buffer() As Byte = Bit.InputStreamToBytes(File.OpenInput(File.DirAssets, "testfile.txt"))
The point being, it would be nice if we could write the PCL commands as a text file like they can on a PC/MAC.
The difficulty comes with using the actual Escape character, Chr(27), 0x1b mixed in with the string ascii characters, but I'll find a way.

I realize I haven't posted any code yet, but I will.
I deliver stuff all over the Eastern US in a small truck, so I have to manage my time.
Off to pick up some freight, will post later,
Mark
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
doing some tests with pcl/ps is nice, the problem will be on how you will send for example a PDF to pcl/ps.

not sure if there is a library that can decode and reencode pdf > pcl or ps ?
 
Upvote 0

Mark Zraik

Member
Licensed User
Longtime User
Hi Sorex,

Yes, it will be a challenge for sure to scan and create the right pickle(PCL). I think if we overcome one catastrophe at a time, we can eventually be successful.
HP managed! So can we! They have an Android app, but the requirement I believe is 4+. Their ePrint can also use Wifi Direct, so that means there is a way to do it.
You have to have an ePrint qualified printer, but it does not have to be connected to the cloud - HP or Google or Other, it just has to be compliant (Has the correct code set)
I downloaded a Windoze executable called PCL Paraphernalia at http://www.pclparaphernalia.eu
It is a little stand alone that request the pcl codes from the printer and allows you to see them and a little explanation of what they do. It was Free, so why not.

PRN files are something I used to deal with as a Print Broker and Designer. I created them for off sized (Commercial Printer Sized) layouts that needed certain crop and bleed margins so that the end product was the correct size for a printed book. The cover in that case was the toughest, but we managed.
What I did not realize until now is that using the Acrobat Printer to Post Script and then turning the .ps files into pdf's, was actually an adventure in pcl, but I never wrote the pcl codes, I just used the Adobe Printer Preferences to create a new size and set all the attributes and so forth. It was interesting and rewarding work that I volunteered to a local non-profit. I may have to return there and see if I can find any of the PRN files, if they exist.

Well, I only had time to check in,
Mark
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Have you made any progress?

I took my BTPrint App (https://www.b4x.com/android/forum/t...g-to-hp-deskjet-100-mobile.36089/#post-222513) and changed the program to instead of writing to the BlueTooth Printer to right all the codes to a .PRN file

Took this PRN file (which has the PCL codes to work for a HP Deskjet Moblie 100) and sent it to my Brother printer (on windows did a copy /b to the printer) and it printed just fine the PCL codes and pretty much the same.

So truly if I could some how send this file to my Brother Printer's IP address from my Android I could be printing to it.

But I have no idea how to go about that.
I do not have a print server and my Brother printer is too old to support WiFi direct.

Anyway you said you were looking for a PRN file. I was going to attached one.

BobVal
 

Attachments

  • PrintTest.zip
    1 KB · Views: 450
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…