public string BuildBluetoothConnectionChannelsString(string macAddress) { BluetoothConnection connection = new BluetoothConnection(macAddress); connection.Open(); // Check connection try { ServiceDiscoveryHandlerImplementation serviceDiscoveryHandler = new ServiceDiscoveryHandlerImplementation(); BluetoothDiscoverer.FindServices(global::Android.App.Application.Context, macAddress, serviceDiscoveryHandler); while (!serviceDiscoveryHandler.Finished) { Task.Delay(100); } StringBuilder sb = new StringBuilder(); foreach (ConnectionChannel connectionChannel in serviceDiscoveryHandler.ConnectionChannels) { sb.AppendLine(connectionChannel.ToString()); } return(sb.ToString()); } finally { try { connection?.Close(); } catch (ConnectionException) { } } }
private void doBluetoothDiscovery() { try { displayPrinters(BluetoothDiscoverer.FindPrinters()); } catch (DiscoveryException ex) { handleException(ex.Message); } catch (ZebraGeneralException) { handleException("Bluetooth not available"); } }
/** * Use BlutoothDiscoverer class to get an array of printers detected * Display printers in listbox * **/ private void doBluetoothDiscovery() { updateButtonFromWorkerThread(false); Thread.Sleep(1000); try { DiscoveredPrinter[] printers = BluetoothDiscoverer.FindPrinters(); displayPrinters(printers); updateButtonFromWorkerThread(true); } catch (DiscoveryException ex) { handleException(ex.Message); updateButtonFromWorkerThread(true); } }
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; }); }); } }
public void FindBluetoothPrinters(DiscoveryHandler discoveryHandler) { BluetoothDiscoverer.FindPrinters(discoveryHandler); }
public void FindBluetoothPrinters(DiscoveryHandler discoveryHandler) { BluetoothDiscoverer.FindPrinters(global::Android.App.Application.Context, discoveryHandler); }
/// <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; } }
private void searchBluetooth() { Logger.Write("Start search Bluetooth printers"); // process connection to Bluetooth PrinterZebra.EPrinterConnectionType connType = PrinterZebra.EPrinterConnectionType.eBluetooth; if (deviceAdress != null && !PrinterManager.Instance.hasPrinter(deviceAdress)) { Logger.Write("Start search in address: " + deviceAdress); ConnecttionJob job = zebraSingleton.tryToConnect(0, deviceAdress, ZebraConstants.connectionTimeout, connType); if (job.Connection != null) { PrinterManager.Instance.addPrinterWithID(deviceAdress, 0, connType); if (!isSearchStopped) { zebraSingleton.sendConnectResult(job.FriendlyName, deviceAdress, 0, connType, oResult); } job.Close(); } } else { DiscoveredPrinter[] printers = null; for (int attempt = 0; attempt < connettionAttempts; attempt++) { printers = BluetoothDiscoverer.FindPrinters(); if (printers.Length > 0) { break; } Thread.Sleep(500); } LogDiscoveryPrinters(printers); foreach (DiscoveredPrinter printer in printers) { Logger.Write("searching in address: " + printer.Address); if (PrinterManager.Instance.hasPrinter(printer.Address)) { continue; } if (isSearchStopped == true) { return; } Logger.Write("Found printer on address: " + printer.Address); //zebraSingleton.sendConnectResult(job.FriendlyName, printer.Address, 0, connType, oResult); zebraSingleton.sendConnectResult(printer.Address, printer.Address, 0, connType, oResult); } } }