mtmsuhail / ESC-POS-USB-NET

This project is a simple .NET (C#) Implementation of the Epson ESC/POS Printing using USB Device Driver.
MIT License
201 stars 85 forks source link

Code128 Barcode is not rendering correctly #43

Open jchathu opened 2 years ago

jchathu commented 2 years ago

If we print the code 128 barcode as same as using this method printer.Code128("123456789"); It will print wrong barcode. It will print something like this "495051525354555657" after scanning the printed barcode

Is there anyway to decode this or how can we correct his for Code128 barcodes?

iformas commented 2 years ago

I just extracted this from here and it works for me

    private byte[] BarcodeBytes(string barcode)
        {
            byte type = 0x49; //CODE128
            byte gs = 0x1D;
            byte printBarcode = 0x6B; 
            byte code = 0x42; //CODE_B

            barcode = barcode.Replace("{", "{{");
            barcode = $"{(char)0x7B}{(char)code}" + barcode;

            var command = new List<byte> { gs, printBarcode, (byte)type, (byte)barcode.Length };
            command.AddRange(barcode.ToCharArray().Select(x => (byte)x));
            return command.ToArray();
        }

Use it with

var printer = new USBPrinter.Printer("printer-name", "utf-8");
printer.Append(BarcodeBytes("123456789"));
PabloGallegosH commented 1 year ago

Hi, I Revie this bug, the problem is the Font Code. Currently is 'C' change the font to 'A' or 'B' 0x42 . fix in the class BarCode.cs I Hope this post can help you.
0x42

saper-2 commented 5 months ago

Hi, I have created PR #70 that addressing this issue and fix it (and add more config too 😄 ), also there is PR #38 regarding this too.