Click or drag to resize

UsbDiscoverer Class

Discovers Zebra printers connected to an Android™ device via USB Host.
Inheritance Hierarchy
SystemObject
  Zebra.Sdk.Printer.DiscoveryUsbDiscoverer

Namespace:  Zebra.Sdk.Printer.Discovery
Assemblies:   SdkApi.Desktop (in SdkApi.Desktop.dll) Version: 2.15.2634
  ZebraPrinterSdk (in ZebraPrinterSdk.dll) Version: 2.15.2521
Syntax
public class UsbDiscoverer

The UsbDiscoverer type exposes the following members.

Constructors
  NameDescription
Public methodUsbDiscoverer
A class used to discover USB connected Zebra printers. Printers can be accessed either directly or through a USB printer driver.
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodStatic memberFindPrinters(Context, DiscoveryHandler)
Enumerate all currently connected Zebra USB printers.
Public methodStatic memberFindPrinters(UsbManager, DiscoveryHandler)
Enumerate all currently connected Zebra USB printers.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodStatic memberGetZebraDriverPrinters
Enumerate locally installed Zebra Designer Drivers.
Public methodStatic memberGetZebraUsbPrinters
Enumerate all currently connected Zebra USB printers.
Public methodStatic memberGetZebraUsbPrinters(DiscoveredPrinterFilter)
Enumerate currently connected Zebra USB printers that meet the specified DiscoveredPrinterFilter criteria.
Public methodStatic memberIsZebraUsbDevice
Determines if the UsbDevice is a Zebra printer.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Examples
Desktop
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.");
    }
}
Examples
Android
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>();
    }
}
See Also