Zebra printer will not print ZPL format

I follow the Zebra Android Link_OS SDK sample code for printing a test mark on the ZQ510 via Bluetooth, but it will not print in ZPL format.

Here is the code that I run to print the label:

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

And here is the print result. (I ran it twice, so there are two test prints).

Print example Then I read about how it could be in a different mode, because for some reason Zebra cannot detect its own corporate language. So I tried to get the settings and see the Android application. Using this example SDK Link-OS code again:

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

This time I get a SettingsException with the description Operation cannot be performed on raw channel with a printer set to line print mode

How can I print ZPL text using Mac and develop Android correctly? I read about using some Zebra Utility applications to change the mode, but it is available only for Windows and their Android application does not work.

Regardless, if someone had to use the application with the printer in the wrong mode, they would have to go through all this unnecessary setup, which would not be intuitive for anyone.

Thanks for the help and appreciate any feedback.

+5
source share
2 answers

You can programmatically set the print mode to ZPL, currently it is in line-mode .

For this:

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

In your code example, you are establishing a Bluetooth connection and trying to send raw data, use the ZebraPrinter and BluetoothConnection classes provided by Zebra instead from the com.zebra.sdk.printer namespace.

I adjusted your code, now it should work.

  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(); 
+4
source

If you do not want to perform this step programmatically, as in Dayan's answer, and you have access to a Windows machine (or emulation), install Zebra Settings Utilities. Then following the instructions here https://km.zebra.com/kb/index?page=content&id=SO7296 to switch the print mode to ZPL using the command

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

Source: https://habr.com/ru/post/1268889/


All Articles