我在使用ZDesigner GK420T使用C# .NET打印标签时遇到了问题。我将下面的字符串转换为Bytes并传递给打印机。
^XA
^FO3,3^AD^FDZEBRA^FS
^XZ预期的结果是,打印机应该打印‘斑马’,但它没有。
我的C#代码:
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++;
}我在这里做错什么了?我需要额外的代码吗?
发布于 2014-06-03 11:28:39
首先,您需要清除以下内容:
例如,下面的代码片段使用并行口lpt1在斑马打印机上打印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,以便移到下一行。
发布于 2014-06-03 16:32:54
打印机处理普通的ASCII编码。确保使用Encoding.ASCII输出文本。另一个问题是,C#无法直接写入并行端口。apomene显示了对文件的创造性使用,然后将其复制到lpt1中。问题是他没有使用ASCII,而是发送UTF-16。
我不知道您的RawPrinterHelper是什么,但是它是以ASCII还是Unicode的形式发送文本呢?
解决这些问题可能会导致成功的印刷。
我在这里找到了打印机的文档:http://www.servopack.de/support/zebra/ZPLII-Prog.pdf
https://stackoverflow.com/questions/24013799
复制相似问题