Print only work the first time and I need to restart the bluetooth to print again.
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start with the printerService.js example and trace Bluetooth.findPrinters, device.open, and the qrimage callback across repeated print requests. Reproduce the listener warning and one-print-only behavior, then verify that repeated prints complete without restarting Bluetooth or accumulating listeners.
Written by the indexing model from the issue text.
Description
I want to create a REST service with Node.js using Express that prints tickets to ESC/POS bluetooth printer.
The actual result my service print only the first time and I need to restart the bluetooth to print again.
I tried update my service to only look for the printer and return it but it only works a couple of times. I received this error in the console:
(node:16608) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [Device]. Use emitter.setMaxListeners() to increase limit (Use node --trace-warnings ... to show where the warning was created)
The expected result print data multiple times
Here is my printerService.js :
const { Printer } = require("escpos");
const Bluetooth = require("escpos-bluetooth");
const foundPrinter = async (name, address, channel, printData) => {
const PRINTER_NAME = name;
const PRINTER_ADDRESS = address;
const PRINTER_CHANNEL = channel;
const preferredPrinterAddress = "(" + PRINTER_ADDRESS + ")" + PRINTER_NAME;
const availablePrinters = await Bluetooth.findPrinters();
console.log("availablePrinters", availablePrinters);
const btPrinter =
availablePrinters && availablePrinters.length > 0
? availablePrinters.filter(
(p) =>
p &&
p.name === PRINTER_NAME &&
p.address === preferredPrinterAddress
)[0]
: false;
console.log("btPrinter", btPrinter);
return new Promise((resolve, reject) => {
if (btPrinter) {
if (!printData) {
resolve({ printer: btPrinter });
} else {
const device = new Bluetooth(PRINTER_ADDRESS, PRINTER_CHANNEL);
const printer = new Printer(device);
device.open(function (deviceError) {
if (!deviceError) {
printer
.font("a")
.align("ct")
.style("bu")
.size(1, 1)
.text("Text1")
.text("Text2")
.barcode("1234567", "EAN8")
.qrimage("qrImage", function (qrImageError) {
if (!qrImageError) {
this.cut();
this.close();
} else {
reject({
name: qrImageError.name,
message: qrImageError.message,
});
}
});
resolve({ printer: btPrinter });
} else {
reject({ name: deviceError.name, message: deviceError.message });
}
});
}
} else {
reject({
errorType: "ERROR_PRINTER_NOT_FOUND",
errorName: "PRINTER_NOT_FOUND",
message: "printer not found",
fullMessage:
"printer not found, availablePrinters: " +
availablePrinters.toString(),
});
}
});
};
- Dominant language
- TypeScript
- Stars
- 1.6k
- Forks
- 443
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from lsongdev/node-escpos
-
[BUG]:Openbug
Difficulty 4/5 3-5 days Newbie friendliness 15/100
lsongdev/node-escpos#447 ·
-
[BUG]: AJCBOSEOpenbug
Difficulty 5/5 Over a week Newbie friendliness 10/100
lsongdev/node-escpos#446 ·
-
Capt BilalOpen
Difficulty 5/5 Over a week Newbie friendliness 1/100
lsongdev/node-escpos#443 ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 35/100
lsongdev/node-escpos#442 · 2 reactions ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 38/100
lsongdev/node-escpos#441 · 5 comments · 1 reaction ·
All issues in lsongdev/node-escpos
Similar issues
-
bug via-triage
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
pingdotgg/t3code#15221 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
521xueweihan/HelloGitHub#3847 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
MystenLabs/MemWal#1085 · 1 comment ·
Maintainers usually reply within 1 day
-
needs-triage
Difficulty 1/5 Under an hour Newbie friendliness 92/100
PhyberApex/kuroshiro#1187 ·
Maintainers usually reply within 1 day