My printer does not work receiving esc / p commands

2

I am trying to start working with ESC / P commands with a Brother QL-800 label printer. I have tried the printer software, P-touch Editor 5.0, and if I can print the labels that I want, the printer works fine, but, when it comes to making my own Java code labels, the printer does not work at all, does not respond What can I try now?

This is the code I use. What am I doing wrong?

public class PrintESC_P {   
    public static void main(String[] args) {
        PrintService printService = null;
        String printerName = "Brother QL-800";
        HashAttributeSet attributeSet = new HashAttributeSet();
        attributeSet.add(new PrinterName(printerName, null));
        PrintService[] services = PrintServiceLookup.lookupPrintServices(null, attributeSet);
        if (services.length == 0) {
            throw new IllegalArgumentException("Printer not found.");
        } else if (services.length > 1) {
            System.out.println("Found more than one printer. Only the first printer will be used.");
        }
        printService = services[0];
        System.out.println("Printer found: "+printService.getName());
        try {
            DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;          
            String _ESC_P_Code = "ESC i a 00h\r\n"  +
                    "ESC @\r\n" +
                    "ESC i L 01h\r\n" +
                    "ESC ( C 02h 00h FCh 02h\r\n" +
                    "ESC $ 2Bh 00h\r\n" +
                    "ESC ( V 02h 00h 6Dh 01h\r\n" +
                    "ESC k 0bh\r\n" +
                    "ESC X 00h 64h 00h\r\n" +
                    "PRINTER TEST\r\n" +
                    "ESC i C\r\n" +
                    "FF\r\n";
            SimpleDoc doc = new SimpleDoc(_ESC_P_Code.getBytes(), flavor, null);
            DocPrintJob job = printService.createPrintJob();
            job.print(doc, null);
        } catch (Exception e) {
        e.printStackTrace();
        }
    }
}
    
asked by Giovani Preciado Ortiz 26.07.2017 в 21:17
source

0 answers