escpos-mc 1.0.4-debug → 1.0.5
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 +50 -33
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -12,6 +12,8 @@ const Promiseify = require('./promisify');
|
|
|
12
12
|
const statuses = require('./statuses');
|
|
13
13
|
const {PrinterStatus,OfflineCauseStatus,ErrorCauseStatus,RollPaperSensorStatus, ExternalSensorStatus} = statuses;
|
|
14
14
|
|
|
15
|
+
var dontCheckStatus = false;
|
|
16
|
+
|
|
15
17
|
/**
|
|
16
18
|
* [function ESC/POS Printer]
|
|
17
19
|
* @param {[Adapter]} adapter [eg: usb, network, or serialport]
|
|
@@ -107,8 +109,13 @@ Printer.prototype.marginRight = function (size) {
|
|
|
107
109
|
* @return {[Printer]} printer [the escpos printer instance]
|
|
108
110
|
*/
|
|
109
111
|
Printer.prototype.print = function (content) {
|
|
112
|
+
dontCheckStatus = true;
|
|
110
113
|
console.log("PRINT_DEBUG", "PRINT_TO_BUFFER", content);
|
|
111
114
|
this.buffer.write(content);
|
|
115
|
+
setTimeout(() => {
|
|
116
|
+
dontCheckStatus = false;
|
|
117
|
+
},50000);
|
|
118
|
+
|
|
112
119
|
return this;
|
|
113
120
|
};
|
|
114
121
|
/**
|
|
@@ -960,48 +967,58 @@ Printer.prototype.getStatuses = function(callback) {
|
|
|
960
967
|
return this;
|
|
961
968
|
}
|
|
962
969
|
|
|
970
|
+
/**
|
|
971
|
+
* Return dontCheckStatus
|
|
972
|
+
* @return {dontCheckStatus}
|
|
973
|
+
*/
|
|
974
|
+
Printer.prototype.getCheckStatus = function () {
|
|
975
|
+
return dontCheckStatus;
|
|
976
|
+
}
|
|
977
|
+
|
|
963
978
|
/**
|
|
964
979
|
* get custom statuses from the printer
|
|
965
980
|
* @param {Function} callback
|
|
966
981
|
* @return {Printer}
|
|
967
982
|
*/
|
|
968
983
|
Printer.prototype.getCustomStatuses = function(callback) {
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
if (buffer.length < 2) {
|
|
977
|
-
return;
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
let statuses = [];
|
|
981
|
-
|
|
982
|
-
for (let i = 0; i <= buffer.length; i++) {
|
|
983
|
-
let byte = buffer[i];
|
|
984
|
-
switch (i) {
|
|
985
|
-
case 0:
|
|
986
|
-
statuses.push(new RollPaperSensorStatus(byte));
|
|
987
|
-
break;
|
|
988
|
-
case 1:
|
|
989
|
-
statuses.push(new ExternalSensorStatus(byte));
|
|
990
|
-
break;
|
|
991
|
-
}}
|
|
992
|
-
|
|
993
|
-
buffer = [];
|
|
994
|
-
callback(statuses);
|
|
995
|
-
})
|
|
984
|
+
if (!dontCheckStatus) {
|
|
985
|
+
let buffer = [];
|
|
986
|
+
|
|
987
|
+
this.adapter.read(data => {
|
|
988
|
+
for (let i = 0; i < data.byteLength; i++) {
|
|
989
|
+
buffer.push(data.readInt8(i));
|
|
990
|
+
}
|
|
996
991
|
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
992
|
+
if (buffer.length < 2) {
|
|
993
|
+
return;
|
|
994
|
+
}
|
|
1000
995
|
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
996
|
+
let statuses = [];
|
|
997
|
+
|
|
998
|
+
for (let i = 0; i <= buffer.length; i++) {
|
|
999
|
+
let byte = buffer[i];
|
|
1000
|
+
switch (i) {
|
|
1001
|
+
case 0:
|
|
1002
|
+
statuses.push(new RollPaperSensorStatus(byte));
|
|
1003
|
+
break;
|
|
1004
|
+
case 1:
|
|
1005
|
+
statuses.push(new ExternalSensorStatus(byte));
|
|
1006
|
+
break;
|
|
1007
|
+
}}
|
|
1008
|
+
|
|
1009
|
+
buffer = [];
|
|
1010
|
+
callback(statuses);
|
|
1011
|
+
})
|
|
1012
|
+
|
|
1013
|
+
RollPaperSensorStatus.commands().forEach((c) => {
|
|
1014
|
+
this.adapter.write(c);
|
|
1015
|
+
});
|
|
1004
1016
|
|
|
1017
|
+
ExternalSensorStatus.commands().forEach((c) => {
|
|
1018
|
+
this.adapter.write(c);
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1005
1022
|
return this;
|
|
1006
1023
|
}
|
|
1007
1024
|
|