knyga / html2thermal

JavaScript library to translate subset of HTML into commands which can be executed on the thermal printer.
MIT License
43 stars 2 forks source link

Multiple prints #6

Closed samdigitalpanda closed 1 year ago

samdigitalpanda commented 1 year ago

Unsure if this is an issue with this repo or the underlying node-thermal printer. I have an Epson printer connected over IP. I seem to get an irregular number of copies of each print each time. Seems to always be between 1 and 3 copies.

knyga commented 1 year ago

It is weird. And do you have this issue via ethernet or USB interface as well? At the moment, I have an ethernet interface setup, and it works. We use the ethernet interface in production on a quite big scale.

I would suggest you clone the repo and debug the execute.js file. It is the only place where the converter is connected to the external repo. Check what signals it sends.

samdigitalpanda commented 1 year ago

Sorry yes by 'via IP' I meant connected over ethernet (via a network switch). I'll try via USB and see if the issue persists.

samdigitalpanda commented 1 year ago

So it seems that the issue is being caused not by either library or the connection method, but something to do with my implementation. I have an express server which prints restaurant orders to the thermal printer when an endpoint is hit. On each subsequent endpoint hit it increments the number of prints I get (1 -> 2 -> 3 etc). Bizarre. Also tried with fastify to check it wasn't just express and the same things happens

samdigitalpanda commented 1 year ago

Found the issue! The print buffer was getting added to each time. Added printer.clear() from the underlying nodethermalprinter library to each route and now just get 1 print each time as expected. Hope this helps someone in the future.