1 Reply Latest reply on Dec 14, 2017 7:09 AM by Daniel Quagliana

    Which SDK to use for Zebra KR203?

    Omar Barrera

      I tried to connect to my printer zebra KR203 for Kiosk, I downloaded link-os-sdk.

       

      I´m programming with JAVA this is my code, I want to get the printers connected:

       

      package logic;

      import com.zebra.sdk.comm.ConnectionException;

      import com.zebra.sdk.printer.discovery.*;

      public class Inicio {

      public static void main(String[] args) throws ConnectionException {

              try {

                  for (DiscoveredPrinterDriver printer : UsbDiscoverer.getZebraDriverPrinters()) {

                      System.out.println(printer);

                  }           

                  for (DiscoveredUsbPrinter usbPrinter : UsbDiscoverer.getZebraUsbPrinters()) {  // My line 10

                      System.out.println(usbPrinter);

                  }

              } catch (ConnectionException e) {

                  System.out.println("Error discovering local printers: " + e.getMessage());

              }

      }

      }

       

      But when I run my app I get this error:

      Exception in thread "main" java.lang.NullPointerException

      at com.zebra.sdk.printer.discovery.UsbDiscoverer.getZebraUsbPrinters(Unknown Source)

      at logic.Inicio.main(Inicio.java:10).

       

      My working directory is "C:\Program Files\Zebra Technologies\link_os_sdk\PC\v2.9.2275\lib"

       

      I do not know if the error is my code or isn´t it possible to connect to my printer for incompatible with the SDK, Can anyone help me please?

       

      On the other hand is possible print with the PrintService of JAVA  code, example:

       

      FileInputStream inputStream = inputStream = new FileInputStream("C:/Temp/ticket.txt");

      DocFlavor docFormat = DocFlavor.INPUT_STREAM.AUTOSENSE;

      Doc document = new SimpleDoc(inputStream, docFormat, null);

      PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();

      PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();

      if (defaultPrintService != null) {

      String print_default = defaultPrintService.getName();

      DocPrintJob printJob = defaultPrintService.createPrintJob();

      try {

        printJob.print(document, attributeSet);

      } catch (Exception er) {

        log.error("Error al imprimir: " + er.getMessage());

      }

      }