如何使用ionic 3连接蓝牙打印机?
How to connect bluetooth printer using ionic 3?
我无法使用以下插件连接蓝牙打印机
$ ionic cordova plugin add de.appplant.cordova.plugin.printer
$ npm install --save @ionic-native/printer
有什么方法可以使用ionic 3连接蓝牙打印机吗?
下面是使用 ionic 2+ 打印到蓝牙收据打印机的示例。我写这篇文章是因为我遇到了同样的问题。
所以我尝试使用 ionic 本机蓝牙串行连接到 'write' 进行打印并且成功了。
它应该也适用于 ionic 3:
遵循这 3 个步骤:1-找到蓝牙设备,2-使用其 ID 连接设备,3-打印
devices = [];
btnFindDevices() {
this.bluetoothSerial.isEnabled().then(() => {
this.bluetoothSerial.discoverUnpaired().then((allDevices) => {
this.devices = allDevices;
console.log(allDevices);
});
});
}
btnBlueToothConnect() {
if (this.devices.length > 0) {
//this code connects device which’s position is 0. Change it whatever you
//want.
this.bluetoothSerial.connect(this.devices[0].id).subscribe((data) => {
console.log(“Connected”, data);
}, (error) => {
console.log(“not Connected”, error);
});
}
else {
console.log(“Device List did not genereted yet.”);
}
}
btnBlueToothPrint() {
//Attention… Bluetooth printer prints data when whole line filled. For
//example in my case printer is 32 colon,
//“hello world” has 11 characters. so it prints after 3 times clicked
//the print button.
this.bluetoothSerial.write(‘hello world’).then(() => { console.log(“s”); }, () => { console.log(“f”); });
}
我无法使用以下插件连接蓝牙打印机
$ ionic cordova plugin add de.appplant.cordova.plugin.printer
$ npm install --save @ionic-native/printer
有什么方法可以使用ionic 3连接蓝牙打印机吗?
下面是使用 ionic 2+ 打印到蓝牙收据打印机的示例。我写这篇文章是因为我遇到了同样的问题。
所以我尝试使用 ionic 本机蓝牙串行连接到 'write' 进行打印并且成功了。
它应该也适用于 ionic 3:
遵循这 3 个步骤:1-找到蓝牙设备,2-使用其 ID 连接设备,3-打印
devices = [];
btnFindDevices() {
this.bluetoothSerial.isEnabled().then(() => {
this.bluetoothSerial.discoverUnpaired().then((allDevices) => {
this.devices = allDevices;
console.log(allDevices);
});
});
}
btnBlueToothConnect() {
if (this.devices.length > 0) {
//this code connects device which’s position is 0. Change it whatever you
//want.
this.bluetoothSerial.connect(this.devices[0].id).subscribe((data) => {
console.log(“Connected”, data);
}, (error) => {
console.log(“not Connected”, error);
});
}
else {
console.log(“Device List did not genereted yet.”);
}
}
btnBlueToothPrint() {
//Attention… Bluetooth printer prints data when whole line filled. For
//example in my case printer is 32 colon,
//“hello world” has 11 characters. so it prints after 3 times clicked
//the print button.
this.bluetoothSerial.write(‘hello world’).then(() => { console.log(“s”); }, () => { console.log(“f”); });
}