我编写了以下代码,以便在应用程序的警报消息中显示收到的蓝牙数据。
open(item: any){
alert("Selected ");
this.bluetoothSerial.connectInsecure("XX:XX:X4:X6:1X:2X").subscribe((data) =>{
alert(JSON.stringify(data));
this.bluetoothSerial.subscribeRawData().subscribe((data) => { alert("Subscription : " + JSON.stringify(data))});
});
setTimeout(() => {
this.bluetoothSerial.read().then((data) => { alert("read data : " +JSON.stringify(data))});
}, 2000);
}
发送蓝牙信号时,"订阅"警报框和"读取数据"警告框既显示空字符串,也不显示实际发送的数据。如何配置Ionic Bluetooth Serial软件包以显示收到的蓝牙数据?
答案 0 :(得分:0)
请尝试删除超时并在subscribeRawData()中调用read(),如下所示:
open(item: any){
alert("Selected ");
this.bluetoothSerial.connectInsecure("XX:XX:X4:X6:1X:2X").subscribe((data) {
alert(JSON.stringify(data));
this.bluetoothSerial.subscribeRawData().subscribe((data) => {
alert("Subscription : " + JSON.stringify(data));
this.bluetoothSerial.read().then((data) => { alert("read data : " +JSON.stringify(data))});
});
});
}