public class DiscoveryUtil extends Object
package test.zebra.sdk.discovery.examples;
import com.zebra.sdk.comm.Connection;
import com.zebra.sdk.comm.ConnectionException;
import com.zebra.sdk.comm.TcpConnection;
import com.zebra.sdk.device.MagCardReader;
import com.zebra.sdk.device.MagCardReaderFactory;
import com.zebra.sdk.printer.ZebraPrinter;
import com.zebra.sdk.printer.ZebraPrinterFactory;
import com.zebra.sdk.printer.ZebraPrinterLanguageUnknownException;
import com.zebra.sdk.printer.discovery.*;
import sun.rmi.transport.tcp.TCPConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class DiscoveryUtilExample {
public static void main(String[] args) {
// Instantiate connection for ZPL TCP port at given address
Connection connection = new TcpConnection("192.168.1.1", TcpConnection.DEFAULT_ZPL_TCP_PORT);
try {
// Open the connection - physical connection is established here.
connection.open();
Map<String, String> discoveryData = DiscoveryUtil.getDiscoveryDataMap(connection);
System.out.println("The printer's firmware version is: " + discoveryData.get("FIRMWARE_VER"));
} catch (ConnectionException e) {
// Handle communications error here.
e.printStackTrace();
} catch (DiscoveryPacketDecodeException e) {
e.printStackTrace();
} finally {
// Close the connection to release resources.
try {
connection.close();
} catch (ConnectionException e) {
e.printStackTrace();
}
}
}
}
Constructor and Description |
---|
DiscoveryUtil() |
Modifier and Type | Method and Description |
---|---|
static Map<String,String> |
getDiscoveryDataMap(Connection connection)
Reads the discovery packet from the provided connection and returns a discovery data map
|
static Map<String,String> |
parseDiscoveryPacket(String discoveryPacketMimed)
Decodes the provided MIME encoded discovery packet and returns a discovery data map
|
public static Map<String,String> parseDiscoveryPacket(String discoveryPacketMimed) throws DiscoveryPacketDecodeException
discoveryPacketMimed
- a Base64 encoded discovery packetDiscoveryPacketDecodeException
- if provided a malformed discovery packetpublic static Map<String,String> getDiscoveryDataMap(Connection connection) throws DiscoveryPacketDecodeException, ConnectionException
connection
- A Connection
to a printerConnectionException
- if an I/O error occurs.DiscoveryPacketDecodeException
- if provided a malformed discovery packet
© 2016 ZIH Corp. All Rights Reserved.