我正在尝试构建一个简单的蓝牙串行应用程序来连接到我的arduino。我正在使用ionic2来制作Android应用程序。现在,我所要做的就是列出所有可用的蓝牙设备。下面是我的代码:Bluetooth Serial Ionic 2
import { Component } from '@angular/core';
import { BluetoothSerial } from 'ionic-native';
import { NavController } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public working:string;
public var2: string ;
bluetoothSerial.isEnabled(
function() {
this.working= "Bluetooth is enabled";
},
function() {
this.working="Bluetooth is *not* enabled";
}
);
public lists = [];
bluetoothSerial.discoverUnpaired(function(devices) {
this.lists.push(devices);
}, function(){ this.var2 = 'could not find any bluetooth device';});
constructor() { }
}
每当我做离子成为我做很多的错误,主要是因为蓝牙无法识别(函数实现缺失)。它也不允许我构建应用程序。
请帮忙。
谢谢你这么多
非常感谢你的伴侣!我非常感谢你的时间和帮助。我会尝试你的给定的代码,并会返回给你更新。谢谢 –
当然,我自己并没有使用这个库。查看他们的ionic2文档,如果你有一些业余时间:) https://ionicframework.com/docs/v2/native/bluetooth-serial/ – Ivaro18
嘿队友,你的代码通过删除'this.getAlBluetoothDevices()完美地工作。 '从constrcutor(),我不知道为什么它是问题。另外BS.list只列出配对的设备不是不配对的(这也在BS文档中提及)。但是,它的工作伙伴...接下来的事情我会尝试连接到一个Arduino设备,看看它是否工作。 –