本文整理汇总了TypeScript中ionic-native.BluetoothSerial类的典型用法代码示例。如果您正苦于以下问题:TypeScript BluetoothSerial类的具体用法?TypeScript BluetoothSerial怎么用?TypeScript BluetoothSerial使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BluetoothSerial类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: ngOnInit
ngOnInit(){
//this.bluetoothSerial.connect(macAddress_or_uuid, connectSuccess, connectFailure);
/* BluetoothSerial.startScan([]).subscribe(device => {
this.devices.push(device);
});
*/
BluetoothSerial.available();
BluetoothSerial.isConnected();
BluetoothSerial.isEnabled();
BluetoothSerial.enable();
BluetoothSerial.showBluetoothSettings();
}
示例2: bledeviceChanged
bledeviceChanged(value) {
this.blescan = false;
this.datastream = [];
if (this.platform.is('mobile')) {
BluetoothSerial.connect(value).then(
value => {
this.datastream.push("connect ok:" + JSON.stringify(value));
console.log(value);
this.watcher = BluetoothSerial.subscribe('\n').subscribe(
(data) => {
this.datastream.push("subscribe data:" + JSON.stringify(data));
this.userData.setBluetoothData(data);
console.log("subscribe data" + data);
},
(err) => {
this.datastream.push("subscribe err:" + JSON.stringify(data));
console.log("subscribeRaw err:" + data);
}
);
},
err => {
this.datastream.push("connect err:" + JSON.stringify(err));
console.error(err);
}
);
} else {
var data = '{\"id\":\"0000000001\",\"pr\":127,\"tp\":22.0,\"ba\":2.95}\r\n';
this.datastream.push(JSON.stringify(data));
this.userData.setBluetoothData(data);
}
}
示例3:
BluetoothSerial.isConnected().then((result) => {
var counter = (this.counter++).toString() + '\n';
BluetoothSerial.write(counter).then((data) => {
this.datastream.push(JSON.stringify(data));
this.userData.setBluetoothData(data);
this.datastream.push("write data:" + JSON.stringify(data) + this.counter);
console.log("write data" + data);
});
});
示例4: sendData
sendData() {
if (this.counter > 9) this.counter = 1;
if (this.platform.is('mobile')) {
BluetoothSerial.isConnected().then((result) => {
var counter = (this.counter++).toString() + '\n';
BluetoothSerial.write(counter).then((data) => {
this.datastream.push(JSON.stringify(data));
this.userData.setBluetoothData(data);
this.datastream.push("write data:" + JSON.stringify(data) + this.counter);
console.log("write data" + data);
});
});
} else {
var data = '{\"id\":\"0000000001\",\"pr\":127,\"tp\":22.0,\"ba\":2.95}\r\n';
this.datastream.push(JSON.stringify(data));
this.userData.setBluetoothData(data);
this.datastream.push("write data:" + this.counter++);
}
}
示例5: bleToggleMobile
bleToggleMobile(value) {
if (value) {
BluetoothSerial.list().then(
value => {
if (value.length > 0) {
this.devices = value;
} else {
this.userData.showToast('No bluetooth device paired!', 'Error!', this.nav);
}
//this.datastream.push("list ok:" + JSON.stringify(value));
console.log(value);
},
err => {
this.datastream.push("list err:" + JSON.stringify(err));
console.error(err);
}
);
} else {
if (this.watcher) {
this.watcher.unsubscribe();
this.watcher = null;
}
}
}