小票打印 API

@cutos/device-receipt-printer 是一个 JavaScript 库,提供统一的接口来访问和控制支持小票打印机。 开发者可以使用该接口发送和接收数据、配置打印机参数以及处理打印机事件。

安装

npm install @cutos/device-receipt-printer

导入依赖

import {DeviceReceiptPrinter} from '@cutos/device-receipt-printer';

DeviceReceiptPrinter

构造函数,用于创建小票打印机设备实例

let devReceiptPrinter = new DeviceReceiptPrinter();

DeviceReceiptPrinter.init

小票打印机设备初始化

devReceiptPrinter.init(callback);
  • callback:回调函数
示例:
devReceiptPrinter.init((result, error) => {
    if (!error) {
        console.log('init ReceiptPrinter', result)
    } else {
        console.log(error)
    }
});
  • 返回示例:
"Driver device-receipt-printer loaded"

DeviceReceiptPrinter.connect

连接小票打印机

devReceiptPrinter.connect(path, callback);
  • path:设备端口
  • callback:回调函数
示例:
 devReceiptPrinter.connect('/ttyS1', (response) => {
    console.log(response)
})
  • 返回示例:
{
  "status": true,
  "msg": "connect success"
}

DeviceReceiptPrinter.print

打印文本

devReceiptPrinter.print(text, callback);
  • text:打印文本
  • callback:回调函数
示例:
 devReceiptPrinter.print('测量结果', (response) => {
    console.log(response)
})
  • 返回示例:
{
  "status": true,
  "msg": "print success"
}

DeviceReceiptPrinter.printQrcode

打印二维码

devReceiptPrinter.printQrcode(text, callback);
  • text:要生成二维码的文本
  • callback:回调函数
示例:
 devReceiptPrinter.printQrcode('hello cutos', (response) => {
    console.log(response)
})
  • 返回示例:
{
  "status": true,
  "msg": "print qrcode success"
}

DeviceReceiptPrinter.setAlign

设置对齐方式

 setAlign(align, callback)
  • align:对齐方式,有效值:'left', 'center', 'right'
  • callback:回调函数
示例:
devReceiptPrinter.setAlign('left', (response) => {
    console.log(response)
})
  • 返回示例:
{
  "status": true,
  "msg":"set align success"
}

DeviceReceiptPrinter.setFontSize

设置打印字体大小

devReceiptPrinter.setFontSize(width, height, callback)
  • width:字体宽度,数值范围(1-7)
  • height:字体高度,数值范围(1-7)
  • callback:回调函数
示例:
devReceiptPrinter.setFontSize(2, 2, (response) => {
    console.log(response)
})
  • 返回示例:
{
  "status": true,
  "msg":"set fontSize success"
}

DeviceReceiptPrinter.feed

打印空行

devReceiptPrinter.feed(lines, callback)
  • lines:空行数量,空行的行高和文字行高一样,数值范围(1-255)
  • callback:回调函数
示例:
devReceiptPrinter.feed(1, (response) => {
    console.log(response)
})
  • 返回示例:
{
  "status": true,
  "msg":"feed success"
}

results matching ""

    No results matching ""