我正在关注Zebra Android Link_OS SDK示例代码,用于通过蓝牙在ZQ510上打印测试标签,但它不会以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();
}
这是打印的结果 . (我运行了两次,这就是为什么有两个测试打印) .
然后我读到了它在不同模式下的情况,因为由于某种原因,Zebra无法检测到自己的专有语言 . 所以我尝试了解设置并查看Android应用 . 再次使用给定的Link-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打印ZPL文本并正确开发Android?我读到了使用一些Zebra Utility应用程序来更改模式,但它仅适用于Windows,并且他们的Android应用程序不起作用 .
无论如何,如果有人在不正确的模式下使用打印机的应用程序,他们将不得不经历所有这些不必要的设置,这对任何人来说都不是直观的 .
感谢您的帮助,感谢任何反馈 .
2 回答
您可以以编程方式将打印模式设置为ZPL,它当前位于
line-mode
.为此:
在您的示例代码中,您正在 Build 蓝牙连接并尝试发送原始数据,请使用Zebra提供的
ZebraPrinter
和BluetoothConnection
类,而不是com.zebra.sdk.printer
名称空间 .我纠正了你的代码,现在应该可以了 .
如果您不想像在 Dayan 答案中那样以编程方式执行此步骤,并且您可以访问Windows计算机(或模拟一台),请安装Zebra Setup Utilities . 然后按照此处的说明https://km.zebra.com/kb/index?page=content&id=SO7296使用该命令将打印模式切换为ZPL