斑马标签打印机与c#

本文关键字:打印机 标签 马标签 | 更新日期: 2023-09-27 18:06:30

我在使用c# . net使用ZDesigner GK420T打印标签时遇到了麻烦。我将下面的字符串转换为Bytes并传递给打印机。

^XA 
^FO3,3^AD^FDZEBRA^FS
^XZ

预期的结果是打印机应该打印"ZEBRA",但它没有。

My c# Code:

StringBuilder sb; sb = new StringBuilder();
if (frmPrintJob._type != 1) 
{
    sb.AppendLine("^XA"); 
    sb.AppendLine("^FO3,3^AD^FDZEBRA^FS"); 
    sb.AppendLine("^XZ"); 
} 
int intTotalPrinted = 0; 
for (int i = 1; i <= NoOfCopies; i++) 
{ 
    if (RawPrinterHelper.SendStringToPrinter(PrinterName, sb.ToString()) == true) 
        intTotalPrinted++; 
}

我在这里做错了什么?我需要额外的代码吗?

斑马标签打印机与c#

首先您需要澄清以下内容:

  • 您打印的是RFID标签还是条形码标签
  • 是通过USB或并口连接的打印机

例如,下面的代码片段使用并行端口lpt1在Zebra打印机上打印RFID标签:

String strPath = "C:''Zebra";
String zplStart = "CT~~CD,~CC^~CT~'r'n^XA'r'n^MMT'r'n^PW831'r'n^LL0599'r'n^LSO'r'n";
String zplMiddle = "^FT50,180^BY3^BCN,200,N,N,N^FD"; ///+barcode
String zplMiddle2 = "^FS'r'n^FT600,145^AAN,30,10,^FH''^FD";///+barcode 
String zplMiddle3 = "^FS^^RS8,,800,5^RFW,H^FD";//+RFID
String splend1 = "^FS'r'n^RWH,H^FS'r'n^RR10^FS'r'n^PQ1'r'n^XZ";
string filePath = strPath + "''Books" + ".zpl";
string Prefix="..." //Define tag ID Prefix
string Sufix =".."//Define tag ID suffix
RFID ="Prefix"+ barcode +Sufix;
StreamWriter strw = new StreamWriter(filePath);
strw.Write(zplStart + zplMiddle + barcode + zplMiddle2 + barcode+ zplMiddle3 + RFID+  splend1); // assemble the three parts of the ZPL code
string command = "copy " + filePath + " lpt1"; //prepare a string with the command to be sent to the printer
// The /c tells cmd that we want it to execute the command that follows, and then exit.
System.Diagnostics.ProcessStartInfo sinf = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
sinf.UseShellExecute = false;
sinf.CreateNoWindow = true;
System.Diagnostics.Process p = new System.Diagnostics.Process(); // new process            
p.StartInfo = sinf;//load start info into process. 
p.Start(); //start process (send file to printer)

以上是RFID标签的示例,在您的情况下,要输入的zpl字符串我猜是:

string zpl="^XA^'r'nFO3,3^AD^FDZEBRA^FS'r'n^XZ";

注意我使用'r'n以便移动到下一行

打印机处理纯ASCII编码。确保使用Encoding.ASCII输出文本。另一个问题是c#不具备直接写入并行端口的能力。apomene展示了创造性地使用写入文件,然后将其复制到lpt1。问题是他没有使用ASCII,而是发送UTF-16

我不知道你的RawPrinterHelper是什么,但它是发送文本作为ASCII或Unicode?

解决这些问题可能会导致打印成功。

我在这里找到了打印机的文档:http://www.servopack.de/support/zebra/ZPLII-Prog.pdf