(蓝牙串口)Bluetooth Serial

(蓝牙串口)Bluetooth Serial,第1张

该插件可以通过蓝牙进行串行通信。 它是为了在Android或iOS和Arduino之间进行通信而编写的。

Repo(备用): https://github.com/don/BluetoothSerial

1.安装Cordova和Ionic原生插件:

2. 添加插件到app's module

Android

iOS

Windows Phone 8

connect(macAddress_or_uuid)

Platforms:****ANDROID IOS WINDOWS PHONE

连接到蓝牙设备

****Returns:** Observable<any>

连接订阅,断开连接取消订阅。

connectInsecure(macAddress)

Platforms:****ANDROID

蓝牙设备不安全地连接

****Returns:** Observable<any>

连接订阅,断开连接取消订阅。

disconnect()

断开连接的设备

****Returns:** Promise<any>

write(data)

Platforms:****ANDROID IOS WINDOWS PHONE

将数据写入串口

****Returns:** Promise<any>

当数据写入时返回promise

available()

Platforms:****ANDROID IOS WINDOWS PHONE

获取可用数据的字节数

****Returns:** Promise<any>

返回包含可用字节的promise

read()

Platforms:****ANDROID IOS WINDOWS PHONE

从缓冲区读取数据

****Returns:** Promise<any>

从缓冲区返回数据的promise

readUntil(delimiter)

Platforms:****ANDROID IOS WINDOWS PHONE

从缓冲区读取数据,直到达到定界符

****Returns:** Promise<any>

returns a promise

subscribe(delimiter)

Platforms:****ANDROID IOS WINDOWS PHONE

订阅收到数据时收到通知

****Returns:** Observable<any>

返回一个observable.

subscribeRawData()

Platforms:****ANDROID IOS WINDOWS PHONE

订阅收到数据时收到通知

****Returns:** Observable<any>

返回一个observable

clear()

Platforms:****ANDROID IOS WINDOWS PHONE

清除缓冲区中的数据

****Returns:** Promise<any>

完成后返回promise

list()

Platforms:****ANDROID IOS WINDOWS PHONE

列出绑定设备

****Returns:** Promise<any>

返回一个promise

isEnabled()

Platforms:****ANDROID IOS WINDOWS PHONE

报告蓝牙是否启用

****Returns:** Promise<any>

返回一个promise

isConnected()

Platforms:****ANDROID IOS WINDOWS PHONE

报告连接状态

****Returns:** Promise<any>

返回一个promise

readRSSI()

Platforms:****ANDROID IOS WINDOWS PHONE

从连接的外围设备读取RSSI

****Returns:** Promise<any>

返回一个promise

showBluetoothSettings()

Platforms:****ANDROID IOS WINDOWS PHONE

显示设备上的蓝牙设置

****Returns:** Promise<any>

返回一个promise

enable()

Platforms:****ANDROID IOS WINDOWS PHONE

在设备上启用蓝牙

****Returns:** Promise<any>

返回一个 promise

discoverUnpaired()

Platforms:****ANDROID IOS WINDOWS PHONE

发现不配对的设备

****Returns:** Promise<any>

返回一个promise

setDeviceDiscoveredListener()

Platforms:****ANDROID IOS WINDOWS PHONE

订阅蓝牙设备发现通知。 发现过程必须通过discoverUnpaired 来启动功能。

****Returns:** Observable<any>

返回一个 observable

setName(newName)

Platforms:****ANDROID

设置广播到其他设备的可读设备名称

setDiscoverable(discoverableDuration)

Platforms:****ANDROID

使设备可以被其他设备发现

4、ng-cordova安装与使用

4.1、下载ng-cordova

bower install ngCordova

4.2、引入ng-cordova.js文件

把 ng-cordova.js 或者 ng-cordova.min.js引入index.html中并放在cordova.js之前, AngularJS Ionic 文件之后 (因为ngCordova d依赖AngularJS).

4.4、引入ng-cordova的依赖

在主程序的app.js中引入ng-cordova的依赖

angular.module('myApp', ['ngCordova'])

4.5、添加插件到你的Cordova CLI环境中

cordova plugin add ...

4.6、使用

要在检查设备准备完毕之后使用

document.addEventListener("deviceready", function () {

$cordovaPlugin.someFunction().then(success, error)

}, false)

// OR with IONIC

$ionicPlatform.ready(function() {

$cordovaPlugin.someFunction().then(success, error)

})

不过我测试过,因为已经run过了,你的各种功能肯定在这之后,所以之后在哪用都可以。不过要是有些功能是启动应用就要有,还是要写在这里面的。

?

angular.module('starter', ['ionic', 'route','config','global','commonJs','ngCordova'])

.run(['$ionicPlatform','$rootScope', '$location', '$timeout', '$ionicHistory','CommonJs','$cordovaToast',function($ionicPlatform,$rootScope, $location, $timeout, $ionicHistory,CommonJs,$cordovaToast) {

$ionicPlatform.ready(function() {

// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard

if (window.cordova &&window.cordova.plugins &&window.cordova.plugins.Keyboard) {

cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true)

}

if (window.StatusBar) {

// org.apache.cordova.statusbar required

StatusBar.styleLightContent()

}

})

}])


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11641198.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存