Click or drag to resize

NetworkCardDiscoverer Class

A class used to discover printers on an IP Network.
Inheritance Hierarchy
SystemObject
  Zebra.Sdk.Card.Printer.DiscoveryNetworkCardDiscoverer

Namespace:  Zebra.Sdk.Card.Printer.Discovery
Assembly:  SdkApi_Card_Core (in SdkApi_Card_Core.dll) Version: 2.14.1989
Syntax
public class NetworkCardDiscoverer

The NetworkCardDiscoverer type exposes the following members.

Constructors
  NameDescription
Public methodNetworkCardDiscoverer
Initializes a new instance of the NetworkCardDiscoverer class
Top
Properties
  NameDescription
Public propertyStatic memberSetNetworkAdapterAddresses
Sets the list of network adapter addresses to be used during discovery.
Top
Methods
  NameDescription
Public methodStatic memberDirectedBroadcast(DiscoveryHandler, String)
Sends a directed broadcast discovery packet to the subnet specified by ipAddress.
Public methodStatic memberDirectedBroadcast(DiscoveryHandler, String, Int32)
Sends a directed broadcast discovery packet to the subnet specified by ipAddress.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodStatic memberFindPrinters(DiscoveryHandler)
This method will search the network using a combination of discovery methods to find printers on the network.
Public methodStatic memberFindPrinters(DiscoveryHandler, ListString)
Sends a discovery request to the list of printer DNS names or IP addresses in printersToFind.
Public methodStatic memberFindPrinters(DiscoveryHandler, ListString, Int32)
Sends a discovery request to the list of printer DNS names or IP addresses in printersToFind.
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 memberLocalBroadcast(DiscoveryHandler)
Sends a local broadcast packet.
Public methodStatic memberLocalBroadcast(DiscoveryHandler, Int32)
Sends a local broadcast packet.
Public methodStatic memberSubnetSearch(DiscoveryHandler, String)
Sends a discovery packet to the IP addresses specified in the subnetRange.
Public methodStatic memberSubnetSearch(DiscoveryHandler, String, Int32)
Sends a discovery packet to the IP addresses specified in the subnetRange.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Examples
using System;
using System.Collections.Generic;
using System.Threading;
using Zebra.Sdk.Card.Printer.Discovery;
using Zebra.Sdk.Printer.Discovery;

public class NetworkCardDiscovererExample {

    public static void Main(string[] args) {
        try {
            Console.WriteLine("Starting printer discovery.");

            NetworkDiscoveryHandler discoveryHandler = new NetworkDiscoveryHandler();
            NetworkCardDiscoverer.FindPrinters(discoveryHandler);

            discoveryHandler.DiscoveryCompleteEvent.WaitOne();

            List<DiscoveredPrinter> discoveredPrinters = discoveryHandler.DiscoveredPrinters;
            Console.WriteLine($"Discovered {discoveredPrinters.Count} printers.");

            foreach (DiscoveredPrinter printer in discoveredPrinters) {
                Console.WriteLine(printer);
            }
        } catch (DiscoveryException e) {
            Console.WriteLine($"Error discovering printers: {e.Message}");
        }
    }

    private class NetworkDiscoveryHandler : DiscoveryHandler {

        private List<DiscoveredPrinter> printers = new List<DiscoveredPrinter>();
        private AutoResetEvent discoCompleteEvent = new AutoResetEvent(false);

        public void DiscoveryError(string message) {
            Console.WriteLine($"An error occurred during discovery: {message}.");
            discoCompleteEvent.Set();
        }

        public void DiscoveryFinished() {
            discoCompleteEvent.Set();
        }

        public void FoundPrinter(DiscoveredPrinter printer) {
            printers.Add(printer);
        }

        public List<DiscoveredPrinter> DiscoveredPrinters {
            get => printers;
        }

        public AutoResetEvent DiscoveryCompleteEvent {
            get => discoCompleteEvent;
        }
    }
}
See Also