Ionic 2中的蓝牙串口,无法连接

时间:2017-03-18 15:38:45

标签: html typescript bluetooth ionic2 cordova-plugins

我在Ionic2应用程序中使用蓝牙序列,我想连接到设备。

现在在.ts文件中有这个但是不起作用。我可以启用蓝牙但无法连接。

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 stat_on:any;
  public stat_con:any;
  public macAddress:"98:D3:31:90:77:36";
  constructor(public navCtrl: NavController) {

  }
  turnON(){
    BluetoothSerial.enable().then((status)=> {
        this.stat_on=status;

    });
  }
  Connect(){
    BluetoothSerial.isEnabled().then((data)=> {
      BluetoothSerial.connect("98:D3:31:90:77:36").then((stat_con)=>{
            this.stat_con=stat_con;

        });
    });
  }
}

这是我的HTML文件

<ion-header>
  <ion-navbar>
    <ion-title>Home</ion-title>
  </ion-navbar>

</ion-header>

<ion-content padding>
    <ion-fab right bottom>
      <button ion-fab color="light"><ion-icon name="arrow-dropleft"></ion-icon></button>
    </ion-fab>
    <ion-card-content>
    <button ion-button (click)="turnON()">Turn ON Bluetooth</button>
    <button ion-button (click)="Connect()">Connect</button>
      <p>BT: {{ stat_on }}</p>
      <p>Status: {{ stat_connect }}</p>
    </ion-card-content>
</ion-content>

之前感谢:)

0 个答案:

没有答案