ESC/POS命令仅打印内容

huangapple go评论64阅读模式
英文:

ESC/POS commands for QR prints only the content

问题

以下是您的代码的翻译部分:

String content = "Hello !!";
int store_len = content.length() + 3;
byte store_pL = (byte) (store_len % 256);
byte store_pH = (byte) (store_len / 256);

byte ESC = 0x1b;
byte[] INIT = new byte[]{ESC, '@'};
byte[] CUT = new byte[]{0x0c};
byte[] FUNC_165 = new byte[]{Commands.GS, 0x28, 0x6b, 0x04, 0x00, 0x31, 0x41, 0x51, 0x00};
byte[] FUNC_167 = new byte[]{Commands.GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x43, 0x64};
byte[] FUNC_169 = new byte[]{Commands.GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x45, 0x48};
byte[] FUNC_180 = new byte[]{Commands.GS, 0x28, 0x6b, store_pL, store_pH, 0x31, 0x50, 0x30};
byte[] FUNC_181 = new byte[]{Commands.GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x51, 0x48};
byte[] FUNC_182 = new byte[]{Commands.GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x52, 0x48};

ByteArrayOutputStream writer = new ByteArrayOutputStream();

writer.write(INIT);
writer.write(FUNC_165);
writer.write(FUNC_167);
writer.write(FUNC_169);
writer.write(FUNC_180);
writer.write(content.getBytes());
writer.write(FUNC_181);
writer.write(FUNC_182);
writer.write(CUT);
writer.close();

输出为 QHello !!

请问有什么可以帮助您的吗?

英文:

I'm trying to print a QR code on a Custom VKP printer. The printer supports QR codes. I send ESC/POS commands to it, but all that is printed is the text and not the QR code. The following is my code in Java:

    String content = "Hello !!";
int store_len = content.length() + 3;
byte store_pL = (byte) (store_len % 256);
byte store_pH = (byte) (store_len / 256);
byte ESC = 0x1b;
byte[] INIT = new byte[]{ESC, '@'};
byte[] CUT = new byte[]{0x0c};
byte[] FUNC_165 = new byte[]{Commands.GS, 0x28, 0x6b, 0x04, 0x00, 0x31, 0x41, 0x51, 0x00};
byte[] FUNC_167 = new byte[]{Commands.GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x43, 0x64};
byte[] FUNC_169 = new byte[]{Commands.GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x45, 0x48};
byte[] FUNC_180 = new byte[]{Commands.GS, 0x28, 0x6b, store_pL, store_pH, 0x31, 0x50, 0x30};
byte[] FUNC_181 = new byte[]{Commands.GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x51, 0x48};
byte[] FUNC_182 = new byte[]{Commands.GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x52, 0x48};
ByteArrayOutputStream writer = new ByteArrayOutputStream();
writer.write(INIT);
writer.write(FUNC_165);
writer.write(FUNC_167);
writer.write(FUNC_169);
writer.write(FUNC_180);
writer.write(content.getBytes());
writer.write(FUNC_181);
writer.write(FUNC_182);
writer.write(CUT);
writer.close();

The output is QHello !!.

What am I doing wrong here. Any help is appreciated.

答案1

得分: 2

如果您是指EPSON的这些页面,其中参数的数字是十进制,而不是十六进制。

