我是一名初级C#程序员。我有一个项目需要我通过USB将原始命令发送到Zebra打印机LP2844并使其工作。我做了很多研究,并试图找到一种方法来做到这一点。我使用的代码来自http://support.microsoft.com/kb/322091,但没有起作用。根据我的测试,我似乎已经向打印机发送了命令,但它没有响应并打印。我对此一无所知。有人能帮我吗?
我正在使用按钮直接发送命令
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:要解决更新问题,您遇到的问题是使用SendStringToPrinter
,它会向打印机发送ANSI字符串(以null结尾),而这不是打印机所期望的。根据官方EPL2编程指南第23页(根据您的示例,这是您真正在做的,而不是ZPL)。
每个命令行都必须以换行符(LF)字符结束(12月10日)。大多数基于PC的系统在按下Enter键时发送CR/LF按下。回车(CR)字符被打印机忽略并且不能代替LF使用。
因此,您必须修改SendStringToPrinter
以在字符串末尾发送n
而不是