-
-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Printer stop before excute cut command #227
Comments
Try something like this?
|
@nivle do you mean i should wait after every send data via socket because i have develop services and mobile apps(android and IOS) use it to get commands and send it chunk by chunk(height 256px) via socket |
@kero43 do you have a short example of your code, I myself had some issue with the regular cutting method, causing premature cuts, so I started using |
@nivle i will ask apps developers to wait 100 ms before send next commands and share the result |
@kero43 you definitely need to provide a minimal sample that will reproduce the issue if you want more detailed help. In general though, the base printer's write methods are synchronous but they enqueue in a queue, they do not immediately write to the printer. The implementation will flush bytes to the printer every few milliseconds, and as soon as the printer accepts the bytes, it will send the next set. For Epson printers, this works fine, because they hold the line open and don't accept the bytes if their buffer is full. However, the issue is when you get into 3rd party printers, they follow the ESCPOS protocol, but that protocol doesn't specify some implementation details like this, and it'll cause issues. It's also possible that your printer doesn't fully support images, and you're trying to send images. In that case, you can use the legacy image mode. Sleeping to write bytes slower is the type of solution that will probably work most of the time, but it might be flaky sometimes, so if you want to look into this issue in more detail, give us an example that reliably reproduces the issue and I'll help where I can. I can run it against my epson and non-epson printers and see how they behave. |
hello @lukevp |
Yeah, so the problem is likely a buffer overflow on the printer side, not on the computer hosting the program. EPSON printers are set up so they don't ACK a write unless their buffer has space, so the flush method will naturally wait until the buffer is empty, but a lot of 3rd party printers don't behave correctly in this situation. Any time you see garbage data, what's typically happening is one of these 2 things:
The reason #2 results in garbage data is because your printer starts interpreting the byte stream with missing ESC commands, so it starts interpreting images as text, etc, because it misses the ESC sequences that tell the printer to switch into image / barcode / QR code printing mode. I would first double-check that you're not running into issue #1 by switching to legacy image mode if possible. If that doesn't help, then I would try and definitively determine if #2 is your issue. One way you could verify if this is the issue is doing the following:
If this solves your garbage data, then the problem is a buffer overflow on the printer side. 1000 bytes per second is a super slow data rate for these printers, so if you're still seeing garbage data, then something else is wrong with your ESC commands. Testing by putting a sleep between entire requests isn't sufficient for testing this, because the problem may be the underlying printer hardware, so you need to throttle the actual byte stream you're sending to the printer. Let me know what the outcome is of these tests and I'll see if I can point you to the next thing to try. |
@kero43 How big are your image chunks?(in width and height px) from my experience, my printer did similar things as to what you're describing when my image width was greater than 512px(which is 2x 256), then my printer started printing the image slower, in chunks, and sometimes failed and printed weird stuff(prob cus of buffer issues). I fixed that issue as described here. |
Hello
My problem is that sometimes the printer stops in the middle or the end of the paper before executing the cut command, and then it print garbage data if print anything. Is there a way to reset or clear the printer buffer before print new order, or a solution to the problem of stopping before the cut order that mentioned before?
printer stop here
garbage data next time
The text was updated successfully, but these errors were encountered: