ESC/P Set Absolute Horizontal Print Position

跟風遠走 提交于 2019-12-01 12:46:05
Wu Fu Chi

ESC/P Set Absolute Horizontal Print Position

From the given 3rd Party Java code on ESCPrinter.java, the approach to send ESC/P control code to the printer port is waiting for disaster. For your case, when the value is larger than 7-bit data (127 / 0x7F).

Given the command to set absolute horizontal position:

ESC $ nL nH
nL value: 0 <= nL < 256

When nL value is over 127, the value is converted incorrectly and sent to the printer port. The incorrect conversion is caused by PrintStream() class which will call the default charset encoding based on your system locale (internally create java.io.Writer() class). That's why the value nL is never correctly send to printer port.

To fix this problem, you must never try to use String() class or any other charset encoding related class to write the control code (e.g. .toString(), .toByteArray(charset), Writer).

You can try UTF-8 encoding for PrintStream(), to see if it fixes the bug or not.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!