I'm a beginner C# programmer. I have a project that requires me to send the raw command to Zebra printer LP 2844 via USB and make it work. I did a lot of research and tried to figure out a way to do that. I'm using the code from http://support.microsoft.com/kb/322091, but it didn't work. Based on my test, it seems that I have sent commands to the printer, but it didn't respond and print. I have no idea about this. Can someone help me out?
I'm using button to send the command directly
private void button2_Click(object sender, EventArgs e)
{
string s = "A50,50,0,2,1,1,N,\"9129302\"";
// Allow the user to select a printer.
PrintDialog pd = new PrintDialog();
pd.PrinterSettings = new PrinterSettings();
if (DialogResult.OK == pd.ShowDialog(this))
{
// Send a printer-specific to the printer.
RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, s);
MessageBox.Show("Data sent to printer.");
}
}
EDIT: To address your update, The problem you are having is you are using
SendStringToPrinter
which sends a ANSI string (a null terminated) string to the printer which is not what the printer is expecting. According to the official EPL2 programming guide page 23 (Which is what you are really doing, not ZPL according to your example).So you must either modify
SendStringToPrinter
to send a\n
at the end of the string instead of a\0
or you must build the ASCII byte array yourself and useRawPrinterHelper.SendBytesToPrinter
yourself (like I did in my original answer below).So to fix your simple posted example we change out your function call, we also must tell the printer to actually print by sending a
P1\n
I did this with Zebra's older EPL2 language, but it should be very similar to what you need to do with ZPL. Perhaps it will get you started in the right direction.