Skip to content
Kyle La Barge edited this page Mar 16, 2019 · 3 revisions

Compatibility

  • ✅ 2.1 | ⛔ 2.0 | ⛔ 1.9 | ...

Objective

  • Retrieve status information from printers (.e.g. out of paper, offline, etc.).

Outline

Listen for Printers

Select the printers to get statuses on

qz.printers.startListening("ZDesigner LP2844"); // specific printer

qz.printers.startListening(); // all printers

// using arrow functions
var printerName = "ZDesigner LP2844"; // leave empty for all
qz.printers.startListening(printerName).then(() => console.log("Started listening for", printerName))
   .catch(err => console.error(err));

Setup Callback

Setup a callback to fire when status changes

qz.printers.setPrinterCallbacks(function(evt) {
    console.log(evt.message, evt.severity);
});

// using arrow functions
qz.printers.setPrinterCallbacks(evt => console.log(evt.severity, evt.event))
   .catch(err => console.error(err));

Get status

Get the current status of the printer

qz.printers.getStatus();

Stop listening

Stop listening to all printers

qz.printers.stopListening();

// using arrow functions
qz.printers.stopListening().then(() => console.log("Stopped listening"))
   .catch(err => console.error(err));

Full example

//setup a callback
qz.printers.setPrinterCallbacks(function(evt) {
    console.log(evt.message, evt.severity);
});

function getPrintersStatus () {
   // get the printer, and pass it into the next function
    qz.printers.find("Printer Name").then(function(printer) {
        // listen to the printer
        qz.printers.startListening(printer).then(function(){
            // get the status
            qz.printers.getStatus().then(function() {
            });
        });
    }).catch(function(e) { console.error(e); });
};

image