escpos-mc 1.0.0 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +54 -2
- package/package.json +1 -1
- package/statuses.js +98 -0
package/index.js
CHANGED
|
@@ -10,7 +10,7 @@ const utils = require('./utils');
|
|
|
10
10
|
const _ = require('./commands');
|
|
11
11
|
const Promiseify = require('./promisify');
|
|
12
12
|
const statuses = require('./statuses');
|
|
13
|
-
const {PrinterStatus,OfflineCauseStatus,ErrorCauseStatus,RollPaperSensorStatus} = statuses;
|
|
13
|
+
const {PrinterStatus,OfflineCauseStatus,ErrorCauseStatus,RollPaperSensorStatus, ExternalSensorStatus} = statuses;
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* [function ESC/POS Printer]
|
|
@@ -900,6 +900,7 @@ Printer.prototype.raw = function raw(data) {
|
|
|
900
900
|
*/
|
|
901
901
|
Printer.prototype.getStatuses = function(callback) {
|
|
902
902
|
let buffer = [];
|
|
903
|
+
|
|
903
904
|
this.adapter.read(data => {
|
|
904
905
|
for (let i = 0; i < data.byteLength; i++) {
|
|
905
906
|
buffer.push(data.readInt8(i));
|
|
@@ -910,7 +911,7 @@ Printer.prototype.getStatuses = function(callback) {
|
|
|
910
911
|
}
|
|
911
912
|
|
|
912
913
|
let statuses = [];
|
|
913
|
-
for (let i = 0; i
|
|
914
|
+
for (let i = 0; i <= buffer.length; i++) {
|
|
914
915
|
let byte = buffer[i];
|
|
915
916
|
switch (i) {
|
|
916
917
|
case 0:
|
|
@@ -925,6 +926,9 @@ Printer.prototype.getStatuses = function(callback) {
|
|
|
925
926
|
case 3 :
|
|
926
927
|
statuses.push(new ErrorCauseStatus(byte));
|
|
927
928
|
break;
|
|
929
|
+
case 4 :
|
|
930
|
+
statuses.push(new ExternalSensorStatus(byte));
|
|
931
|
+
break;
|
|
928
932
|
}
|
|
929
933
|
}
|
|
930
934
|
|
|
@@ -948,9 +952,57 @@ Printer.prototype.getStatuses = function(callback) {
|
|
|
948
952
|
this.adapter.write(c);
|
|
949
953
|
});
|
|
950
954
|
|
|
955
|
+
ExternalSensorStatus.commands().forEach((c) => {
|
|
956
|
+
this.adapter.write(c);
|
|
957
|
+
});
|
|
958
|
+
|
|
951
959
|
return this;
|
|
952
960
|
}
|
|
953
961
|
|
|
962
|
+
/**
|
|
963
|
+
* get custom statuses from the printer
|
|
964
|
+
* @param {Function} callback
|
|
965
|
+
* @return {Printer}
|
|
966
|
+
*/
|
|
967
|
+
Printer.prototype.getCustomStatuses = function(callback) {
|
|
968
|
+
let buffer = [];
|
|
969
|
+
|
|
970
|
+
this.adapter.read(data => {
|
|
971
|
+
for (let i = 0; i < data.byteLength; i++) {
|
|
972
|
+
buffer.push(data.readInt8(i));
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
if (buffer.length < 2) {
|
|
976
|
+
return;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
let statuses = [];
|
|
980
|
+
|
|
981
|
+
for (let i = 0; i <= buffer.length; i++) {
|
|
982
|
+
let byte = buffer[i];
|
|
983
|
+
switch (i) {
|
|
984
|
+
case 0:
|
|
985
|
+
statuses.push(new RollPaperSensorStatus(byte));
|
|
986
|
+
break;
|
|
987
|
+
case 1:
|
|
988
|
+
statuses.push(new ExternalSensorStatus(byte));
|
|
989
|
+
break;
|
|
990
|
+
}}
|
|
991
|
+
|
|
992
|
+
buffer = [];
|
|
993
|
+
callback(statuses);
|
|
994
|
+
})
|
|
995
|
+
|
|
996
|
+
RollPaperSensorStatus.commands().forEach((c) => {
|
|
997
|
+
this.adapter.write(c);
|
|
998
|
+
});
|
|
999
|
+
|
|
1000
|
+
ExternalSensorStatus.commands().forEach((c) => {
|
|
1001
|
+
this.adapter.write(c);
|
|
1002
|
+
});
|
|
1003
|
+
|
|
1004
|
+
return this;
|
|
1005
|
+
}
|
|
954
1006
|
|
|
955
1007
|
/**
|
|
956
1008
|
* Printer Supports
|
package/package.json
CHANGED
package/statuses.js
CHANGED
|
@@ -307,9 +307,107 @@ class RollPaperSensorStatus extends DeviceStatus {
|
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
+
class ExternalSensorStatus extends DeviceStatus {
|
|
311
|
+
static commands() {
|
|
312
|
+
return [_.DLE, _.EOT, String.fromCharCode(5)];
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
static getClassName() {
|
|
316
|
+
return 'ExternalSensorStatus';
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
toJSON() {
|
|
320
|
+
let result = super.toJSON();
|
|
321
|
+
|
|
322
|
+
for (let i = 0; i < 8; i++) {
|
|
323
|
+
let label = '';
|
|
324
|
+
let status = 'ok';
|
|
325
|
+
switch (i) {
|
|
326
|
+
case 0:
|
|
327
|
+
if (this.bitsAsc[i] === 1) {
|
|
328
|
+
status = 'error';
|
|
329
|
+
label = 'Paper blocked';
|
|
330
|
+
} else {
|
|
331
|
+
label = 'Paper blocking detection sensor is normal';
|
|
332
|
+
}
|
|
333
|
+
break;
|
|
334
|
+
// case 1:
|
|
335
|
+
// if (this.bitsAsc[i] === 1) {
|
|
336
|
+
// status = 'error';
|
|
337
|
+
// label = 'Happened retracting ticket or clear data';
|
|
338
|
+
// } else {
|
|
339
|
+
// label = 'No operation';
|
|
340
|
+
// }
|
|
341
|
+
// break;
|
|
342
|
+
// case 2:
|
|
343
|
+
// if (this.bitsAsc[i] === 1) {
|
|
344
|
+
// status = 'error';
|
|
345
|
+
// label = 'Ticket held on printer bezel';
|
|
346
|
+
// } else {
|
|
347
|
+
// label = 'No ticket held on printer bezel or this function invalid';
|
|
348
|
+
// }
|
|
349
|
+
// break;
|
|
350
|
+
case 3:
|
|
351
|
+
if (this.bitsAsc[i] === 1) {
|
|
352
|
+
status = 'error';
|
|
353
|
+
label = 'Paper jam';
|
|
354
|
+
} else {
|
|
355
|
+
label = 'External sensor is normal';
|
|
356
|
+
}
|
|
357
|
+
break;
|
|
358
|
+
// case 4:
|
|
359
|
+
// if (this.bitsAsc[i] === 1) {
|
|
360
|
+
// status = 'error';
|
|
361
|
+
// label = 'No used. Fixed to On';
|
|
362
|
+
// } else {
|
|
363
|
+
// label = 'No error';
|
|
364
|
+
// }
|
|
365
|
+
// break;
|
|
366
|
+
// case 5:
|
|
367
|
+
// if (this.bitsAsc[i] === 1) {
|
|
368
|
+
// status = 'error';
|
|
369
|
+
// label = 'Blackmark sensor error';
|
|
370
|
+
// } else {
|
|
371
|
+
// label = 'Blackmark sensor is normal';
|
|
372
|
+
// }
|
|
373
|
+
// break;
|
|
374
|
+
// case 6:
|
|
375
|
+
// if (this.bitsAsc[i] === 1) {
|
|
376
|
+
// status = 'error';
|
|
377
|
+
// label = 'Paper error 6';
|
|
378
|
+
// } else {
|
|
379
|
+
// label = 'No error';
|
|
380
|
+
// }
|
|
381
|
+
// break;
|
|
382
|
+
// case 7:
|
|
383
|
+
// if (this.bitsAsc[i] === 1) {
|
|
384
|
+
// status = 'error';
|
|
385
|
+
// label = 'No used. Fixed to Off';
|
|
386
|
+
// } else {
|
|
387
|
+
// label = 'No error';
|
|
388
|
+
// }
|
|
389
|
+
// break;
|
|
390
|
+
default:
|
|
391
|
+
label = 'Fixed';
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
result.statuses.push({
|
|
396
|
+
bit: i,
|
|
397
|
+
value: this.bitsAsc[i],
|
|
398
|
+
label: label,
|
|
399
|
+
status: status
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return result;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
310
407
|
module.exports = {
|
|
311
408
|
PrinterStatus: PrinterStatus,
|
|
312
409
|
OfflineCauseStatus: OfflineCauseStatus,
|
|
313
410
|
ErrorCauseStatus: ErrorCauseStatus,
|
|
314
411
|
RollPaperSensorStatus: RollPaperSensorStatus,
|
|
412
|
+
ExternalSensorStatus: ExternalSensorStatus
|
|
315
413
|
};
|