ESC / POS commands EPSON printer basic format functions in C #

1

Good afternoon

Ando lost in a topic about impressions, basically I have to print some text, but I can not give the desired format and I do not understand well how the ESC / POS commands work, I have the following code:

SerialPort sp;
        sp = new SerialPort();
        sp.PortName = "COM1";
        sp.BaudRate = 9600;
        sp.Parity = Parity.None;
        sp.DataBits = 8;
        sp.StopBits = StopBits.One;
        sp.Handshake = Handshake.RequestToSend;
        sp.DtrEnable = true;
        sp.RtsEnable = true;

        sp.Encoding = System.Text.Encoding.UTF7;

        sp.Open();

        if (!sp.IsOpen)
        {
            MessageBox.Show("Puerto serial no es soportado.");
            return;
        }

        sp.WriteLine((char)27 + "E" + "This is Bold" + (char)27 + "F" + Environment.NewLine);
        sp.WriteLine("La opción de: " + "[CRÉDITO VEHICULAR]" + " se ha activado correctamente." + Environment.NewLine);
        sp.WriteLine("Los datos consignados para la operación, son los siguientes:" + Environment.NewLine);
        sp.WriteLine("Nombre Completo: " + Environment.NewLine);
        sp.WriteLine("DNI: " + Environment.NewLine);
        sp.WriteLine("Fecha de operación: " + Environment.NewLine);
        sp.WriteLine("Correo de contacto:" + Environment.NewLine);
        sp.WriteLine(Environment.NewLine);
        sp.WriteLine("Los documentos del contrato ha sido enviados a su correo electrónico, indicado lineas arriba." + Environment.NewLine);
        sp.WriteLine("Sirvase ponerse en contacto con nosotros a los siguientes números:" + Environment.NewLine);
        sp.WriteLine("" + Environment.NewLine);
        sp.WriteLine("[CÓDIGO DE BARRA]" + Environment.NewLine);

        sp.Write(CutPaper, 0, CutPaper.Length);
        byte[] data = new byte[sp.BytesToRead];
        sp.Read(data, 0, data.Length);

        this.Close();

That way I do not know how to put the code so that certain letters are in bold.

Also looking for another way, using a library: ThermalDotNet, with the following code:

string printerPortName = "COM1";

        SerialPort printerPort = new SerialPort(printerPortName, 9600);

        if (printerPort != null)
        {
            Console.WriteLine("Puerto OK");
            if (printerPort.IsOpen)
            {
                printerPort.Close();
            }
        }

        Console.WriteLine("Abriendo puerto");

        try
        {
            printerPort.Open();
        }
        catch
        {
            Console.WriteLine("I/O error");
            Environment.Exit(0);
        }

        //Printer init
        ThermalPrinter printer = new ThermalPrinter(printerPort, 2, 180, 2);
        printer.WakeUp();
        Console.WriteLine(printer.ToString());

        //TestReceipt(printer);

        printer.WriteLineSleepTimeMs = 200;

        printer.WriteLine("Default style");
        printer.WriteLine("PrintingStyle.Bold", ThermalPrinter.PrintingStyle.Bold);
        printer.WriteLine("PrintingStyle.DeleteLine", ThermalPrinter.PrintingStyle.DeleteLine);
        printer.WriteLine("PrintingStyle.DoubleHeight", ThermalPrinter.PrintingStyle.DoubleHeight);
        printer.WriteLine("PrintingStyle.DoubleWidth", ThermalPrinter.PrintingStyle.DoubleWidth);
        printer.WriteLine("PrintingStyle.Reverse", ThermalPrinter.PrintingStyle.Reverse);
        //printer.WriteLine("PrintingStyle.Underline", ThermalPrinter.PrintingStyle.Underline);
        //printer.WriteLine("PrintingStyle.Updown", ThermalPrinter.PrintingStyle.Updown);
        //printer.WriteLine("PrintingStyle.ThickUnderline", ThermalPrinter.PrintingStyle.ThickUnderline);
        printer.SetAlignCenter();
        printer.WriteLine("BIG TEXT!", ((byte)ThermalPrinter.PrintingStyle.Bold +
            (byte)ThermalPrinter.PrintingStyle.DoubleHeight +
            (byte)ThermalPrinter.PrintingStyle.DoubleWidth));
        printer.SetAlignLeft();
        printer.WriteLine("Default style again");

        printer.WriteLine({ ESC, 0x69 }, 0);
        printer.LineFeed(3);
        printer.Sleep();
        Console.WriteLine("Printer is now offline.");
        printerPort.Close();

With this last code, if I can see the format, but at the time of printing, the sheet does not cut it or eject it, this seems even worse to me.

I hope you can help me. Thanks

    
asked by Kenny 14.11.2016 в 22:00
source

1 answer

0

It is not a solution but an alternative, the vast majority of current printers support ZPL in that language simply send in plain text and the printer converts and prints it.

If you want to start in ZPL download the free zebra designer, create your format and send to print to file and you will see what you have to modify.

    
answered by 06.12.2016 в 19:58