2017-06-15 24 views
5

Tôi đang theo mã mẫu SDK Android Link_OS SDK của Zebra để in nhãn thử trên ZQ510 qua Bluetooth, nhưng nó sẽ không in ở định dạng ZPL.Máy in Zebra sẽ không in định dạng ZPL

Đây là mã Tôi đang chạy để in các nhãn:

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

Và đây là kết quả của bản in. (Tôi đã chạy nó hai lần, đó là lý do tại sao có hai bản in thử).

Example print Sau đó tôi đọc về cách nó có thể ở chế độ khác vì vì lý do nào đó Zebra không thể phát hiện ngôn ngữ độc quyền của riêng họ. Vì vậy, tôi đã cố gắng để có được các thiết lập và xem thông qua các ứng dụng Android. Một lần nữa bằng cách sử dụng Link-OS SDK mã ví dụ đưa ra:

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)); 
    } 
} 

Lần này, tôi nhận được một SettingsException với mô tả của Operation cannot be performed on raw channel with a printer set to line print mode

Làm thế nào tôi có thể in ZPL văn bản sử dụng máy Mac và phát triển Android một cách chính xác? Tôi đọc về cách sử dụng một số ứng dụng Zebra Utility để thay đổi chế độ, nhưng nó chỉ có sẵn cho Windows và ứng dụng Android của chúng không hoạt động.

Bất kể, nếu ai đó sử dụng ứng dụng với máy in ở chế độ không chính xác, họ sẽ phải trải qua tất cả các thiết lập không cần thiết này sẽ không trực quan cho bất kỳ ai.

Cảm ơn sự giúp đỡ và đánh giá cao mọi phản hồi.

+0

Tôi khuyên bạn nên thêm một hình ảnh nhỏ hơn về vấn đề bạn gặp phải, tôi nghĩ rằng hình ảnh này quá lớn đối với bài đăng. – Dayan

Trả lời

4

Bạn có thể lập trình thiết lập chế độ in để ZPL, đó là hiện tại line-mode.

Để thực hiện:

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"); 

Trong mã ví dụ của bạn, Bạn đang thiết lập một kết nối Bluetooth và cố gắng để gửi dữ liệu thô, tận dụng các ZebraPrinterBluetoothConnection lớp được cung cấp bởi Zebra thay vì từ namespace com.zebra.sdk.printer.

Tôi đã sửa mã của bạn, mã sẽ hoạt động ngay bây giờ.

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

Giải pháp hoàn hảo. Cảm ơn đã giúp đỡ! – jacks205

+0

Bất cứ lúc nào! Tôi đã đi qua cùng một vấn đề như bạn. Có một tốt – Dayan

+0

@Dayan tôi có tệp .txt chứa mã ZPL như:^XA ^ FO50,50^A0,60,60^FDTest^FS ^ XZ Nhưng tôi không thể in đầu ra trên Zebra ZTC máy in gc420t (EPL). Tôi nên làm gì? – ArgaPK

0

Nếu bạn không muốn thực hiện bước này theo chương trình như trong câu trả lời Dayan và bạn có acces với máy Windows (hoặc mô phỏng một), hãy cài đặt Zebra Setup Utilities. Rồi làm theo các hướng dẫn tại đây https://km.zebra.com/kb/index?page=content&id=SO7296 để chuyển sang chế độ in để ZPL với lệnh

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

Tôi đã tìm ra đây là giải pháp có khả năng nhất mà tôi sẽ phải chấp nhận. Cảm ơn câu trả lời. – jacks205

Các vấn đề liên quan