GS(k <Function 165>
GS(k <Function 167>
GS(k <Function 169>
GS(k <Function 180>
GS(k <Function 181>
GS(k <Function 182>

还是这是适用于自定义VKP打印机的正确参数?
我无法判断,因为我没有Custom VKP打印机的ESC/POS命令参考。

  • 从数字值来看,似乎我正在尝试打印Micro QR Code,打印机是否支持?
  • 模块大小指定了一些未知值,但EPSON的范围在1到16之间。默认值为3。
  • 既然FUNC_182是用于通知条码的打印尺寸的函数,在打印后调用它没有意义。

假设打印机支持MicroQRCode打印,命令创建部分如下:

byte[] FUNC_165 = new byte[]{Commands.GS, 0x28, 0x6b, 0x04, 0x00, 0x31, 0x41, 0x33, 0x00};
byte[] FUNC_167 = new byte[]{Commands.GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x43, 0x03};
byte[] FUNC_169 = new byte[]{Commands.GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x45, 0x30};
byte[] FUNC_180 = new byte[]{Commands.GS, 0x28, 0x6b, store_pL, store_pH, 0x31, 0x50, 0x30};
byte[] FUNC_181 = new byte[]{Commands.GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x51, 0x30};
byte[] FUNC_182 = new byte[]{Commands.GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x52, 0x30};

尽管当前内容没有问题,但实际上将数据长度指定为字节数组的长度,而不是字符串的长度。

因此,第一部分将是:

String content = "Hello !!";
byte[] content_bytes = content.getBytes(StandardCharsets.US_ASCII)
int store_len = content_bytes.length + 3;
byte store_pL = (byte) (store_len % 256);
byte store_pH = (byte) (store_len / 256);

实际写入将类似于:

writer.write(INIT);
writer.write(FUNC_165);
writer.write(FUNC_167);
writer.write(FUNC_169);
writer.write(FUNC_180);
writer.write(content_bytes);
writer.write(FUNC_181);
writer.write(CUT);
writer.close();

请尝试根据您的自定义VKP打印机实际支持的参数范围进行调整。

英文:

If you are referring to these pages in EPSON, the numbers for the parameters written in them are decimal, not hexadecimal.

GS ( k &lt;Function 165&gt;
GS ( k &lt;Function 167&gt;
GS ( k &lt;Function 169&gt;
GS ( k &lt;Function 180&gt;
GS ( k &lt;Function 181&gt;
GS ( k &lt;Function 182&gt;

Or is it the right parameter for a Custom VKP printer?
I can't judge it because I don't have the ESC/POS command reference for the Custom VKP printer.

  • From the numerical value, it seems that I am trying to print Micro QR Code, is the printer supported?
  • Some unknown value is specified for the module size, but EPSON is in the range of 1 to 16. The default is 3.
  • And since FUNC_182 is a function to notify the print size of the barcode, calling it after printing has no meaning.

Assuming the printer supports MicroQRCode printing, the command creation part would look like this:

byte[] FUNC_165 = new byte[]{Commands.GS, 0x28, 0x6b, 0x04, 0x00, 0x31, 0x41, 0x33, 0x00};
byte[] FUNC_167 = new byte[]{Commands.GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x43, 0x03};
byte[] FUNC_169 = new byte[]{Commands.GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x45, 0x30};
byte[] FUNC_180 = new byte[]{Commands.GS, 0x28, 0x6b, store_pL, store_pH, 0x31, 0x50, 0x30};
byte[] FUNC_181 = new byte[]{Commands.GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x51, 0x30};
byte[] FUNC_182 = new byte[]{Commands.GS, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x52, 0x30};
  • Although there is no problem with the current contents, actually specify the data length as the length of the byte array, not the length of the string.

So the first part would be:

String content = &quot;Hello !!&quot;;
byte[] content_bytes = content.getBytes(StandardCharsets.US_ASCII)
int store_len = content_bytes.length + 3;
byte store_pL = (byte) (store_len % 256);
byte store_pH = (byte) (store_len / 256);

The actual writing will be like this?:

writer.write(INIT);
writer.write(FUNC_165);
writer.write(FUNC_167);
writer.write(FUNC_169);
writer.write(FUNC_180);
writer.write(content_bytes);
writer.write(FUNC_181);
writer.write(CUT);
writer.close();

Please try adjusting it to the parameter range that your Custom VKP printer actually supports.

huangapple
  • 本文由 发表于 2020年8月18日 23:04:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/63471463.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定