private void DiscoverPrinters() { viewModel.DiscoveredPrinters.Clear(); viewModel.IsDiscovering = true; Task.Run(() => { try { List <DiscoveredUsbPrinter> usbPrinters = UsbDiscoverer.GetZebraUsbPrinters(new ZebraCardPrinterFilter()); foreach (DiscoveredUsbPrinter printer in usbPrinters) { Application.Current.Dispatcher.Invoke(() => { viewModel.DiscoveredPrinters.Add(printer); }); } NetworkCardDiscoverer.FindPrinters(new NetworkCardDiscoveryHandler(this)); countdownEvent.Wait(); } catch (Exception e) { Application.Current.Dispatcher.Invoke(() => { MessageBoxHelper.ShowError($"Error discovering printers: {e.Message}"); }); } finally { Application.Current.Dispatcher.Invoke(() => { viewModel.IsDiscovering = false; }); } }); }
/* * Connect to a printer using the Zebra API */ private void ConnectToPrinter() { DiscoveredUsbPrinter discoveredPrinter = UsbDiscoverer.GetZebraUsbPrinters(new ZebraPrinterFilter())[0]; Connection connection = discoveredPrinter.GetConnection(); connection.Open(); printer = ZebraPrinterFactory.GetInstance(connection); ConnectionLabel.Text = "Printer Connected!"; }
public void Connect() { usbPrinter = UsbDiscoverer.GetZebraUsbPrinters(new ZebraPrinterFilter()).FirstOrDefault(); if (usbPrinter == null) { throw new ArgumentException("Принтер не найден!"); } connection = usbPrinter.GetConnection(); Connected = true; }
private void commandPrint() { UsbConnection connection = null; try { DiscoveredUsbPrinter usbPrinter = null; List <DiscoveredUsbPrinter> printers = UsbDiscoverer.GetZebraUsbPrinters(new ZebraPrinterFilter()); if (printers == null || printers.Count <= 0) { MessageBox.Show("没有检测到打印机,请检查打印机是否开启!"); myEventLog.LogInfo("没有检测到打印机,请检查打印机是否开启!"); return; } usbPrinter = printers[0]; connection = new UsbConnection(usbPrinter.Address); connection.Open(); var printer = ZebraPrinterFactory.GetInstance(connection); //printer.SendCommand("~JA"); var startTime = DateTime.Now; var command = GetCommandFromDb(); Console.WriteLine($"生成打印命令花费时间:{(DateTime.Now - startTime).TotalMilliseconds}ms"); System.Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")); startTime = DateTime.Now; for (int i = 0; i < 20; i++) { printer.SendCommand(command); Console.WriteLine($"打印内容发送成功!花费时间:{(DateTime.Now - startTime).TotalMilliseconds}ms"); Thread.Sleep(200); startTime = DateTime.Now; } //System.Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")); //printer.SendCommand(command); //Console.WriteLine($"打印内容发送成功!花费时间:{(DateTime.Now - startTime).TotalMilliseconds}ms"); //Thread.Sleep(5000); //printer.SendCommand("~JA"); } catch (Exception e) { connection.Close(); } }
/// <summary> /// Lists all the printers connected (USB) to the workstation /// </summary> /// <returns></returns> public static ZebraZC3[] GetPrinterList() { List <ZebraZC3> devices = new List <ZebraZC3>(); foreach (DiscoveredUsbPrinter usbPrinter in UsbDiscoverer.GetZebraUsbPrinters(new ZebraCardPrinterFilter())) { devices.Add(new ZebraZC3(usbPrinter)); } return(devices.ToArray()); }
public void GetZebraUsbDirectPrinters(DiscoveryHandler discoveryHandler) { try { foreach (DiscoveredUsbPrinter printer in UsbDiscoverer.GetZebraUsbPrinters()) { discoveryHandler.FoundPrinter(printer); } discoveryHandler.DiscoveryFinished(); } catch (Exception e) { discoveryHandler.DiscoveryError(e.Message); } }
private void button1_Click(object sender, EventArgs e) { if (textBoxId.Text != "") { Value1 = textBoxId.Text; ZebraCardPrinter zebraCardPrinter = null; Connection connection = null; String usbAdress = null; try { foreach (DiscoveredPrinter usbPrinter in UsbDiscoverer.GetZebraUsbPrinters(new ZebraCardPrinterFilter())) { usbAdress = usbPrinter.Address; } connection = new UsbConnection(usbAdress); connection.Open(); zebraCardPrinter = ZebraCardPrinterFactory.GetInstance(connection); ZebraTemplate zebraCardTemplate = new ZebraCardTemplate(zebraCardPrinter); //string templateData = GetTemplateData(); List <string> templateFields = zebraCardTemplate.GetTemplateDataFields(Template); Dictionary <string, string> fieldData = PopulateTemplateFieldData(templateFields); // Generate template job TemplateJob templateJob = zebraCardTemplate.GenerateTemplateDataJob(Template, fieldData); // Send job int jobId = zebraCardPrinter.PrintTemplate(1, templateJob); // Poll job status JobStatusInfo jobStatus = PollJobStatus(jobId, zebraCardPrinter); //labelStatus.Text = "Impression OK"; //Console.WriteLine($"Job {jobId} completed with status '{jobStatus.PrintStatus}'."); } catch (Exception ev) { labelStatus.Text = "Erreur d'impression : " + ev.Message; //Console.WriteLine($"Error printing template: {ev.Message}"); } finally { CloseQuietly(connection, zebraCardPrinter); } } else { MessageBox.Show("Pas de valeur"); } }
public override ConnectionA GetConnection() { DiscoveredUsbPrinter usbPrinter = null; List <DiscoveredUsbPrinter> printers = UsbDiscoverer.GetZebraUsbPrinters(new ZebraPrinterFilter()); if (printers == null || printers.Count <= 0) { //MessageBox.Show("没有检测到打印机,请检查打印机是否开启!"); myEventLog.LogInfo("没有检测到打印机,请检查打印机是否开启!"); return(null); } usbPrinter = printers[0]; return(new UsbConnection(usbPrinter.Address)); }
private static string GetUSBConnection() { string usbString = ""; try { foreach (DiscoveredUsbPrinter usbPrinter in UsbDiscoverer.GetZebraUsbPrinters(new ZebraPrinterFilter())) { usbString += usbPrinter.Address; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(usbString); }
/// <summary> /// Discovers USB connected Zebra Card Printers /// </summary> /// <param name="count">number printers discovered</param> /// <returns>true if no errors are encountered</returns> public bool DiscoverUSBPrinters() { bool discovered = false; try { UsbPrinters = UsbDiscoverer.GetZebraUsbPrinters(new ZebraCardPrinterFilter()); if (UsbPrinters == null || UsbPrinters.Count == 0) { throw new Exception("No printers found"); } UsbPrinter = UsbPrinters[0]; discovered = true; } catch (Exception ex) { printerError = ex.Message; } return(discovered); }
private DiscoveredPrinter DiscoveryUSB() { DiscoveredPrinter discoveredPrinter = null; try { foreach (DiscoveredUsbPrinter usbPrinter in UsbDiscoverer.GetZebraUsbPrinters()) { discoveredPrinter = usbPrinter; } } catch (DiscoveryException e) { Debug.WriteLine("DiscoveryException Exception: " + e.ToString()); } return(discoveredPrinter); }
public static IEnumerable <Printer> GetConnectedPrinters() { var printers = UsbDiscoverer.GetZebraUsbPrinters(new ZebraPrinterFilter()); /*var printers = discoveredUsbPrinters.Select(d => { * var conn = d.GetConnection(); * conn.Open(); * return ZebraPrinterFactory.GetInstance(conn); * });*/ var p = printers?.FirstOrDefault(); if (p == null) { return(null); } var model = p.DiscoveryDataMap["MODEL"] + " | " + p.DiscoveryDataMap["SERIAL_NUMBER"]; return(printers.Select(p => new Printer(p))); }
private void Form1_Load(object sender, EventArgs e) { try { foreach (DiscoveredUsbPrinter usbPrinter in UsbDiscoverer.GetZebraUsbPrinters(new ZebraCardPrinterFilter())) { Printer = usbPrinter.ToString(); } if (Environment.UserName.ToString().ToUpper() == "DMARROQUIN") { Printer = @"\\?\usb#vid_0a5f&pid_0148#412509098#{28d78fad-5a12-11d1-ae5b-0000f803a8c2}"; } } catch (Exception ex) { MessageBox.Show(ex.Message); } // }
public static DiscoveredPrinter GetUSBPrinter() { DiscoveredPrinter discoveredPrinter = null; try { foreach (var usbPrinter in UsbDiscoverer.GetZebraUsbPrinters()) { discoveredPrinter = usbPrinter; Console.WriteLine(usbPrinter); } } catch (ConnectionException e) { Console.WriteLine($"Error discovering local printers: {e.Message}"); } Console.WriteLine("Done discovering local printers."); return(discoveredPrinter); }
public List <DiscoveredPrinter> GetUSBPrinters() { List <DiscoveredPrinter> printerList = new List <DiscoveredPrinter>(); try { foreach (DiscoveredUsbPrinter usbPrinter in UsbDiscoverer.GetZebraUsbPrinters()) { printerList.Add(usbPrinter); Console.WriteLine(usbPrinter); } } catch (ConnectionException e) { Console.WriteLine($"Error discovering local printers: {e.Message}"); } Console.WriteLine("Done discovering local printers."); return(printerList); }
public Connection ImprimirEtiqueta() { Connection c = null; try { //O DiscoverdUsbPrinter só funciona com interface visual, não consegui que funcionasse com o terminal. foreach (DiscoveredUsbPrinter usbPrinter in UsbDiscoverer.GetZebraUsbPrinters(new ZebraPrinterFilter())) { c = usbPrinter.GetConnection(); c.Open(); } } catch (ConnectionException ex) { MessageBox.Show("Não Foi possivel localizar a impressora." + ex.Message); } return(c); }
/// <summary> /// 프린터 커넥션 활성화 /// </summary> public static bool PrinterConnectionOpen() { try { List <string> list = new List <string>(); foreach (DiscoveredUsbPrinter usbPrinter in UsbDiscoverer.GetZebraUsbPrinters(new ZebraPrinterFilter())) { list.Add(usbPrinter.ToString()); } if (list.Count == 0) { MessageBox.Show("연결된 라벨 프린터가 없습니다.", "알림", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } // 커넥션이 없으면 커넥션 만들어서 Open하고 return true if (PrinterConnection == null) { PrinterConnection = new UsbConnection(list[0]); PrinterConnection.Open(); return(true); } else { return(true); } } catch (ConnectionException ex) { MessageBox.Show("프린터 연결실패" + Environment.NewLine + ex.ToString(), "실패", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } catch (Exception ex) { MessageBox.Show("프린터 연결실패" + Environment.NewLine + ex.ToString(), "실패", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } }
public PrinterDiscoveryWindow() { InitializeComponent(); selectedPrinterInfo = new PrinterInfo(); DoubleAnimation da = new DoubleAnimation() { From = 0, To = 360, Duration = new Duration(TimeSpan.FromSeconds(1.5)), RepeatBehavior = RepeatBehavior.Forever }; rt = new RotateTransform(); animatedDiscoveryArrow_image.RenderTransform = rt; animatedDiscoveryArrow_image.RenderTransformOrigin = new Point(0.5, 0.5); rt.BeginAnimation(RotateTransform.AngleProperty, da); List <DiscoveredUsbPrinter> connectedUsbPrinters = UsbDiscoverer.GetZebraUsbPrinters(new ZebraPrinterFilter()); foreach (DiscoveredUsbPrinter usbPrinter in connectedUsbPrinters) { string imageSource = "/Resources/usb.png"; Application.Current.Dispatcher.Invoke(() => { PrinterDiscoverListView.Items.Add(new { ConnectionImageSource = imageSource, FriendlyName = "USB Printer (" + usbPrinter.DiscoveryDataMap["SERIAL_NUMBER"] + ")", IpAddress = usbPrinter.Address }); }); } DiscoveryHandlerImpl networkDiscoHandler = new DiscoveryHandlerImpl(this); NetworkDiscoverer.FindPrinters(networkDiscoHandler); DiscoveryHandlerImpl bluetoothDiscoHandler = null; if (IsBluetoothSupported()) { bluetoothDiscoHandler = new DiscoveryHandlerImpl(this); BluetoothDiscoverer.FindPrinters(bluetoothDiscoHandler); } if (bluetoothDiscoHandler != null) { Task.Run(() => { while (!bluetoothDiscoHandler.DiscoveryComplete || !networkDiscoHandler.DiscoveryComplete) { Thread.Sleep(50); } Application.Current.Dispatcher.Invoke(() => { animatedDiscoveryArrow_image.Visibility = Visibility.Hidden; }); }); } else { Task.Run(() => { while (!networkDiscoHandler.DiscoveryComplete) { Thread.Sleep(50); } Application.Current.Dispatcher.Invoke(() => { animatedDiscoveryArrow_image.Visibility = Visibility.Hidden; }); }); } }
/// <exception cref="ConnectionException"></exception> /// <exception cref="DiscoveryException"></exception> private void PerformDiscovery() { DiscoveryHandlerImpl discoveryHandler = new DiscoveryHandlerImpl(this); switch (discoveryMethodsDropdown.SelectedItem) { case DiscoveryMethod.DirectedBroadcast: NetworkDiscoverer.DirectedBroadcast(discoveryHandler, viewModel.IpAddress); break; case DiscoveryMethod.FindPrintersNearMe: NetworkDiscoverer.FindPrinters(discoveryHandler); break; case DiscoveryMethod.LocalBroadcast: NetworkDiscoverer.LocalBroadcast(discoveryHandler); break; case DiscoveryMethod.MulticastBroadcast: NetworkDiscoverer.Multicast(discoveryHandler, int.Parse(viewModel.NumberOfHops)); break; case DiscoveryMethod.SubnetSearch: NetworkDiscoverer.SubnetSearch(discoveryHandler, viewModel.SubnetRange); break; case DiscoveryMethod.ZebraUsbDrivers: try { discoveryHandler = null; discoverPrintersButton.IsEnabled = false; viewModel.DiscoveredPrinters.Clear(); foreach (DiscoveredPrinterDriver printer in UsbDiscoverer.GetZebraDriverPrinters()) { viewModel.DiscoveredPrinters.Add(printer); } } finally { SetDiscoverButtonState(true); } break; case DiscoveryMethod.UsbDirect: try { discoveryHandler = null; discoverPrintersButton.IsEnabled = false; viewModel.DiscoveredPrinters.Clear(); foreach (DiscoveredUsbPrinter printer in UsbDiscoverer.GetZebraUsbPrinters()) { viewModel.DiscoveredPrinters.Add(printer); } } finally { SetDiscoverButtonState(true); } break; case DiscoveryMethod.Bluetooth: BluetoothDiscoverer.FindPrinters(discoveryHandler); break; } }