(蓝牙串口)Bluetooth Serial

作者: 待花谢花开 | 来源:发表于2017-06-30 09:30 被阅读142次

Bluetooth Serial

该插件可以通过蓝牙进行串行通信。 它是为了在Android或iOS和Arduino之间进行通信而编写的。
Repo(备用): https://github.com/don/BluetoothSerial

Installation(安装)

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

$ ionic cordova plugin add cordova-plugin-bluetooth-serial
$ npm install --save @ionic-native/bluetooth-serial

2.添加插件到app's module

Supported platforms(支持平台)

Android
iOS
Windows Phone 8

Usage(用法)

import { BluetoothSerial } from '@ionic-native/bluetooth-serial';

constructor(private bluetoothSerial: BluetoothSerial) { }


// Write a string
this.bluetoothSerial.write('hello world').then(success, failure);

// Array of int or bytes
this.bluetoothSerial.write([186, 220, 222]).then(success, failure);

// Typed Array
var data = new Uint8Array(4);
data[0] = 0x41;
data[1] = 0x42;
data[2] = 0x43;
data[3] = 0x44;
this.bluetoothSerial.write(data).then(success, failure);

// Array Buffer
this.bluetoothSerial.write(data.buffer).then(success, failure);

Instance Members(实例成员)

connect(macAddress_or_uuid)

Platforms:****ANDROID IOS WINDOWS PHONE
连接到蓝牙设备

参数 类型 详情
macAddress_or_uuid string 远程设备的标识符

****Returns:** Observable<any>
连接订阅,断开连接取消订阅。

connectInsecure(macAddress)

Platforms:****ANDROID
蓝牙设备不安全地连接

参数 类型 详情
macAddress string 远程设备的标识符

****Returns:** Observable<any>
连接订阅,断开连接取消订阅。

disconnect()

断开连接的设备
****Returns:** Promise<any>

write(data)

Platforms:****ANDROID IOS WINDOWS PHONE
将数据写入串口

参数 类型 详情
data any ArrayBuffer的数据

****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
从缓冲区读取数据,直到达到定界符

参数 类型 详情
delimiter string 要搜索的字符串

****Returns:** Promise<any>
returns a promise

subscribe(delimiter)

Platforms:****ANDROID IOS WINDOWS PHONE
订阅收到数据时收到通知

参数 类型 详情
delimiter string 你想要搜索的字符串

****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
设置广播到其他设备的可读设备名称

参数 类型 详情
newName string 所需的设备名称

setDiscoverable(discoverableDuration)

Platforms:****ANDROID
使设备可以被其他设备发现

参数 类型 详情
discoverableDuration number 所需设备应该被发现的秒数

相关文章

  • (蓝牙串口)Bluetooth Serial

    Bluetooth Serial 该插件可以通过蓝牙进行串行通信。 它是为了在Android或iOS和Arduin...

  • 蓝牙学习-SPP

    SPP - Serial Port Profifile SPP提供两个连接的蓝牙设备可以建立虚拟串口连接的能力。务...

  • Android蓝牙权限

    1. 蓝牙权限 蓝牙连接和通讯需要获取相关的蓝牙权限BLUETOOTH和BLUETOOTH_ADMIN。 蓝牙权限...

  • 蓝牙开发入门

    蓝牙开发 相关资料: 蓝牙通过网站下载蓝牙开发套件 Bluetooth 和BLE 蓝牙(Bluetooth) 一种...

  • android蓝牙专题

    深入了解Android蓝牙Bluetooth ——《总结篇》 安卓蓝牙应用程序编写步骤 蓝牙 bluetooth-...

  • iOS蓝牙实现

    iOS 中使用 Core Bluetooth 框架实现蓝牙通信。Core Bluetooth 是基于蓝牙 4.0 ...

  • iOS 蓝牙开发 - 学习

    iOS 中使用 Core Bluetooth 框架实现蓝牙通信。Core Bluetooth 是基于蓝牙 4.0 ...

  • Android-蓝牙(Bluetooth)

    蓝牙(Bluetooth) 蓝牙(Bluetooth)是一种短距离的无线通信技术标准。 蓝牙协议 蓝牙协议分为4层...

  • 关于BLE需要知道的

    Bluetooth Low Energy 1、蓝牙协议 蓝牙( Bluetooth® )是一种无线技术标准,可实现...

  • iOS学习-蓝牙

    一、Core Bluetooth iOS中使用Core Bluetooth这个框架来进行蓝牙的开发支持蓝牙4.0,...

网友评论

  • 搬砖的哈哈:为啥6s ios12 扫描不到外围蓝牙
  • 阿飞_1217:链接打印机 打印汉字乱码 怎么搞呢
    a67251d52b88:@阿飞_1217 现在这块搞定了,但是卡在打印二维码那儿了,不知道write()该传什么样的数据,搜也搜不到。。你有做过么?
    阿飞_1217:@流浪的贝壳 你确定是配对成功了? 还是链接成功了?
    a67251d52b88:哥们,我手机明明蓝牙连到打印机了,但是isConnected()还是返回无连接,你有过这种情况么?

本文标题:(蓝牙串口)Bluetooth Serial

本文链接:https://www.haomeiwen.com/subject/trdbcxtx.html