Inject the printer uri via the msg.topic
from your calling node (e.g. Timestamp node).
Printer uri should look like this: ipp://mycupsserver:632/printers/Brother_HL2030
Add a function to your flow and add the module @sealsystems/ipp
on the Setup
tab.
Then add the following code to the On Message
tab.
const printer = sealsystemsIpp.Printer(msg.topic);
const ippmsg = {
'operation-attributes-tag': {
'attributes-charset': 'utf-8',
'attributes-natural-language': 'en',
'printer-uri': msg.topic,
'which-jobs': 'pending',
'requested-attributes': [
'job-id',
'job-state',
'job-name',
]
}
}
printer.execute('Get-Jobs', ippmsg, function (err, res) {
msg.topic = 'pending-jobs';
msg.payload = 0;
if(err) {
msg.topic = 'error';
msg.payload = err;
} else {
if (Array.isArray(res['job-attributes-tag'])) {
msg.payload = res['job-attributes-tag'].length;
} else if (res['job-attributes-tag']) {
// single job is returned as object
msg.payload = 1;
}
}
node.send(msg);
});
return;
Payload contains the pending jobs count:
{ _msgid: "c00f96ee4ec4408c", payload: 1, topic: "pending-jobs" }
This can be modified to return any information about your printer and print jobs.
E.g. which-jobs
can be set to:
aborted
all
canceled
pending
pending-held
processing
processing-stopped
More examples for @sealsystems/ipp
can be found here:
https://github.com/sealsystems/node-ipp/tree/master/examples
https://github.com/sealsystems/node-ipp/blob/master/examples/Get-Jobs.js
https://ftp.pwg.org/pub/pwg/candidates/cs-ippjobext21-20230210-5100.7.pdf page 67
Flow: