2017-06-15 14 views
5

Podążam za próbnym kodem Zebra Android Link_OS SDK, aby wydrukować etykietę testową na ZQ510 przez Bluetooth, ale nie będzie ona drukowana w formacie ZPL.Drukarka Zebra nie będzie drukować w formacie ZPL

Oto kod biegnę aby wydrukować etykietę:

private void sendZplOverBluetooth(final String theBtMacAddress) { 

    new Thread(new Runnable() { 
     public void run() { 
      try { 
       // Instantiate connection for given Bluetooth® MAC Address. 
       Connection thePrinterConn = new BluetoothConnection(theBtMacAddress); 

       // Initialize 
       Looper.prepare(); 

       // 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()); 

       // Make sure the data got to the printer before closing the connection 
       Thread.sleep(500); 

       // Close the connection to release resources. 
       thePrinterConn.close(); 

       Looper.myLooper().quit(); 
      } catch (Exception e) { 
       // Handle communications error here. 
       e.printStackTrace(); 
      } 
     } 
    }).start(); 
} 

A oto wynik wydruku. (Uruchomiłem go dwukrotnie, dlatego są dwa wydruki testowe).

Example print Potem czytałem o tym, jak to może być w innym trybie, ponieważ z jakiegoś powodu Zebra nie może wykryć własnego zastrzeżonego języka. Próbowałem więc pobrać ustawienia i przejrzeć aplikację na Androida. Ponownie stosując dane Link-OS SDK przykładowy kod:

private static void displaySettings(Connection c) throws ConnectionException, ZebraPrinterLanguageUnknownException, SettingsException, ZebraIllegalArgumentException { 
    ZebraPrinter genericPrinter = ZebraPrinterFactory.getInstance(c); 
    ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.createLinkOsPrinter(genericPrinter); 

    if (linkOsPrinter != null) { 

     System.out.println("Available Settings for myDevice"); 
     Set<String> availableSettings = linkOsPrinter.getAvailableSettings(); 
     for (String setting : availableSettings) { 
      System.out.println(setting + ": Range = (" + linkOsPrinter.getSettingRange(setting) + ")"); 
     } 

     System.out.println("\nCurrent Setting Values for myDevice"); 
     Map<String, String> allSettingValues = linkOsPrinter.getAllSettingValues(); 
     for (String settingName : allSettingValues.keySet()) { 
      System.out.println(settingName + ":" + allSettingValues.get(settingName)); 
     } 

     String darknessSettingId = "print.tone"; 
     String newDarknessValue = "10.0"; 
     if (availableSettings.contains(darknessSettingId) && 
       linkOsPrinter.isSettingValid(darknessSettingId, newDarknessValue) && 
       linkOsPrinter.isSettingReadOnly(darknessSettingId) == false) { 
      linkOsPrinter.setSetting(darknessSettingId, newDarknessValue); 
     } 

     System.out.println("\nNew " + darknessSettingId + " Value = " + linkOsPrinter.getSettingValue(darknessSettingId)); 
    } 
} 

Tym razem dostaję SettingsException z opisem Operation cannot be performed on raw channel with a printer set to line print mode

Jak jestem w stanie drukować tekst ZPL komputera Mac i rozwój Android prawidłowo? Przeczytałem o używaniu aplikacji Zebra Utility do zmiany trybu, ale jest ona dostępna tylko dla systemu Windows, a ich aplikacja na Androida nie działa.

Bez względu na to, czy ktoś miałby używać aplikacji z drukarką w niewłaściwym trybie, musiałby przejść przez wszystkie te niepotrzebne ustawienia, które nie byłyby intuicyjne dla nikogo.

Dzięki za pomoc i doceniamy wszelkie uwagi.

+0

Polecam dodanie mniejszego obrazu problemu, który myślę, że ten jest zbyt duży dla postu. – Dayan

Odpowiedz

4

można programowo ustawić tryb drukowania do ZPL, to obecnie w line-mode.

Aby to zrobić:

BluetoothConnection printerIns= new BluetoothConnection(theBtMacAddress); 
ZebraPrinter zPrinterIns = ZebraPrinterFactory.getInstance(printerIns); 
//Set printer to ZPL mode 
zPrinterIns.sendCommand("! U1 setvar \"device.languages\" \"zpl\"\r\n"); 
//Feed and calibrate to the media 
zPrinterIns.sendCommand("~jc^xa^jus^xz"); 

W przykładzie kodu Jesteś nawiązywania połączenia Bluetooth i próbuje wysłać dane surowe, skorzystać z ZebraPrinter i BluetoothConnection klas przedstawionych przez Zebra zamiast z obszaru nazw com.zebra.sdk.printer.

Poprawiłem twój kod, powinien działać teraz.

new Thread(new Runnable() { 
     public void run() { 
      try { 
       // Instantiate connection for given Bluetooth&reg; MAC Address. 
       BluetoothConnection thePrinterConn = new BluetoothConnection(theBtMacAddress); 

       // Initialize 
       Looper.prepare(); 

       // Open the connection - physical connection is established here. 
       ZebraPrinter zPrinterIns = ZebraPrinterFactory.getInstance(thePrinterConn); 
       zPrinterIns.sendCommand("! U1 setvar \"device.languages\" \"zpl\"\r\n"); 
       zPrinterIns.sendCommand("~jc^xa^jus^xz"); 
       Thread.sleep(500); 

       // Send the data to printer as a byte array. 
       zPrinterIns.sendCommand("^XA^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^XZ"); 

       // Make sure the data got to the printer before closing the connection 
       Thread.sleep(500); 

       // Close the connection to release resources. 
       thePrinterConn.close(); 

       Looper.myLooper().quit(); 
      } catch (Exception e) { 
       // Handle communications error here. 
       e.printStackTrace(); 
      } 
     } 
}).start(); 
+1

Idealne rozwiązanie. Dzięki za pomoc! – jacks205

+0

W każdej chwili! Przeszedłem przez ten sam problem co ty. Dobrej. – Dayan

+0

@Dayan Mam plik .txt, który zawiera kod ZPL, taki jak:^XA ^ FO5050^A0,60,60^FDTest^FS ^ XZ Ale nie mogę wydrukować jego danych wyjściowych na Zebra ZTC drukarka gc420t (EPL). Co powinienem zrobić? – ArgaPK

0

Jeśli nie chcesz wykonać tego kroku programowo, tak jak w odpowiedzi Dayan i masz dostęp do komputera z systemem Windows (lub emulując go), zainstaluj narzędzia instalacji Zebra. Następnie postępując zgodnie z instrukcjami tutaj https://km.zebra.com/kb/index?page=content&id=SO7296 aby przełączyć tryb drukowania do ZPL z poleceniem

! U1 setvar "device.languages" "zpl" 
+0

Uznałem, że jest to najbardziej prawdopodobne rozwiązanie, które muszę zaakceptować. Dziękuję za odpowiedź. – jacks205

Powiązane problemy