UsbDiscoverer Class |
Namespace: Zebra.Sdk.Printer.Discovery
The UsbDiscoverer type exposes the following members.
Name | Description | |
---|---|---|
UsbDiscoverer |
A class used to discover USB connected Zebra printers. Printers can be accessed either directly or through a USB
printer driver.
|
Name | Description | |
---|---|---|
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
FindPrinters(Context, DiscoveryHandler) |
Enumerate all currently connected Zebra USB printers.
| |
FindPrinters(UsbManager, DiscoveryHandler) |
Enumerate all currently connected Zebra USB printers.
| |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
GetZebraDriverPrinters |
Enumerate locally installed Zebra Designer Drivers.
| |
GetZebraUsbPrinters |
Enumerate all currently connected Zebra USB printers.
| |
GetZebraUsbPrinters(DiscoveredPrinterFilter) |
Enumerate currently connected Zebra USB printers that meet the specified DiscoveredPrinterFilter criteria.
| |
IsZebraUsbDevice |
Determines if the UsbDevice is a Zebra printer.
| |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
using System; using Zebra.Sdk.Comm; using Zebra.Sdk.Printer.Discovery; public class UsbDiscovererExample { public static void Main(string[] args) { try { foreach (DiscoveredPrinterDriver printer in UsbDiscoverer.GetZebraDriverPrinters()) { Console.WriteLine(printer); } foreach (DiscoveredUsbPrinter usbPrinter in UsbDiscoverer.GetZebraUsbPrinters(new ZebraPrinterFilter())) { Console.WriteLine(usbPrinter); } } catch (ConnectionException e) { Console.WriteLine($"Error discovering local printers: {e.Message}"); } Console.WriteLine("Done discovering local printers."); } }
using Android.App; using Android.OS; using Android.Views; using Android.Widget; using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Zebra.Sdk.Printer.Discovery; public class UsbDiscovererExample : Activity { protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); LinearLayout layout = (LinearLayout)View.Inflate(this, Android.Resource.Layout.ActivityListItem, null); layout.Orientation = Orientation.Vertical; Button testButton = new Button(this) { Text = "Run USB Discovery Example", LayoutParameters = new ViewGroup.LayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)) }; layout.AddView(testButton); SetContentView(layout); testButton.Click += async (sender, e) => { await Task.Run(() => { UsbDiscoveryHandler discoveryHandler = new UsbDiscoveryHandler(); UsbDiscoverer.FindPrinters(ApplicationContext, discoveryHandler); while (!discoveryHandler.DiscoveryComplete) { Thread.Sleep(10); } foreach (DiscoveredPrinter printer in discoveryHandler.DiscoveredPrinters) { Console.WriteLine(printer); } Console.WriteLine($"Discovered {discoveryHandler.DiscoveredPrinters.Count} Link-OS(TM) printers."); }); }; } private class UsbDiscoveryHandler : DiscoveryHandler { public void DiscoveryError(string message) { Console.WriteLine($"An error occurred during discovery: {message}."); DiscoveryComplete = true; } public void DiscoveryFinished() { DiscoveryComplete = true; } public void FoundPrinter(DiscoveredPrinter printer) { DiscoveredPrinters.Add(printer); } public bool DiscoveryComplete { get; private set; } = false; public List<DiscoveredPrinter> DiscoveredPrinters { get; } = new List<DiscoveredPrinter>(); } }