微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 escpos 包和串口创建收据

如何解决使用 escpos 包和串口创建收据

我正在尝试构建一个电子应用程序并创建一个简单的收据以通过串行端口打印。

我正在使用:

  • 电子:^11.1.1
  • escpos^3.0.0-alpha.6
  • escpos-serialport:^3.0.0-alpha.4

这是我创建收据的代码

const escpos = require('escpos');
escpos.SerialPort = require('escpos-serialport');

module.exports = {

  printSerial: function(port,data){

    let device = new escpos.SerialPort('COM2',{ baudrate: 19200 });
    let printer = new escpos.Printer(device);

    device.open(function(err){
      printer
      .size(1,1)
      .font('A')
      .encode('CP949')
      .align('CT')
      .style('norMAL')
      .println('Receipt')
      .newLine()
      .align('LT')
      .style('norMAL')
      .tableCustom([
        { text: 'Date:',width: 0.2 },{ text: '2021-01-04 11:11',width: 0.6 }
      ])
      .style('norMAL')
      .tableCustom([
        { text: 'Order ID:',{ text: '050-7866-2406',width: 0.6 }
      ])
      .style('norMAL')
      .tableCustom([
        { text: '전화번호:',{ text: '200000000',width: 0.6,align: 'LEFT' }
      ],{ encoding: 'EUC-KR' })
      .tableCustom([
        { text: '메모:',width: 0.4 },{ text: '문앞에 두고 벨을 눌러주세요',width: 0.6 }
      ],'CP949')
      .drawLine()
      .newLine()
      .println('기사님 이름:','CP949')
      .println('기사님 번호:','CP949')
      .drawLine()
      .newLine()
      .tableCustom([
        { text: '내부규',width: 0.33,align: 'LEFT' },{ text: '내부',align: 'CENTER' },{ text: '율과',align: 'CENTER' }
      ],'CP949')
      .tableCustom([
        { text: '내부규율과',{ text: '1',{ text: '2,000,000 원','CP949')
      .drawLine()
      .newLine()
      .tableCustom([
        { text: '합계',width: 0.4,align: 'RIGHT' }
      ],'CP949')
      .tableCustom([
        { text: '배송료(11.2km)','CP949')
      .tableCustom([
        { text: '수수료',{ text: '-0 원','CP949')
      .drawLine()
      .newLine()
      .tableCustom([
        { text: '총금액','CP949')
      .newLine()
      .newLine()
      .newLine()
      .cut();

      setTimeout(function(){
        printer.close();
      },1000);
    });
  }

};

当我调用 printSerial 方法时。收据打印成功。但是韩文的文字是不正确的。我尝试了许多编码名称,但仍然无法正常工作。

以及如何更改收据中的字体大小,收据上的当前文本非常大。

也许我遗漏了什么?

非常感谢您的帮助。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。