ShellPrinterControl.js
Summary
Printer control using a shell command
function ShellPrinterControl(param) {
this.param = param;
this.runtime = java.lang.Runtime.getRuntime();
}
exports.ShellPrinterControl = ShellPrinterControl;
ShellPrinterControl.type = "printer";
ShellPrinterControl.prototype.configure = function() {
}
ShellPrinterControl.prototype.exec = function(f) {
GPSystem.trace("Call " + f.cmd);
var process = this.runtime.exec(f.cmd);
var reader = new java.io.BufferedReader(new java.io.InputStreamReader(process.getInputStream()));
var rc = process.waitFor();
if (rc != 0) {
GPSystem.trace("Exit code " + rc);
return false;
}
var line = reader.readLine();
GPSystem.trace(line);
return line.match(f.ok) != null;
}
ShellPrinterControl.prototype.feedCard = function() {
return this.exec(this.param.feed);
}
ShellPrinterControl.prototype.ejectCard = function() {
return this.exec(this.param.eject);
}
ShellPrinterControl.prototype.rejectCard = function() {
return this.exec(this.param.reject);
}
ShellPrinterControl.test = function() {
var param = {
feed: {
cmd: [ "evocom", "-pEvolis Quantum2", "Sis;" ],
ok: /^OK$/
},
eject: {
cmd: [ "evocom", "-pEvolis Quantum2", "Se;" ],
ok: /^OK$/
},
reject: {
cmd: [ "evocom", "-pEvolis Quantum2", "Ser;" ],
ok: /^OK$/
}
};
var s = new ShellPrinterControl(param);
print(s.feedCard());
print(s.ejectCard());
print(s.rejectCard());
}
Documentation generated by
JSDoc on Thu Apr 3 11:32:15 2025