我使用ionic cordova和打字稿来开发我的应用程序,并按照官方文档“ ionic cordova plugin add cordova-plugin-ble-central”“ npm install @ ionic-native / ble”的要求导入了相应的插件,可以发现并连接蓝牙打印机,并使用ble.write()打印数据,此函数成功回调“确定”,但是打印机不起作用,以下是我的代码:
const data = new Uint8Array([0x80, 0xbe, 0xf5, 0xac, 0xff]);
const characteristics = this.deviceinfo.characteristics;
for (let i = 0; i < characteristics.length; i++) {
const item = characteristics[i];
if (item.properties.includes('Write')) {
this.ble.write(this.deviceinfo.id, item.service, item.characteristic, data.buffer).then(res => {
console.log('write()success: ' + JSON.stringify(res)); //write()success: "OK"
}, err => {
console.log('write()fail: ' + JSON.stringify(err));
});
break;
}
任何建议将不胜感激!