private static String GetPrinterDisplayName(DiscoveredPrinter printer) { String printerName = printer.Address; if (printer is DiscoveredPrinterBluetooth) { printerName += " (" + ((DiscoveredPrinterBluetooth)printer).FriendlyName + ")"; } else if (printer is DiscoveredPrinterNetwork) { DiscoveredPrinterNetwork thisDiscoveredPrinterNetwork = (DiscoveredPrinterNetwork)printer; if (false == thisDiscoveredPrinterNetwork.Address.Equals(thisDiscoveredPrinterNetwork.DnsName)) { printerName += " (" + thisDiscoveredPrinterNetwork.DnsName + ")"; } } return(printerName); }
private void searchWiFi() { Logger.Write("Start search TCP printers"); // process connection to TCP address PrinterZebra.EPrinterConnectionType connType = PrinterZebra.EPrinterConnectionType.eTCP; if (deviceAdress != null && devicePort > 0 && !PrinterManager.Instance.hasPrinter(deviceAdress)) { Logger.Write("searching in address: " + deviceAdress); ConnecttionJob job = zebraSingleton.tryToConnect(devicePort, deviceAdress, ZebraConstants.connectionTimeout, connType); if (job.Connection != null) { Logger.Write("Found printer on address: " + deviceAdress); PrinterManager.Instance.addPrinterWithID(deviceAdress, devicePort, connType); if (!isSearchStopped) { zebraSingleton.sendConnectResult(job.FriendlyName, deviceAdress, devicePort, connType, oResult); } job.Close(); } } else { Logger.Write("Start search in TCP network"); DiscoveredPrinter[] printers = null; for (int attempt = 0; attempt < connettionAttempts; attempt++) { printers = NetworkDiscoverer.LocalBroadcast(); if (printers.Length > 0) { break; } Thread.Sleep(500); } if (printers.Length == 0) { for (int attempt = 0; attempt < connettionAttempts; attempt++) { printers = NetworkDiscoverer.Multicast(5); if (printers.Length > 0) { break; } Thread.Sleep(500); } } LogDiscoveryPrinters(printers); foreach (DiscoveredPrinter printer in printers) { if (isSearchStopped) { break; } Logger.Write("searching in address: " + printer.Address); if ((printer is DiscoveredPrinterNetwork) && !PrinterManager.Instance.hasPrinter(printer.Address)) { DiscoveredPrinterNetwork networkPrinter = (DiscoveredPrinterNetwork)printer; ConnecttionJob job = zebraSingleton.tryToConnect(networkPrinter.Port, networkPrinter.Address, ZebraConstants.connectionTimeout, connType); if (job.Connection != null) { Logger.Write("Found printer on address: " + printer.Address); PrinterManager.Instance.addPrinterWithID(networkPrinter.Address, networkPrinter.Port, connType); zebraSingleton.sendConnectResult(job.FriendlyName, networkPrinter.Address, networkPrinter.Port, connType, oResult); job.Close(); } } } } }