Class DriverPrinterConnection

Object
com.zebra.sdk.comm.ConnectionA
com.zebra.sdk.comm.DriverPrinterConnection
All Implemented Interfaces:
Connection, ConnectionWithWriteLogging

public class DriverPrinterConnection extends ConnectionA
Establishes a USB connection to a printer. This class is only supported on Windows PC platforms.

package test.zebra.sdk.comm.examples;
 
 import com.zebra.sdk.comm.Connection;
 import com.zebra.sdk.comm.ConnectionException;
 import com.zebra.sdk.comm.DriverPrinterConnection;
 
 public class DriverPrinterConnectionExample {
 
     public static void main(String[] args) throws Exception {
         DriverPrinterConnectionExample example = new DriverPrinterConnectionExample();
 
         example.sendZplOverUsb("ZDesigner QLn320");
         example.sendCpclOverUsb("ZDesigner QLn320");
     }
 
     private void sendZplOverUsb(String printerName) throws ConnectionException {
         // Instantiate connection for ZPL USB port for given printer name
         Connection thePrinterConn = new DriverPrinterConnection(printerName);
 
         try {
             // Open the connection - physical connection is established here.
             thePrinterConn.open();
 
             // This example prints "This is a ZPL test." near the top of the label.
             String zplData = "^XA^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^XZ";
 
             // Send the data to printer as a byte array.
             thePrinterConn.write(zplData.getBytes());
         } catch (ConnectionException e) {
             // Handle communications error here.
             e.printStackTrace();
         } finally {
             // Close the connection to release resources.
             thePrinterConn.close();
         }
     }
 
     private void sendCpclOverUsb(String printerName) throws ConnectionException {
         // Instantiate connection for CPCL USB port for given printer name
         Connection thePrinterConn = new DriverPrinterConnection(printerName);
 
         try {
             // Open the connection - physical connection is established here.
             thePrinterConn.open();
 
             // This example prints "This is a CPCL test." near the top of the label.
             String cpclData = "! 0 200 200 210 1\r\n" + "TEXT 4 0 30 40 This is a CPCL test.\r\n" + "FORM\r\n" + "PRINT\r\n";
 
             // Send the data to printer as a byte array.
             thePrinterConn.write(cpclData.getBytes());
         } catch (ConnectionException e) {
             // Handle communications error here.
             e.printStackTrace();
         } finally {
             // Close the connection to release resources.
             thePrinterConn.close();
         }
     }
 }