【问题标题】:Cannot read bluetooth data from Bluetooth Serial Ionic无法从蓝牙串行离子读取蓝牙数据
【发布时间】:2017-12-14 13:56:43
【问题描述】:

我编写了以下代码以在应用程序的警报消息中显示接收到的蓝牙数据。

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 蓝牙串行包以显示接收到的蓝牙数据?

【问题讨论】:

    标签: android cordova typescript ionic-framework bluetooth


    【解决方案1】:

    请尝试删除您的超时并在 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))});
            });
        });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 2021-05-19
      • 2021-08-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多