简体   繁体   中英

How to format and send command for printing bill items on termal printer Datecs LP-50 H?

My printer is connected via Serial Port (COM3, 9600), and now I want to print some text on it. I have tried all codes that I was found on net, mostly named for epson printers, but none of them didn't worked for me.

Simply I want to send message to printer on Button_click event.

 private void Button_Click(object sender, RoutedEventArgs e)
    {
        if (!serialPort.IsOpen)
            serialPort.Open();
        serialPort.Write(Message());
    }

Simple test message would be (and that's where I need help):

private String Message() {
    char[] init = new char[] { (char)0x1b, '@' };
    String msg = "";
    foreach (char c in init)
        msg += c;

       msg+="Hello World";
    return msg;
}

I also have user manual for printer, with pseudo command:

LPRINT “0123456789012345678901”; 
LPRINT CHR$ (&HA); 
LPRINT CHR$ (&H9) + “AAA”; 
LPRINT CHR$ (&H9) + “BBB”; 
LPRINT CHR$ (&HA); 
LPRINT CHR$ (&H1B) + “D”; 
LPRINT CHR$ (3) + CHR$ (7) + CHR$ (14) + CHR$ (0); 
LPRINT CHR$ (&H9) + “AAA”; 
LPRINT CHR$ (&H9) + “BBB”; 
LPRINT CHR$ (&H9) + “CCC” + CHR$ (&HA);

How this would be converted to C# and does something missing in this pseudo command? I need help here to properly define my Message() method and to print text.

I was found workaround for my problem. Datecs have windows drivers for this type of printer, so that printer acts as regular printer. No messing with com ports and it's params, just send regular formated string for printing. Here is methodt for printing String

public void PrintText(StringBuilder s, String PrinterName)
    {
        PrintDocument p = new PrintDocument();
        p.PrintPage += delegate(object sender1, PrintPageEventArgs e1)
        {
            e1.Graphics.DrawString(s.ToString(), new Font("Times New Roman", 11), new SolidBrush(System.Drawing.Color.Black), new RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height));

        };
        try
        {
            p.PrinterSettings.PrinterName = PrinterName;
            p.Print();
        }
        catch (Exception ex)
        {
            throw new Exception("Exception Occured While Printing", ex);
        }
    }

For this method is needed to add references:

System.Drawing

And to add using statment on top

using System.Drawing;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM