escpos-mc 1.0.3 → 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 +51 -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,7 +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;
|
|
113
|
+
console.log("PRINT_DEBUG", "PRINT_TO_BUFFER", content);
|
|
110
114
|
this.buffer.write(content);
|
|
115
|
+
setTimeout(() => {
|
|
116
|
+
dontCheckStatus = false;
|
|
117
|
+
},50000);
|
|
118
|
+
|
|
111
119
|
return this;
|
|
112
120
|
};
|
|
113
121
|
/**
|
|
@@ -959,48 +967,58 @@ Printer.prototype.getStatuses = function(callback) {
|
|
|
959
967
|
return this;
|
|
960
968
|
}
|
|
961
969
|
|
|
970
|
+
/**
|
|
971
|
+
* Return dontCheckStatus
|
|
972
|
+
* @return {dontCheckStatus}
|
|
973
|
+
*/
|
|
974
|
+
Printer.prototype.getCheckStatus = function () {
|
|
975
|
+
return dontCheckStatus;
|
|
976
|
+
}
|
|
977
|
+
|
|
962
978
|
/**
|
|
963
979
|
* get custom statuses from the printer
|
|
964
980
|
* @param {Function} callback
|
|
965
981
|
* @return {Printer}
|
|
966
982
|
*/
|
|
967
983
|
Printer.prototype.getCustomStatuses = function(callback) {
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
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
|
-
})
|
|
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
|
+
}
|
|
995
991
|
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
992
|
+
if (buffer.length < 2) {
|
|
993
|
+
return;
|
|
994
|
+
}
|
|
999
995
|
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
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
|
+
});
|
|
1003
1016
|
|
|
1017
|
+
ExternalSensorStatus.commands().forEach((c) => {
|
|
1018
|
+
this.adapter.write(c);
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1004
1022
|
return this;
|
|
1005
1023
|
}
|
|
1006
1024
|
|