Thermal Printer - Graphic Printing

jflaplante

Member
Licensed User
Longtime User
I've been banging my head recently over this. I'm trying to print an image contained in a blob (signature capture) on a thermal printer using the ESC/POS escape sequence. I'm speaking to the printer via a serial connection and text printing is working fine.

I've collected hints from the following post:

http://www.b4x.com/forum/basic4android-updates-questions/24981-print-image.html

But it comes short of a concrete example and I have been unable to apply that in a concrete fashion. My attempt at resurrecting the thread has been unsuccessful. The closest I have come was this very good example written in C# (there's even a delphi translation in there):

Sending a bit image to an Epson TM-T88III receipt printer using C# and ESC/POS | Simply Does Not Work

I was able to translate most of it but I can't translate some of the lines in b4a.

I researched everywhere for a concrete example in vb6 or vb.net that take an image, let's say a bmp or jpeg, and convert and print it using that ESC/POS escape sequence. In my case, the image is already a blob so I guess there is one less step to send it.

I know very well what the Point Of Sale acronym is but honestly, ESC/POS is starting to get a whole other meaning for me. It has nothing to do with b4a as I haven't even found a vb6 example on the net so far. Like most stuff, it's probably not that complex once you know what to do...

Could someone P L E A S E help me with some lines of code over that?

Thanks in advance!

JF.
 

jflaplante

Member
Licensed User
Longtime User
Which lines weren't you able to translate?

This one:

B4X:
slice |= (byte)((v ? 1 : 0) << (7 - b))

Located at the bottom of the fourth code block is giving me some problems. The fourth code block is the heart of the transformation into the prescribed ESC/POS format. It is the only one I need.

I'm proud of what I was able to achieve so far with b4a but I'm far from mastering it. I accomplished great things but I always worked from examples and good bases. That being said, it is entirely possible that my code translation is not accurate and other problems will pop-up.

Thanks in advance.

JF.
 
Upvote 0

MrRey

Member
Licensed User
Longtime User
I'm a bit rusty, but here goes (someone better at this check my work).

Example: a |= b means a = a | b
|= is a compound assignment operator using the bitwise OR, the pipe {|}.

v ? 1 : 0 means if v is true, return 1; if not, return 0.

The (byte) returns it as a byte, not as another data type.
 
Last edited:
Upvote 0

jflaplante

Member
Licensed User
Longtime User
Thanks Erel,

Yesterday, I was driving 900km to go visit a client so I wasn't able to reply to your very helpful post. This is the client where I'm implementing my b4a Android solution. I will implement it without the signature printing at first and add this feature ASAP. I will revive that thread if I have further C# translation problem.

I have a related question however. I know that the printer's manufacturer (Star Micronics) has a Java Android SDK available that could facilitate such tasks as printing graphics. I prefer using ESC/POS since that permits the use of many more different manufacturer but let's say, for the purpose of discussion, that someone would like to use this SDK.

Would it be possible (using reflexion) to somehow interface b4a with these java classes and interact with the printer?

Thanks again for your time Eral and rmgb

JF.
 
Upvote 0

rboeck

Well-Known Member
Licensed User
Longtime User
Hi jflaplante,

if you need this routine 'only' for the printing of the signature, which is always ? the same, then i have a tipp for you, which i used for long in old dos programs:
Use a windows system to create the signature; below the signature use a font for text mode. Then print this signature to a file.
Now you have to analyse this file from the back and find the point, where you take control. Here you have to cut the file.
In your android app you use this cutted file as start of your printing. Maybe its hard to find the right point; but its very much easier, than your plan. In your plan, you have to completly substitude the windows printer driver...
Send me a small logo, i try to prepare only file for you to test my idea.
Greetings
Reinhard
 
Upvote 0

jflaplante

Member
Licensed User
Longtime User
Hi jflaplante,

if you need this routine 'only' for the printing of the signature, which is always ? the same, then i have a tipp for you, which i used for long in old dos programs:
Use a windows system to create the signature; below the signature use a font for text mode. Then print this signature to a file.
Now you have to analyse this file from the back and find the point, where you take control. Here you have to cut the file.
In your android app you use this cutted file as start of your printing. Maybe its hard to find the right point; but its very much easier, than your plan. In your plan, you have to completly substitude the windows printer driver...
Send me a small logo, i try to prepare only file for you to test my idea.
Greetings
Reinhard

Thanks for the suggestion, but in my case the signature is the client's signature and it changes for every invoices. I have no problem capturing, storing and accessing the signature. It's just the printing that causes problem.

Also, you talk about the windows driver being substituted but I have no other choices because I talk directly from the android device to the bluetooth printer via a serial connection. There's no driver between the two. The graphic MUST be sent to the printer in the language understood by the printer and in this case it is the ESC/POS standard.

I'll get it done, it's just a question of time and some help here and there!

JF.
 
Upvote 0

aviario

Active Member
Licensed User
Longtime User
jflaplante we are trying develop an application in b4a and we want to print in esc/p printer via bluetooth. Now we print text without problem, but we can't print image.

I read that you translate c# code to b4a. Is possible that send it to us?
I try translate it but i don't undestand c#.

Sorry for my poor english.

Thans.
 
Upvote 0

Azman

New Member
Licensed User
Longtime User
I have similar problem with ESC Pos Printer. I just need some help in getting the file to the printer.

I am using this append the command and file content to string.
Dim fileContent As String
fileContent = File.ReadString(File.DirAssets, "woosim.bmp")
'Print Image command
sstringBuilder.Append(Chr(27) & Chr(88) & Chr(52) & Chr(47) & Chr(167)) 'Command
sstringBuilder.Append(fileContent)

'then i send the string to the printer.
'printer is declare at TextWriter
printer.Write(fileContent.ToString)

Appreciate assistance.
 
Upvote 0

Lee Gillie CCP

Active Member
Licensed User
Longtime User
I've been experimenting with a Start Micronics SM-T300i thermal POS printer. Some observations:

Constructing the bytes to send to the printer from a static bitmap was expensive. My tact was to take that C# code sample, and write to a file, that I include in my B4A "Files". Call it like "Logo.bin", created by the quick-n-dirty Visual Studio application. Then at print time I simply relay these well formed bytes to the printer, and it is much quicker than translating it from a bitmap on the Android device.

I attempted to use PAGE MODE to print a logo on left side, and company address info in text on the right side. I could not for the life of me make this work. It ALWAYS positioned the text below the bitmap, rather than beside. I had thought this was supposed to be the advantage of page mode. So when I made the logo heading, I included the company address info making a full page width image (3", 576 pixels) for the bin file. This looks quite good and works around the positioning problem well.

And finally, I found when done printing it would often abort and quit printing part way through. While closing down the BT printer access I do the FLUSH, and then call a routine with a 2 second delay to finish up closing. So 1) open, 2) do printing, 3) flush, 4) delay, 5) close. This 2 second delay gave the printer the opportunity to complete the task of printing all in the buffer. If you completely close before the printer is done, then I found it aborts, and much of the printing is missing.

Not entirely your question, but perhaps the BIN file for the static receipt heading graphics is helpful.
 
Upvote 0
Top