Package com.zebra.sdk.printer.discovery
Class DiscoveryUtil
Object
com.zebra.sdk.printer.discovery.DiscoveryUtil
Defines functions used when discovering information about a printer.
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();
}
}
}
}
-
Method Summary
Modifier and TypeMethodDescriptiongetDiscoveryDataMap(Connection connection) Reads the discovery packet from the provided connection and returns a discovery data mapparseDiscoveryPacket(String discoveryPacketRaw) Decodes the provided MIME encoded discovery packet and returns a discovery data map
-
Method Details
-
parseDiscoveryPacket
public static Map<String,String> parseDiscoveryPacket(String discoveryPacketRaw) throws DiscoveryPacketDecodeException Decodes the provided MIME encoded discovery packet and returns a discovery data map- Parameters:
discoveryPacketRaw- a Base64 encoded discovery packet- Returns:
- a discovery data map representative of the provided packet
- Throws:
DiscoveryPacketDecodeException- if provided a malformed discovery packet
-
getDiscoveryDataMap
public static Map<String,String> getDiscoveryDataMap(Connection connection) throws DiscoveryPacketDecodeException, ConnectionException Reads the discovery packet from the provided connection and returns a discovery data map- Parameters:
connection- AConnectionto a printer- Returns:
- a discovery data map representative of the provided packet
- Throws:
ConnectionException- if an I/O error occurs.DiscoveryPacketDecodeException- if provided a malformed discovery packet
-