【问题标题】:Custom TG2480H thermal printer can not print cyrillic characters .NET C#定制TG2480H热敏打印机无法打印西里尔字符.NET C#
【发布时间】:2013-07-22 12:34:11
【问题描述】:

我在自定义 TG2480H 热敏打印机中打印西里尔字符时遇到问题。在其文档中写到 0x1B、0x74、17 命令序列会将字符表设置为 Cyrillic,然后我将字符串编码为字节数组并发送到打印机,但打印机不会打印 cryllic 我的代码就是这样

string text = "Добрый день";
ec = writer.Write(new byte[] { 0x1B, 0x74, 17 }, 1000, out bytesWritten);
ec = writer.Write(Encoding.GetEncoding("windows-1251").GetBytes(text), 1000, out bytesWritten);

如您所见,编码是 windows-1251,我将打印机的字符表设置为西里尔字母,但正在打印未知字符。请帮忙,在此先感谢!

【问题讨论】:

  • 你的writer是什么类型的?
  • 我使用 LibUsbDotNet C# USB 库作为 API 通过 USB 传输数据,这里是完整代码
  • 只是猜测:也许0x17 的意思是而不是17
  • UsbEndpointWriter writer = MyUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep02); // Ep02 字符串 text = "Добрый день"; ec = writer.Write(new byte[] { 0x1B, 0x74, 17 }, 1000, out bytesWritten); ec = writer.Write(Encoding.GetEncoding("windows-1251").GetBytes(text), 1000, out bytesWritten);
  • @StephanBauer 不,因为在文档 0x1B, 0x74 中,写了 n ,其中 n 是表示字符表的数字,而 17 表示西里尔文

标签: c# .net thermal-printer libusbdotnet


【解决方案1】:

只需使用另一种编码:866

string text = "Добрый день";
ec = writer.Write(new byte[] { 0x1B, 0x74, 17 }, 1000, out bytesWritten);
ec = writer.Write(Encoding.GetEncoding(866).GetBytes(text), 1000, out bytesWritten);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多