# readBlueToothData ^7.6.0

读取蓝牙设备的数据

# 请求参数

Prop Type Default Description
param Object mac: "xxxx"//蓝牙mac地址,
serviceUuid: "xxxx"//服务通道的uuid,
readUuid: "xxxx"//写通道的uuid,
请求参数

# 接口调用示例


this.$bridge
    .readBlueToothData(params)
    .then(res => {    
    this.$alert(res)
    })
    .catch(err => {
    this.$toast(err)
    })
1
2
3
4
5
6
7
8
9

# 返回参数

// 设备状态推送,返回数据格式:
{ 
    messageType: "receivebuletoothData",
    messageBody: { mac:"xxx", data: "xxx",serviceUuid: "xxx",readUuid: "xxx" } 
}

const globalEvent = weex.requireModule('globalEvent')
 
export default {
.....   
created() {
    // 监听设备状态推送
    globalEvent.addEventListener('receiveMessageFromApp', (response) => {
        // 业务逻辑
        let { messageType, messageBody } = response
        if (messageType == 'receivebuletoothData'){
            console.log(messageBody)
        }
    })
}
.....
}

// Promise then 链式方式    
callback:result{
    errorCode:0 //读取成功
}
callbackFail:{
    errorCode:1, //读取失败、2蓝牙未连接
    errorMsg:"失败原因描述"
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Last Updated: 6/16/2021, 2:02:29 PM