我遵循Zebra Android Link_OS SDK示例代碼,通過藍牙在ZQ510上打印測試標籤,但不會以ZPL格式打印。Zebra打印機不會打印ZPL格式
這裏是我運行打印標籤的代碼:
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();
}
這裏是打印的結果。 (我跑了兩次,這就是爲什麼有兩個測試打印)。
然後我讀到它是如何處於不同的模式,因爲由於某種原因,斑馬無法檢測到他們自己的專有語言。所以我試圖獲取設置並查看Android應用。再次使用給定鏈路-OS SDK示例代碼:
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));
}
}
這一次,我得到一個SettingsException
與Operation cannot be performed on raw channel with a printer set to line print mode
我如何能夠使用Mac和正確地開發Android打印ZPL文字說明?我閱讀了關於使用一些Zebra Utility應用程序來改變模式,但它僅適用於Windows,並且他們的Android應用程序不起作用。無論如何,如果有人在不正確的模式下使用打印機的應用程序,他們將不得不經歷所有這些不必要的設置,這對任何人都不是直觀的。
感謝您的幫助和欣賞任何反饋。
我建議您添加一個較小的問題圖片,我認爲這個帖子對於帖子太大了。 – Dayan