在 Birch 打印机上使用 ESC/POS 更改代码页

发布于 2025-01-18 07:41:47 字数 665 浏览 0 评论 0原文

我正在使用QZ托盘工具使用ESC/POS命令将原始数据发送到热打印机。这是我使用的代码,并且在大多数打印机上都可以正常工作:

data = [
    "\x1b\x40",
    "\x1b\x74\x49", // ESC t 73 - switch to Windows-1251
    text + "\r\n",
    "\x1B\x74\x48", // ESC t 72 - switch to Windows-1250
    text + "\r\n",
];

let config = qz.configs.create('printer_name', { encoding: 'windows-1251' });
qz.print(config, print_data).catch(function(e) {
    console.error(e);
});

我遇到的问题是桦木CP-Q3打印机。如果N大于33,则该打印机似乎不会执行ESC T N命令。就像它无法识别这些代码页面一样。命令ESC T N如果N小于33。

最奇怪的是,我可以将代码页面切换为73,例如使用打印机工具,但是使用ESC/POS命令无法完成。打印机自我测试还包含那些代码页。

在更改代码页面或打印机配置之前,我应该执行一个命令,以便可以使用扩展代码页面?

I am using QZ Tray tool to send raw data to thermal printer using ESC/POS commands. This is the code I'm using and it's working as expected on most printers:

data = [
    "\x1b\x40",
    "\x1b\x74\x49", // ESC t 73 - switch to Windows-1251
    text + "\r\n",
    "\x1B\x74\x48", // ESC t 72 - switch to Windows-1250
    text + "\r\n",
];

let config = qz.configs.create('printer_name', { encoding: 'windows-1251' });
qz.print(config, print_data).catch(function(e) {
    console.error(e);
});

The issues I am having are with Birch CP-Q3 printer. This printer doesn't seem to execute ESC t n command if the n is greater than 33. Like that it doesn't recognize those code pages. Command ESC t n works fine if the n is less than 33.

Strangest thing is that I can switch code page to 73 for example using printer tool, but it can't be done using ESC/POS commands. Printer self test also contains those code pages.

Is there a command that I should execute before changing code page or a printer configuration that I can change so that extended code pages can be used?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心是晴朗的。 2025-01-25 07:41:47

我给 Birch-POS 支持人员发了电子邮件,他们说了以下内容:

请建议客户使用命令\x1F\x1B\x1F\xFF\x49将代码页设置为windows-1251。

这与OPs的wireshark评论相匹配,引用:

使用wireshark,在使用打印机工具设置代码页73时,我设法获得以下十六进制转储:1f 1b 1f ff 49 ...

不幸的是,JavaScript(特别是UTF-8)不喜欢某些转义序列x7F

工作代码应该如下所示:

var text = 'Привет мир';

// Use QZ's hex mode, which can workaround JavaScript not allowing certain hex values
var data = [
   { 
    type: 'raw',
    format: 'command'
    flavor: 'hex',
    data: 'x1Fx1Bx1FxFFx49', // Instruct Birch POS: Windows-1251
    // data: 'x1Fx1Bx1FxFFx48', // Instruct Birch POS: Windows-1250
   },
   text + '\r\n'
];

// Tell Java to use a strict 8-bit encoding
var config = qz.configs.create('printer_name', { encoding: 'ISO-8859-1' });

qz.print(config, print_data).catch(function(e) {
    console.error(e);
});

I emailed Birch-POS support and they say the following:

Please suggest customer to use command \x1F\x1B\x1F\xFF\x49 to set codepage to windows-1251.

Which matches the OPs wireshark comment, quoting:

Using wireshark I managed to get the following HEX dump when setting code page 73 using printer tool: 1f 1b 1f ff 49 ...

Unfortunately, JavaScript (specifically, UTF-8) does not like certain escape sequences over x7F.

The working code should look like this:

var text = 'Привет мир';

// Use QZ's hex mode, which can workaround JavaScript not allowing certain hex values
var data = [
   { 
    type: 'raw',
    format: 'command'
    flavor: 'hex',
    data: 'x1Fx1Bx1FxFFx49', // Instruct Birch POS: Windows-1251
    // data: 'x1Fx1Bx1FxFFx48', // Instruct Birch POS: Windows-1250
   },
   text + '\r\n'
];

// Tell Java to use a strict 8-bit encoding
var config = qz.configs.create('printer_name', { encoding: 'ISO-8859-1' });

qz.print(config, print_data).catch(function(e) {
    console.error(e);
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文