npm i --save nativescript-ichi-printer
- 版本:0.9.9
- GitHub: https://github.com/mozhju/nativescript-ichi-printer
- NPM: https://npmjs.net.cn/package/nativescript-ichi-printer
- 下载
- 昨天: 0
- 上周: 0
- 上个月: 0
nativescript-ichi-printer
NativeScript POS 打印机。
支持的平台
- Android(任何安装了Android 4.4及以上版本的设备)
目前不支持iOS!
安装
tns plugin add nativescript-ichi-printer
使用方法
以下是一个TypeScript示例
import {PrintClient} from "nativescript-ichi-printer";
// new Printer Client, param: 0: TCP, 1: USB, 2: Bluetooth
var printClient = new PrintClient(0);
printClient.onData = (data: Array<number>) => {
console.log("Data from Printer: ", data);
};
printClient.onError = (id: number, message: string) => {
console.log("Print client error for action #", id, ": ", message);
};
printClient.onConnected = (id: number) => {
console.log("Print client connected action #: ", id);
var message = "Print test String!";
var bytes = [];
for (var i = 0; i < message.length; i++) {
var c = message.charCodeAt(i);
bytes.push(c & 0xFF);
}
printClient.send(bytes);
};
printClient.onSent = (id: number) => {
console.log("Print client sent action #: ", id);
// When we are finished
printClient.close();
};
printClient.onClosed = (id: number) => {
console.log("Print client closed action #: ", id);
};
// Connect printer (type: TCP), param: IP, port
printClient.connect("192.168.1.192", 9100);
// // Connect printer (type: USB), param: printer Name by getUsbPrinters()
// printClient.connect("USB Support Printer 1", 0);
// // Connect printer (type: Bluetooth), param: printer Name by getBlueToothPrinters()
// printClient.connect("58 POS printer", 0);