public static ZebraPrinter Disconnect(ZebraPrinter printer) { try { printer.Connection.Close(); Console.WriteLine($"Printer Disconnected"); } catch (ConnectionException e) { Console.WriteLine($"Error disconnecting from printer: {e.Message}"); } return(printer); }
private void ImprimirEtiqueta(string shipTo, string caja) { var info = InfoShippingBusiness.GetInfoShipping(shipTo); if (info != null && impresora != "") { zebraInstructions = new StringBuilder(); zebraInstructions.Append("^XA"); zebraInstructions.Append("^FT413,153^A0N,39,38^FH\\^FDCountry:^FS"); zebraInstructions.Append("^FT572,153^A0N,39,38^FH\\^FD" + info.country + "^FS" + Environment.NewLine); zebraInstructions.Append("^FT21,371^A0N,39,38^FH\\^FDState:^FS"); zebraInstructions.Append("^FT192,367^A0N,28,28^FH\\^FD" + info.state + "^FS" + Environment.NewLine); zebraInstructions.Append("^FT21,270^A0N,39,38^FH\\^FDCity:^FS"); zebraInstructions.Append("^FT167,263^A0N,25,24^FH\\^FD" + info.city + "^FS" + Environment.NewLine); zebraInstructions.Append("^FT21,219^A0N,39,38^FH\\^FDAddress:^FS"); zebraInstructions.Append("^FT165,213^A0N,25,24^FH\\^FD" + info.address + "^FS" + Environment.NewLine); zebraInstructions.Append("^FT23,420^A0N,39,38^FH\\^FDClient:^FS"); zebraInstructions.Append("^FT175,420^A0N,39,30^FH\\^FD" + info.client + "^FS" + Environment.NewLine); zebraInstructions.Append("^FT23,465^A0N,39,38^FH\\^FDContact:^FS"); zebraInstructions.Append("^FT175,465^A0N,39,38^FH\\^FD" + info.contact + "^FS" + Environment.NewLine); zebraInstructions.Append("^FT22,153^A0N,39,38^FH\\^FDShip To:^FS"); zebraInstructions.Append("^^FT184,153^A0N,39,38^FH\\^FD" + info.shipTo + "^FS" + Environment.NewLine); zebraInstructions.Append("^FT195,66^A0N,39,38^FH\\^FDBOXID:^FS" + Environment.NewLine); zebraInstructions.Append("^BY3,3,56^FT327,76^BCN,,Y,N"); zebraInstructions.Append("^FD>:" + caja + "^FS" + Environment.NewLine); //Codigo QR zebraInstructions.Append("^FT687,112^BQN,2,4" + Environment.NewLine); zebraInstructions.Append(@"^FH\^FDLA" + caja + "^FS"); zebraInstructions.Append("^FT21,320^A0N,39,38^FH\\^FDZip Code:^FS"); zebraInstructions.Append("^FT192,316^A0N,28,28^FH\\^FD" + info.zipcode + "^FS" + Environment.NewLine); zebraInstructions.Append("^FT23,506^A0N,39,38^FH\\^FDEmail:^FS"); zebraInstructions.Append("^FT175,505^A0N,39,38^FH\\^FD" + info.email + "^FS" + Environment.NewLine); zebraInstructions.Append("^PQ1,0,1,Y^XZ"); string selectedPrinterName = impresora; var z = new ZebraPrinter(selectedPrinterName); z.Print(zebraInstructions.ToString()); z.Print(zebraInstructions.ToString()); } }
private void Print(string ipAddress, List <DataPrinter> dataPrint) { Connection connection = new TcpConnection(ipAddress, TcpConnection.DEFAULT_ZPL_TCP_PORT); ZebraPrinter printer = Connect(connection); if (printer == null) { MessageBox.Show("Printer not connected!"); return; } var status = GetPrinterStatus(printer); if (status != Status.Ready) { MessageBox.Show("Printer status: " + status); return; } foreach (var data in dataPrint) { if (PrintOne(printer, data.ZplData)) { data.Send = true; if (CheckPrintingStatus(printer)) { data.Print = true; } else { break; } } } var noPrinted = dataPrint.Where(x => x.Print == false).ToList(); if (noPrinted != null && noPrinted.Count > 0) { MessageBox.Show("Press OK to Continue..."); Print(ipAddress, noPrinted); } Disconnect(printer); MessageBox.Show("Done!"); }
private void CreateFormatTableDialog() { SetButtonState(retrieveFormatsButton, false); SetFormatListState(false); string formatName = (string)storedFilesList.SelectedValue; Connection printerConnection = null; Task.Run(() => { try { printerConnection = connectionSelector.GetConnection(); printerConnection.Open(); ZebraPrinter printer = ZebraPrinterFactory.GetInstance(printerConnection); byte[] formatData = printer.RetrieveFormatFromPrinter(formatName); fieldDescDataVars = printer.GetVariableFields(Encoding.UTF8.GetString(formatData)).ToList(); fieldDescDataVars = FormatFieldDescriptionDataVars(fieldDescDataVars); formatVariables = new ObservableCollection <FormatVariable>(); for (int i = 0; i < fieldDescDataVars.Count; ++i) { formatVariables.Add(new FormatVariable { FieldName = fieldDescDataVars[i].FieldName, FieldValue = "" }); } try { if (printerConnection != null) { printerConnection.Close(); } } catch (ConnectionException) { } ShowStoredFormatDialog(formatName); } catch (Exception e) { MessageBoxCreator.ShowError(e.Message, "Communication Error"); SetButtonState(retrieveFormatsButton, true); SetFormatListState(true); } finally { try { if (printerConnection != null && printerConnection.Connected) { printerConnection.Close(); } } catch (ConnectionException) { } } }); }
private FieldDescriptionData[] GetVarFieldNames() { String formatName = formatListBox.SelectedItem.ToString(); FieldDescriptionData[] fieldNames = new FieldDescriptionData[] { }; try { ZebraPrinter printer = getPrinter(); byte[] formatData = printer.GetFormatUtil().RetrieveFormatFromPrinter(formatName); String formatString = Encoding.UTF8.GetString(formatData, 0, formatData.Length); fieldNames = printer.GetFormatUtil().GetVariableFields(formatString); } catch (ZebraPrinterConnectionException) { updateGuiFromWorkerThread("Communication Error", Color.Red); } return(fieldNames); }
private void TestConnectionString() { Task.Run(() => { try { ClearProgress(); connection = ZebraConnectionBuilder.Build(GetConnectionStringForSdk()); PublishProgress("Connection string evaluated as class type " + connection.GetType().Name); connection.Open(); PublishProgress("Connection opened successfully"); if (IsAttemptingStatusConnection()) { ZebraPrinterLinkOs printer = ZebraPrinterFactory.GetLinkOsPrinter(connection); PublishProgress("Created a printer, attempting to retrieve status"); ZebraPrinterStatus status = printer.GetCurrentStatus(); PublishProgress("Is printer ready to print? " + status.isReadyToPrint); } else { ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection); PublishProgress("Created a printer, attempting to print a config label"); printer.PrintConfigurationLabel(); } PublishProgress("Closing connection"); } catch (ConnectionException) { MessageBoxCreator.ShowError("Connection could not be opened", "Error"); } catch (ZebraPrinterLanguageUnknownException) { MessageBoxCreator.ShowError("Could not create printer", "Error"); } finally { if (connection != null) { try { connection.Close(); } catch (ConnectionException) { } finally { connection = null; SetTestButtonState(true); } } else { SetTestButtonState(true); } } }); }
public void disconnect(IMethodResult oResult) { Logger.Write("disconnect call"); if (m_connection != null && m_connection.IsConnected()) { Thread.Sleep(1000); m_connection.Close(); Thread.Sleep(1000); } m_connection = null; m_printer = null; oResult.set(ZebraConstants.PRINTER_STATUS_SUCCESS); }
public static bool Print(ZebraPrinter printer, string printstring) { bool sent = false; try { VerifyConnection(printer); printer.Connection.Write(Encoding.UTF8.GetBytes(printstring)); sent = true; } catch (ConnectionException e) { Console.WriteLine($"Unable to write to printer: {e.Message}"); } return(sent); }
private async void PrintButton_Clicked(object sender, EventArgs eventArgs) { SetInputEnabled(false); Connection connection = null; try { await Task.Factory.StartNew(() => { connection = CreateConnection(); connection.Open(); ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection); if (printer.PrinterControlLanguage == PrinterLanguage.LINE_PRINT) { throw new ConnectionException("Operation cannot be performed with a printer set to line print mode"); } string signaturePath = Path.Combine(LocalApplicationDataFolderPath, "signature.jpeg"); double printWidth = double.Parse(SGD.GET("ezpl.print_width", connection)); if (File.Exists(signaturePath)) { File.Delete(signaturePath); } using (Stream stream = SignaturePad.GetImageStream(printWidth)) { using (BinaryReader br = new BinaryReader(stream)) { br.BaseStream.Position = 0; byte[] signatureBytes = br.ReadBytes((int)stream.Length); File.WriteAllBytes(signaturePath, signatureBytes); } } ZebraImageI image = ZebraImageFactory.Current.GetImage(signaturePath); printer.PrintImage(image, 0, 0, image.Width, image.Height, false); }); } catch (Exception e) { await DisplayAlert("Error", e.Message, "OK"); } finally { try { connection?.Close(); } catch (ConnectionException) { } SetInputEnabled(true); } }
private bool SaveModifiedSettingsToPrinter() { bool result = false; Connection connection = null; try { connection = connectionSelector.GetConnection(); connection.Open(); ZebraPrinter genericPrinter = ZebraPrinterFactory.GetInstance(connection); ZebraPrinterLinkOs printer = ZebraPrinterFactory.CreateLinkOsPrinter(genericPrinter); if (printer != null) { foreach (string key in viewModel.ModifiedSettings.Keys) { if (printer.IsSettingReadOnly(key) == false) { printer.SetSetting(key, viewModel.ModifiedSettings[key]); } } viewModel.ModifiedSettings.Clear(); result = true; } else { MessageBoxCreator.ShowError("Connected printer does not support settings", "Connection Error"); } } catch (ConnectionException e) { MessageBoxCreator.ShowError(e.Message, "Connection Error"); } catch (ZebraPrinterLanguageUnknownException e) { MessageBoxCreator.ShowError(e.Message, "Connection Error"); } catch (SettingsException e) { MessageBoxCreator.ShowError(e.Message, "Settings Error"); } catch (Exception e) { MessageBoxCreator.ShowError(e.Message, "Save Settings Error"); } finally { try { if (connection != null) { connection.Close(); } } catch (ConnectionException) { } } return(result); }
public bool Print() { bool error = true; try { // Open the connection - physical connection is established here. ThePrinterConn.Open(); printer = ZebraPrinterFactory.GetInstance(ThePrinterConn); PrinterStatus printerStatus = printer.GetCurrentStatus(); bool ready = printerStatus.IsReadyToPrint; if (ready == false) { return(error); } //stvaranje oblika za slanje na printer String output = "! 0 200 200" + " " + (lastYPos + 100).ToString() + " " + "1\r\n"; //output += "IN-MILLIMETERS\r\n"; foreach (String s in buffer) { output += s + "\r\n"; } output += "PRINT\r\n"; // Send the data to the printer as a byte array. ThePrinterConn.Write(Encoding.UTF8.GetBytes(output)); //thePrinterConn.Close(); error = false; } catch (Exception e) { Logger.Logger.Log(e); error = true; } finally { //brisi buffer buffer.Clear(); //na kraju, baci gresku ako nije izvrseno do kraja... } return(error); }
public static IPrinter CreatePrinter(PrinterType printerType) { IPrinter printer = null; switch (printerType) { case PrinterType.BradyPrinter: printer = new Printers.BradyPrinter(); break; case PrinterType.ZebraPrinter: printer = new ZebraPrinter(); break; } return(printer); }
public void PrintLabel(string IpAddress, int number, string name) { string ZPL_STRING = Resources.HeadBarcode + "^FS^FO200,50^A0,25,25^FD" + "Baza narzedzi robotow" + "^FS^FO200,100^A0,25,25^FDNarzedzie numer:" + number + " ^FS^FO200,150^A0,25,25^FDNazwa narzedzia:" + name + " ^FS^FO200,200^A0,25,25^FDData przegladu:" + DateTime.Now.ToString("MM/dd/yyyy") + " ^FS^XZ"; ZebraPrinter zebraPrinter = ZebraPrintHelper.Connect(new TcpConnection(IpAddress, TcpConnection.DEFAULT_ZPL_TCP_PORT), PrinterLanguage.ZPL); if (ZebraPrintHelper.CheckStatus(zebraPrinter)) { ZebraPrintHelper.Print(zebraPrinter, ZPL_STRING); if (ZebraPrintHelper.CheckStatusAfter(zebraPrinter)) { Console.WriteLine($"Label Printed"); } } zebraPrinter = ZebraPrintHelper.Disconnect(zebraPrinter); }
private void ReadMagCard() { Connection connection = null; Task t = Task.Run(() => { try { connection = connectionSelector.GetConnection(); connection.Open(); ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection); MagCardReader magCardReader = MagCardReaderFactory.Create(printer); if (magCardReader != null) { UpdateMagCardOutput(""); SetButtonText("Swipe Card Now"); string[] trackData = magCardReader.Read(30000); if (trackData[0].Equals("") && trackData[1].Equals("") && trackData[2].Equals("")) { MessageBoxCreator.ShowError("Connection timed out", "Mag Card Error"); } else { UpdateMagCardOutput(trackData[0] + "\r\n" + trackData[1] + "\r\n" + trackData[2]); } } else { MessageBoxCreator.ShowError("Printer does not have a mag card reader", "Mag Card Error"); } } catch (ConnectionException e) { MessageBoxCreator.ShowError(e.Message, "Connection Error"); } catch (ZebraPrinterLanguageUnknownException e) { MessageBoxCreator.ShowError(e.Message, "Connection Error"); } finally { if (connection != null) { try { connection.Close(); } catch (ConnectionException) { } } SetButtonText("Read Mag Card"); SetButtonState(true); } }); }
private void GetListOfFormats() { ZebraPrinterConnection connection = getConnection(); ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection); String[] zplFormatExtensions = new String[] { "ZPL" }; String[] cpclFormatExtensions = new String[] { "FMT", "LBL" }; String[] extensions = printer.GetPrinterControlLanguage() == PrinterLanguage.ZPL ? zplFormatExtensions : cpclFormatExtensions; List <String> formatList = new List <String>(); foreach (String format in printer.GetFileUtil().RetrieveFileNames(extensions)) { formatList.Add(format); } Invoke(new FormatListEventHandler(DisplayNames), new object[] { formatList }); }
private void PrintLabel(string theIpAddress) { string ZPL_STRING = Resources.HeadBarcode + "^FS^FO250,50^A0,25,25^FD" + BarcodeDescription + "^FS^FO230,90^BCN,100,Y,N,N^FD" + BarcodeNumber + "^FS^XZ"; ZebraPrinter zebraPrinter = ZebraPrintHelper.Connect(new TcpConnection(theIpAddress, TcpConnection.DEFAULT_ZPL_TCP_PORT), PrinterLanguage.ZPL); if (ZebraPrintHelper.CheckStatus(zebraPrinter)) { ZebraPrintHelper.Print(zebraPrinter, ZPL_STRING); if (ZebraPrintHelper.CheckStatusAfter(zebraPrinter)) { Console.WriteLine($"Label Printed"); } } zebraPrinter = ZebraPrintHelper.Disconnect(zebraPrinter); }
private bool PrintOne(ZebraPrinter printer, string zplData) { try { if (GetPrinterStatus(printer) == Status.Ready) { printer.Connection.Write(Encoding.UTF8.GetBytes(zplData)); return(true); } return(false); } catch (ConnectionException) { return(false); } }
private void threadedConnect(String addressName) { try { connection.Open(); Thread.Sleep(1000); } catch (ZebraPrinterConnectionException) { updateGuiFromWorkerThread("Unable to connect with printer", Color.Red); disconnect(); } catch (Exception) { updateGuiFromWorkerThread("Error communicating with printer", Color.Red); disconnect(); } printer = null; if (connection != null && connection.IsConnected()) { try { printer = ZebraPrinterFactory.GetInstance(connection); PrinterLanguage pl = printer.GetPrinterControlLanguage(); updateGuiFromWorkerThread("Printer Language " + pl.ToString(), Color.LemonChiffon); Thread.Sleep(1000); updateGuiFromWorkerThread("Connected to " + addressName, Color.Green); Thread.Sleep(1000); } catch (ZebraPrinterConnectionException) { updateGuiFromWorkerThread("Unknown Printer Language", Color.Red); printer = null; Thread.Sleep(1000); disconnect(); } catch (ZebraPrinterLanguageUnknownException) { updateGuiFromWorkerThread("Unknown Printer Language", Color.Red); printer = null; Thread.Sleep(1000); disconnect(); } } }
public static bool CheckStatusAfter(ZebraPrinter printer) { PrinterStatus printerStatus = null; try { VerifyConnection(printer); printerStatus = printer.GetCurrentStatus(); while ((printerStatus.numberOfFormatsInReceiveBuffer > 0) && (printerStatus.isReadyToPrint)) { Thread.Sleep(500); printerStatus = printer.GetCurrentStatus(); } } catch (ConnectionException e) { throw new ConnectionException($"Error getting status from printer: {e.Message}"); } if (printerStatus.isReadyToPrint) { Console.WriteLine($"Ready To Print"); return(true); } else if (printerStatus.isPaused) { throw new NotSupportedException($"Cannot Print because the printer is paused."); } else if (printerStatus.isHeadOpen) { throw new NotSupportedException($"Cannot Print because the printer head is open."); } else if (printerStatus.isPaperOut) { throw new NotSupportedException($"Cannot Print because the paper is out."); } else { throw new NotSupportedException($"Cannot Print."); } return(false); }
/// <summary> /// 라벨 프린트 /// </summary> /// <param name="command">ZPL 라벨 프린트 커맨드</param> public static void PrintByCommand(string command) { try { if (!LabelPrint.PrinterConnectionOpen()) { return; } if (Printer == null) { Printer = ZebraPrinterFactory.GetInstance(PrinterConnection); } Printer.SendCommand(command); } catch (ConnectionException ex) { MessageBox.Show("프린트 실패" + Environment.NewLine + ex.ToString(), "실패", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void PerformListFiles(bool isFormat) { Connection printerConnection = null; try { Application.Current.Dispatcher.Invoke(() => { printerConnection = connectionSelector.GetConnection(); }); printerConnection.Open(); ZebraPrinter printer = ZebraPrinterFactory.GetInstance(printerConnection); string[] formatExtensions; if (printer.PrinterControlLanguage == PrinterLanguage.ZPL) { formatExtensions = new string[] { "ZPL" }; } else { formatExtensions = new string[] { "FMT", "LBL" }; } string[] formats = isFormat ? printer.RetrieveFileNames(formatExtensions) : printer.RetrieveFileNames(); Application.Current.Dispatcher.Invoke(() => { foreach (string format in formats) { viewModel.FormatsList.Add(format); } }); } catch (ConnectionException e) { MessageBoxCreator.ShowError(e.Message, "Connection Error"); } catch (ZebraIllegalArgumentException e) { MessageBoxCreator.ShowError(e.Message, "Connection Error"); } catch (ZebraPrinterLanguageUnknownException e) { MessageBoxCreator.ShowError(e.Message, "Connection Error"); } finally { if (printerConnection != null) { printerConnection.Close(); } } }
private void ReadSmartCard(bool sendData) { Connection connection = null; Task.Run(() => { try { UpdateSmartCardOutput(""); Application.Current.Dispatcher.Invoke(() => { connection = connectionSelector.GetConnection(); }); connection.Open(); ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection); SmartcardReader smartcardReader = SmartcardReaderFactory.Create(printer); if (smartcardReader != null) { byte[] response = sendData ? smartcardReader.DoCommand("8010000008") : smartcardReader.GetATR(); UpdateSmartCardOutput(string.Concat(response.Select(x => x.ToString("x2")))); smartcardReader.Close(); } else { MessageBoxCreator.ShowError("Printer does not have a smart card reader", "Smart Card Error"); } } catch (ConnectionException e) { MessageBoxCreator.ShowError(e.Message, "Connection Error"); } catch (ZebraPrinterLanguageUnknownException e) { MessageBoxCreator.ShowError(e.Message, "Connection Error"); } finally { if (connection != null) { try { connection.Close(); } catch (ConnectionException) { } } SetButtonStates(true); } }); }
public static bool CheckStatus(ZebraPrinter printer) { PrinterStatus printerStatus = null; try { VerifyConnection(printer); printerStatus = printer.GetCurrentStatus(); } catch (ConnectionException e) { throw new NotSupportedException($"Error getting status from printer: {e.Message}"); } if (null == printerStatus) { throw new NotSupportedException($"Unable to get status."); } else if (printerStatus.isReadyToPrint) { Console.WriteLine($"Ready To Print"); return(true); } else if (printerStatus.isPaused) { throw new NotSupportedException($"Cannot Print because the printer is paused."); } else if (printerStatus.isHeadOpen) { throw new NotSupportedException($"Cannot Print because the printer head is open."); } else if (printerStatus.isPaperOut) { throw new NotSupportedException($"Cannot Print because the paper is out."); } else { throw new NotSupportedException($"Cannot Print."); } return(false); }
private ZebraPrinter Connect(Connection printerConn) { ZebraPrinter printer = null; try { printerConn.Open(); printer = ZebraPrinterFactory.GetInstance(printerConn); } catch (ConnectionException e) { Debug.WriteLine("Connection Exception: " + e.ToString()); } catch (ZebraPrinterLanguageUnknownException e) { Debug.WriteLine("PrinterLanguage Exception: " + e.ToString()); } return(printer); }
public void Beep(int lenght) { try { printer = ZebraPrinterFactory.GetInstance(ThePrinterConn); PrinterStatus printerStatus = printer.GetCurrentStatus(); bool ready = printerStatus.IsReadyToPrint; if (ready) { String header = "! 0 200 200 0 1"; ThePrinterConn.Write(Encoding.UTF8.GetBytes(header + "\r\nBEEP " + lenght.ToString() + "\r\nPRINT\r\n")); } } catch (Exception e) { Logger.Logger.Log(e); return; } }
public PrinterStatus getPrinterStatus(rho.PrinterZebraImpl.PrinterZebra.EPrinterConnectionType connType, string address, Int32 port) { Logger.Write("MainWindow.getPrinterStatus call, address=" + address + " port=" + port.ToString()); PrinterStatus status = null; ZebraPrinterConnection connection = null; ZebraPrinter printer = null; if (connType == rho.PrinterZebraImpl.PrinterZebra.EPrinterConnectionType.eTCP) { connection = new TcpPrinterConnection(address, port); } else if (connType == rho.PrinterZebraImpl.PrinterZebra.EPrinterConnectionType.eBluetooth) { connection = new BluetoothPrinterConnection(address); } else if (connType == rho.PrinterZebraImpl.PrinterZebra.EPrinterConnectionType.eUSB) { connection = new UsbPrinterConnection(address); } else { Logger.Write("MainWindow.getPrinterStatus undifined connection type"); return(null); } connection.Open(); if (connection.IsConnected()) { printer = ZebraPrinterFactory.GetInstance(PrinterLanguage.ZPL, connection); status = printer.GetCurrentStatus(); } connection.Close(); Logger.Write("MainWindow.getPrinterStatus call finished"); return(status); }
public static string LinkPrinter(string printerName, int port) { try { string ip = Printer.GetRegistryData(printerName + "\\DsSpooler", "portName"); if (ip == "" || ip.Split(new char[] { '.' }).Length != 4) { throw new ConnectionException("没找到IP"); } foreach (string s in ip.Split(new char[] { '.' })) { int.Parse(s); } Ping pingSender = new Ping(); PingReply reply = pingSender.Send(ip, 1); //第一个参数为ip地址,第二个参数为ping的时间 if (reply.Status != IPStatus.Success) { throw new ConnectionException("链接失败!"); } TcpConnection connection = new TcpConnection(ip, port); connection.Open(); printer = ZebraPrinterFactory.GetInstance(connection); } catch (ConnectionException e) { printer = null; FileTools.WriteLineFile(FileTools.exceptionFilePath, DateTime.Now.ToString() + " " + printerName + e.Message); return(printerName + e.Message); } catch (FormatException e) { printer = null; FileTools.WriteLineFile(FileTools.exceptionFilePath, DateTime.Now.ToString() + " " + printerName + "IP地址不正确!"); return(printerName + "IP地址不正确!"); } return(""); }
/// <summary> /// 重启打印机 /// </summary> internal void ResetPrinter() { if (TryOpenPrinterConnection()) { if (printer != null) { lock (printerHelper) { printer.Reset(); printer = null; } lock (connectionHelper) { connection = null; } //printer = GetPrinter(); myEventLog.Log.Warn("正在重置打印机状态!"); } } }
private bool CheckPrintingStatus(ZebraPrinter printer) { PrinterStatus printerStatus = null; try { printerStatus = printer.GetCurrentStatus(); while (printerStatus.numberOfFormatsInReceiveBuffer > 0 && printerStatus.isReadyToPrint) { Thread.Sleep(100); printerStatus = printer.GetCurrentStatus(); } } catch (ConnectionException e) { Debug.WriteLine("Connection Exception: " + e.ToString()); } return(printerStatus.isReadyToPrint); }
private string GetPrinterStatus(ZebraPrinter printer) { try { PrinterStatus printerStatus = printer.GetCurrentStatus(); if (printerStatus.isReadyToPrint) { return(Status.Ready); } else if (printerStatus.isPaused) { return(Status.Paused); } else if (printerStatus.isHeadOpen) { return(Status.HeadOpen); } else if (printerStatus.isPaperOut) { return(Status.MediaOut); } else if (printerStatus.isRibbonOut) { return(Status.RibbonOut); } else { return(Status.CannotPrint); } } catch (ConnectionException e) { return(e.ToString()); } catch (ZebraPrinterLanguageUnknownException e) { return(e.ToString()); } }
public void disconnect(IMethodResult oResult) { Logger.Write("disconnect call"); if (m_connection != null && m_connection.IsConnected()) { Thread.Sleep(1000); m_connection.Close(); Thread.Sleep(1000); } m_connection = null; m_printer = null; oResult.set(ZebraConstants.PRINTER_STATUS_SUCCESS); }
public void connectWithOptions(IReadOnlyDictionary<string, string> options, IMethodResult oResult) { Logger.Write("connectWithOptions call"); Logger.Write("options:", options); string valueObj = null; Int32 connectionTimeout = 0; if (m_connection != null && m_connection.IsConnected() && m_printer != null) { m_connection.Close(); Thread.Sleep(1000); m_connection = null; m_printer = null; } if (options.ContainsKey(ZebraConstants.HK_TIMEOUT)) { valueObj = options[ZebraConstants.HK_TIMEOUT]; if ((valueObj != null) && (valueObj is String)) { try { connectionTimeout = Int32.Parse(valueObj.ToString()); } catch (System.FormatException) { m_maxTimeoutForRead = 0; } } } if (options.ContainsKey(ZebraConstants.PROPERTY_MAX_TIMEOUT_FOR_READ)) { valueObj = options[ZebraConstants.PROPERTY_MAX_TIMEOUT_FOR_READ]; if ((valueObj != null) && (valueObj is String)) { try { m_maxTimeoutForRead = Int32.Parse(valueObj.ToString()); } catch (System.FormatException) { m_maxTimeoutForRead = 0; } } } if (options.ContainsKey(ZebraConstants.PROPERTY_TIME_TO_WAIT_FOR_MORE_DATA)) { valueObj = options[ZebraConstants.PROPERTY_TIME_TO_WAIT_FOR_MORE_DATA]; if ((valueObj != null) && (valueObj is String)) { try { m_timeToWaitForMoreData = Int32.Parse(valueObj.ToString()); } catch (System.FormatException) { m_maxTimeoutForRead = 0; } } } ConnecttionJob job = new ConnecttionJob(); job.Address = ID; job.Port = Port; job.ConnectionType = connectionType; job.MaxTimeoutForRead = m_maxTimeoutForRead; job.TimeToWaitForMoreData = m_timeToWaitForMoreData; if (connectionTimeout == 0) { job.Connect(); } else { if (!job.Connect(connectionTimeout)) { oResult.set(ZebraConstants.PRINTER_STATUS_ERR_TIMEOUT); return; } } if (job.Connection != null && job.Printer != null) { m_connection = job.Connection; m_printer = job.Printer; oResult.set(ZebraConstants.PRINTER_STATUS_SUCCESS); return; } oResult.set(ZebraConstants.PRINTER_STATUS_ERR_NOT_CONNECTED); }