python-escpos icon indicating copy to clipboard operation
python-escpos copied to clipboard

garbage after sending image?

Open lexelby opened this issue 5 years ago • 9 comments

Hi folks, thanks for an awesome project!

I'm new to thermal printers and I'm having a little trouble. It seems like, after I print an image, I get a bunch of garbage characters printed out the next time I try to do anything.

With 2.2.0 (from pypi), if I send text('\n') after printing an image, I seem to avoid the issue. In master (3.0a6) that doesn't help.

I get the same problem even if I use a simple program like this, with an ESC/POS data blob captured from an android esc/pos printer app:

from escpos.printer import Usb
import sys

data = sys.stdin.read()
printer = Usb(0x0416, 0x5011, 0, 0x81, 0x01)
printer._raw(data)
printer.close()

The first time it prints fine, but if I run it again, I see a bit of the image shifted to the right, and then the third time, I get part of the image and garbage. The fourth time, the printout works great, and then the pattern repeats. I could swear it seems like the printer is getting confused, as if it's missing the end of a command or something. Maybe I'm not doing it right?

test.escpos.zip

Device info

Printer: POS-5890K (this one)

python-escpos version: 2.2.0, 3.0a6

python version: 2.7.14

operating system: Ubuntu 18.04.1

lexelby avatar Oct 12 '19 19:10 lexelby

Same printer, identical issue. I've narrowed it down to breaking on images with a height which is a multiple of 96 pixels. I can't figure out why that exact multiple, but it's the only thing that seems to reproduce it. Changing the vertical segmentation doesn't help either. (I figured it might since its 960 by default, a related number, but no it changes nothing).

Do you get the same issue if you increase/reduce the height of your image by a single pixel?

daffy1234 avatar Oct 13 '20 08:10 daffy1234

Hi, thank you for trying out different versions! It indeed seems that there is an issue with your printer understanding the data. Unfortunately, I don't have access to a printer at the moment, but I can try it out on a TM88-II if I get to it.

It's interesting to hear that you get the same result with an Android app. Have you anything like a reference implementation for the picture printing? This way you could check in which way the datasets that are sent to the printer differ.

patkan avatar Oct 19 '20 10:10 patkan

I'm having the same problem. I think that some context might help here.

content is an image path list. In this test I'm trying to print only the first one and then the text below it, just for testing purpose.

def printer_print(content):
    p.image(content[0])
    p.text("test")
    p.cut()

It only prints the image (960px height). It doesn't print the text nor "cuts" (in my printer, a POS-5890C, cut is just a bunch of empty lines)


When I try printing more images, like the code below, it prints the first image then just a bunch of garbage.


def printer_print(content):
    p.text(header)
    p.text(spacing)
    for image in content:
        p.image(image)
    p.text(spacing)
    p.text(footer)
    p.cut()

It prints the header, a two-line return (spacing), the first image... then garbage and nothing else. I let my tape run and wasted almost half a roll.

I can help testing this issue in my printer, but I need further help as I'm a novice python developer.

(I preferred commenting here than opening a new issue with the apparent same problem)

angelod1as avatar Feb 14 '21 06:02 angelod1as

OMG, I think I found out.

Instead of just p.image(image) I did p.image(image, fragment_height=500) (my image is bigger than 500px in height) and IT WORKED.

angelod1as avatar Feb 14 '21 07:02 angelod1as

Hey @angelod1as i'm having the same issue witha generic thermal printer, my main concern is that it doesn't cut, paper just rolls on itself before the printer exit just like you mentioned it. How did you manage to solve the cutting issue?

juancarlord avatar Aug 20 '21 15:08 juancarlord

My experience:

just put a p.ln() right before p.image(filename) and solved for me... hope it helps someone.

ismaelit avatar Dec 06 '21 14:12 ismaelit

Thanks the issue was due the printer being very old and not supporting new commands, only old ESC commands were supported by the printer

On Mon, 6 Dec 2021 at 9:54 AM Ismael Ittner @.***> wrote:

My experience:

just put a p.ln() right before p.image(filename) and solved for me... hope it helps someone.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/python-escpos/python-escpos/issues/367#issuecomment-986849972, or unsubscribe https://github.com/notifications/unsubscribe-auth/AM2YCSFFXRQ3K75Z4TYLEADUPTFCXANCNFSM4JAEFIQA .

juancarlord avatar Dec 06 '21 15:12 juancarlord

In my case, I was using a new printer from Bematech and it works good...but when I try to print in a new EPSON TM-T88V the problem occur. I think it is not due the printers age, but the internal ESCPOS interpreter...maybe the escpos library could make a workaround for that in the future, or look for some printer's firmware update.

Thanks the issue was due the printer being very old and not supporting new commands, only old ESC commands were supported by the printer

ismaelit avatar Dec 06 '21 15:12 ismaelit

Was the same problem with exactly XPrinter 48mm POS-5890K. During debugging the issue we experimentally figured out that it started printing gibberish when we send command GS v 0 with image height multiple of 48 only : i.e. 240, 192, 144, 96 . We handled this case with spliting whole image into chunks of multiple of 256 and then if smaller chunk is multiple of 48 then increase image height on 8 and just fill that addition with 255 brightness pixels. Finally send chunks of GS v 0 one by one to the printer. The issue was with GO escpos library. So it seems a bug with printer`s firmware

zbykovskyi avatar Feb 12 '24 16:02 zbykovskyi