public class DiscoveryUtil
extends Object
package test.zebra.sdk.discovery.examples;
import java.util.Map;
import com.zebra.sdk.comm.Connection;
import com.zebra.sdk.comm.ConnectionException;
import com.zebra.sdk.comm.TcpConnection;
import com.zebra.sdk.printer.discovery.DiscoveryPacketDecodeException;
import com.zebra.sdk.printer.discovery.DiscoveryUtil;
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();
}
}
}
}
Modifier and Type | Method and Description |
---|---|
static java.util.Map<String,String> |
getDiscoveryDataMap(Connection connection)
Reads the discovery packet from the provided connection and returns a discovery data map
|
static java.util.Map<String,String> |
parseDiscoveryPacket(String discoveryPacketMimed)
Decodes the provided MIME encoded discovery packet and returns a discovery data map
|
public static java.util.Map<String,String> parseDiscoveryPacket(String discoveryPacketMimed) throws DiscoveryPacketDecodeException
discoveryPacketMimed
- a Base64 encoded discovery packetDiscoveryPacketDecodeException
- if provided a malformed discovery packetpublic static java.util.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
© 2017 ZIH Corp. All Rights Reserved.