get status printer ZTC ZD500R-203dpi ZPL java

g gennaro ca 3 years 7 months ago
47 0 0

good morning, now i am connected in lan with rj45 ot printer zebra r500 and i have the ipaddress of the printer.

i have installed the printer and i have the driver, the printer is connected and available but in the control panel, in the section printers, it is incative, why?

i need the status of the printer so i could print something, i have tried some blocks. thank you in advance for your help.

1)this block gives me all the printer names, but i don't need that
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
for (int i = 0; i services.length; i++) {
    System.out.println(services[i].getName());
}

2)with this block i can have more info about a fixed printer, but is not what i need
color-supported: not-supported
printer-is-accepting-jobs: accepting-jobs
printer-name: "PRINTER NAME"
queued-job-count: 0

for (int i = 0; i services.length; i++) {
    if(services[i].getName().equals("PRINTER NAME")) {
    att = services[i].getAttributes();
               for (Attribute a : att.toArray()) {
         System.out.println(a.getName() + ": " + att.get(a.getClass()).toString();
    }

3)this block print the name and printerstate 0 and printerstate 3, but these values should change if i turn off the printer or i remove it from the lan, but are always the same

ProcessBuilder builder = new ProcessBuilder("powershell.exe", "get-wmiobject -class win32_printer | Select-Object Name, PrinterState, PrinterStatus | where {$_.Name -eq '"+services[i].getName()+"'}");

        String fullStatus = null;
        Process reg;
        builder.redirectErrorStream(true);
        try {
            reg = builder.start();
            InputStream inputStream = reg.getInputStream();
           
                      //this is a method to convert from inputstream to string
            fullStatus = getStringFromInputStream(reg.getInputStream());
            reg.destroy();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
}

CONTACT
Can’t find what you’re looking for?