public class ConnectionBuilder
extends Object
The description string may be of the explicit forms: "TCP:192.168.1.4:6101" -- creates a TCP connection to the device with IP address 192.168.1.4 on port 6101 "TCP:192.168.1.4" -- creates a TCP connection to the device with IP address 192.168.1.4 on default port 9100 "TCP:dnsName:6101" -- creates a TCP connection to the device with 'dnsName' on port 6101 "TCP:dnsName" -- creates a TCP connection to the device with 'dnsName' on default port 9100 "TCP_MULTI:192.168.1.4" -- creates a Multichannel TCP connection to the device with '192.168.1.4' using the default ports for both the printing channel (9100) and the status channel(9200) "TCP_MULTI:192.168.1.4:1234" -- creates a Multichannel TCP connection to the device with '192.168.1.4' using the given port for the printing channel (1234) and the default port for the status channel(9200) "TCP_MULTI:192.168.1.4:1234:5678" -- creates a Multichannel TCP connection to the device with '192.168.1.4' using the given ports for the printing channel (1234) and the status channel(5678) "TCP_MULTI:dnsName:1234:5678" -- creates a Multichannel TCP connection to the device with 'dnsName' using the given ports for the printing channel (1234) and the status channel(5678) "TCP_STATUS:192.168.1.4:1234" -- creates a TCP status only connection to the device with IP address 192.168.1.4 on port 1234 "TCP_STATUS:192.168.1.4" -- creates a TCP status only connection to the device with IP address 192.168.1.4 on the default status port 9200 "REMOTE:serialNumber" -- creates a remote connection to the device with 'serialNumber' which is accessible via the RMI Server running on the default RMI port (11995). The printer must be registered for use with a Zebra Weblink server. "REMOTE:serialNumber:rmiPort" -- creates a remote connection to the device with 'serialNumber' which is accessible via the RMI Server running on port 'rmiPort'. The printer must be registered for use with a Zebra Weblink server. "REMOTE_MULTI:serialNumber:rmiPort" -- creates a multichannel remote connection to the device with 'serialNumber' which is accessible via the RMI Server running on port 'rmiPort'. The printer must be registered for use with a Zebra Weblink server. "REMOTE_STATUS:serialNumber:rmiPort" -- creates a status only remote connection to the device with 'serialNumber' which is accessible via the RMI Server running on port 'rmiPort'. The printer must be registered for use with a Zebra Weblink server. "USB:deviceName" -- creates a USB connection (through the ZebraDesigner driver) to the device with printer name 'deviceName' "USB_DIRECT:deviceName" -- creates a USB connection to the device with 'device.unique_id' or 'device.product_name' equal to 'deviceName'Generic text may also be used to attempt to specify a device. For example a description string of "genericText" will attempt to connect to a device using the following priority:
package test.zebra.sdk.comm.examples;
 
 import com.zebra.sdk.comm.*;
 import com.zebra.sdk.common.card.containers.*;
 import com.zebra.sdk.common.card.exceptions.ZebraCardException;
 import com.zebra.sdk.common.card.printer.*;
 import com.zebra.sdk.common.card.printer.discovery.ZebraCardPrinterFilter;
 import com.zebra.sdk.printer.discovery.*;
 import com.zebra.sdk.settings.SettingsException;
 
 public class ConnectionBuilderExample {
 
 	public static void main(String[] args) throws Exception {
 		new ConnectionBuilderExample().usbDriverlessTest();
 		new ConnectionBuilderExample().getPrinterStatusOverTcp("1.2.3.4");
 		new ConnectionBuilderExample().getPrinterInfoOverUsb("\\\\?\\usb#vid_0a5f&pid_0050#z3j123900470#...");
 	}
 
 	private void usbDriverlessTest() throws ConnectionException, ZebraCardException, SettingsException {
 		System.out.println("Discovered USB printer list:\r\n");
 		for (DiscoveredUsbPrinter printer : UsbDiscoverer.getZebraUsbPrinters(new ZebraCardPrinterFilter())) {
 			System.out.println(printer);
 		}
 		System.out.println("End USB printer list\r\n");
 
 		ZebraCardPrinter zebraCardPrinter = null;
 		Connection connection = ConnectionBuilder.build("\\\\?\\usb#vid_0a5f&pid_0050#z3j123900470#...");
 		try {
 			connection.open();
 			zebraCardPrinter = ZebraCardPrinterFactory.getInstance(connection);
 
 			CardCountInfo cardCountInfo = zebraCardPrinter.getCardCount();
 			System.out.format("Total cards printed: %d%n%n", cardCountInfo.totalCards);
 		} finally {
 			zebraCardPrinter.destroy();
 			connection.close();
 		}
 	}
 
 	private void getPrinterStatusOverTcp(String theIpAddress) throws ConnectionException, SettingsException, ZebraCardException {
 		Connection connection = ConnectionBuilder.build("TCP:" + theIpAddress + ":9100");
 		ZebraCardPrinter zebraCardPrinter = null;
 
 		try {
 			connection.open();
 			zebraCardPrinter = ZebraCardPrinterFactory.getInstance(connection);
 
 			PrinterStatusInfo printerStatusInfo = zebraCardPrinter.getPrinterStatus();
 			System.out.format("Status: %s%n", printerStatusInfo.status);
 			System.out.format("Alarm: %s (%s)%n", printerStatusInfo.alarmInfo.value, printerStatusInfo.alarmInfo.description);
 			System.out.format("Error: %s (%s)%n", printerStatusInfo.errorInfo.value, printerStatusInfo.errorInfo.description);
 			System.out.format("Total jobs: %s%n", printerStatusInfo.jobsTotal);
 			System.out.format("Pending jobs: %s%n", printerStatusInfo.jobsPending);
 			System.out.format("Active jobs: %s%n", printerStatusInfo.jobsActive);
 			System.out.format("Completed jobs: %s%n%n", printerStatusInfo.jobsComplete);
 		} catch (ConnectionException e) {
 			// Handle communications error here.
 			e.printStackTrace();
 		} finally {
 			// Release resources and close the connection
 			zebraCardPrinter.destroy();
 			connection.close();
 		}
 	}
 
 	private void getPrinterInfoOverUsb(String symbolicName) throws ConnectionException, SettingsException, ZebraCardException {
 		Connection connection = ConnectionBuilder.build("USB_DIRECT:" + symbolicName);
 		ZebraCardPrinter zebraCardPrinter = null;
 
 		try {
 			connection.open();
 			zebraCardPrinter = ZebraCardPrinterFactory.getInstance(connection);
 
 			PrinterInfo printerInfo = zebraCardPrinter.getPrinterInformation();
 			System.out.format("Vendor: %s%n", printerInfo.vendor);
 			System.out.format("Model: %s%n", printerInfo.model);
 			System.out.format("SerialNumber: %s%n", printerInfo.serialNumber);
 			System.out.format("OEM Code: %s%n", printerInfo.oemCode);
 			System.out.format("Firmware Version: %s%n%n", printerInfo.firmwareVersion);
 		} catch (ConnectionException e) {
 			// Handle communications error here.
 			e.printStackTrace();
 		} finally {
 			// Release resources and close the connection
 			zebraCardPrinter.destroy();
 			connection.close();
 		}
 	}
 }
 
| Modifier and Type | Method and Description | 
|---|---|
| static void | addConnectionType(Class<? extends Connection> c)Add a connection type to the ConnectionBuilder | 
| static Connection | build(String descriptionString)Creates a Connection type based on the contents of  descriptionString. | 
public static void addConnectionType(Class<? extends Connection> c)
c - connection classpublic static Connection build(String descriptionString) throws ConnectionException
descriptionString. descriptionString - The format of the input string is: [prefix:] address [: port_number(s)]
 ConnectionException - if a connection could not be established for the given descriptionString.
				© 2016 ZIH Corp. All Rights Reserved.