hennedo / escpos

golang library for espos printers, supporting images, barcodes and qr codes
MIT License
74 stars 30 forks source link

Print number 0 (zero) at the end of every line #1

Closed AurumAustralis closed 2 years ago

AurumAustralis commented 3 years ago

Hello, I have a problem when I print text: at the end of each line it also prints the number 0 (zero)

p.Bold(true).Size(2, 2).Write("Hello World")

Ouput: Hello World0

hennedo commented 3 years ago

Mhh. What kind of printer are you using? Could you provide me with a minimal (but complete) code snippet that causes this bug to appear?

AurumAustralis commented 3 years ago

I was also thinking that it could be the printer, is a "sol802" thermal printer http://postektronics.com/productdetails/SOL802

The code: package main

import ( "net"

"github.com/hennedo/escpos"

)

func main() { socket, err := net.Dial("tcp", "192.168.7.90:9100") if err != nil { println(err.Error()) } defer socket.Close()

p := escpos.New(socket)

p.Bold(true).Size(2, 2).Write("Hello World")
p.LineFeed()

p.PrintAndCut()

}

And the result: Hello World0

AurumAustralis commented 3 years ago

Printer config

`Print Speed 250mm/s Print Density Medium Print Width 72mm Print Direction Normal Print Font 12*24 Auto Cut on ChangePaperRePrint off Buzzer Enable Error On

Command Set ESC/POS Code Page ISO-8859-15`

hennedo commented 3 years ago

Sadly there is not that much information available about the printe. Currently my best guess is that it has to do something with the cut command. In the ESC/POS manual there are 3 ways to perform a cut. Could you clone the library locally and replace it in your project with the local version?

Within your go mod, just before the require part

replace github.com/hennedo/escpos => /home/.../escpos

Then replace

func (e *Escpos) Cut() (int, error) {
    return e.WriteRaw([]byte{gs, 'V', 'A', '0'})
}

with

func (e *Escpos) Cut() (int, error) {
    return e.WriteRaw([]byte{esc, 'i'})
}
// or if that does not work
func (e *Escpos) Cut() (int, error) {
    return e.WriteRaw([]byte{esc, 'm'})
}

One of those could possibly work..

AurumAustralis commented 3 years ago

I'm going to test with that code. Thank you very much for the reply and speed!

AurumAustralis commented 3 years ago

It did not work I'm going to keep trying and I'll put any solution here . Thanks again.

hennedo commented 3 years ago

Sorry that I could not be of more help. If you do find any solution, even if it's another open source library that I can have a look at that works, I'm interested!

AurumAustralis commented 3 years ago

I am adapting the augustopimenta library with yours and so far it works: charset, image, barcode (qr, upca, ean8 and ean13) and I added tables with tablewriter

Links to libraries "github.com/augustopimenta/escpos" "github.com/olekukonko/tablewriter"

I am working with Code128 and a problem with the images

When I finish I upload it to github

Thanks again Hendrik!

pinpox commented 2 years ago

I'm running into this issue aswell, with an EPSON TM-T88II printer. Did you ever find a solution to this?

Printing images works fine, but any text has a "0" appended

hennedo commented 2 years ago

Dang. I if @AurumAustralis did not find a solution for this I might need to buy an EPSON TM-T88II off of ebay-kleinanzeigen to work on a solution :D

hennedo commented 2 years ago

After some debugging on my "new" printer, it seems it does not support the upside down printing, so as the library always pushes the current state when you call write, it sends the codes for upside down printing. the printer then ignores the ESC+{ and prints the 0 which is intended to tell the printer "no upsidedown printing please".

I refresh every setting set in the library with each write because when using a networked printer it's quite possible that another user sets different settings. I need find a solution for this. Maybe some sort of feature enable / disable depending on the model.

pinpox commented 2 years ago

Thanks for investigating! Let me know if you need help testing, I've got a printer sitting on my desk.

hennedo commented 2 years ago

So I added a config struct to disable certain features that are called during the write process and added some Device configs. Could you replace your dependency with a local copy of the compatibility_fix branch and confirm that everything works fine when you are adding the SetConfig line right after the escpos.New call?

p := escpos.New(socket)
// add here:
p.SetConfig(escpos.ConfigEpsonTMT88II)

Also if @AurumAustralis is still interested, would be good to know if this works for you also...

pinpox commented 2 years ago

@hennedo I can confirm this fixes the issue with the Epson TM T88II, no more zeros. I noticed though, the QRcodes are not printed, not sure if this is related to the fix or a different issue, the code I'm using is this: https://gist.github.com/pinpox/c360111ede61f8f62aa0c6cd2a3fb284

hennedo commented 2 years ago

As QR code printing is a printerfeature the qr code is not generated by the library. Therefore the printer needs to support qr code printing. I do not think the TM-T88II supports QR code printing. I'll merge the fix in master then!