//发送指令 public static bool SendPrinterCommand(string command) { if (printerHTTP != null && command != "") { printerHTTP.SendCommand(command); return(true); } return(false); }
/// <summary> /// 清除打印机中所有任务 /// </summary> public void ClearAll() { if (connection != null && connection.Connected) { if (printer != null) { printer.SendCommand("~JA"); } } }
/* * Print the labels using the supplied data using the zebra API */ private void PrintLabels(LabelSetup l) { //Define the label format used to layout the label string labelFormat = $"^XA" + // Start the format $"^DFE:LABEL.ZPL^FS" + // Set the name of the format file $"^PW{l.pagewidth}" + // Set the pagewidth $"^A@N,{l.fontsize},E:TT0003M_.FNT" + // Set the font and fontsize $"^FO0,{l.offset}" + // Set the starting position using the offset $"^FB{l.pagewidth},2,0,C" + // Create a field block to center the text, max 2 lines $"^FN1\"Batch Code Text\"^FS" + // Define the label text into variable slot 1 $"^XZ"; // End the format //Send the label format to the printer printer.SendCommand(labelFormat); //Initialise a dictionary to pass variables to the printer Dictionary <int, string> vars = new Dictionary <int, string> { }; //Print each label individually, providing a string for the label text via the dictionary for (int i = 0; i < l.quantity; i++) { if (cancel) { break; } //Change the text based on the size of the label if (l.pagewidth < 200) { vars[1] = $"{l.batchcode}\\&"; vars[1] += $"{l.prefix}{l.startNumber + i}\\&"; } else { vars[1] = $"{l.batchcode}\\&"; vars[1] += $"Bottle: {l.prefix}{l.startNumber + i}\\&"; } //Print the label with associated text printer.PrintStoredFormat("E:LABEL.ZPL", vars); } }