readBlueToothData 读取蓝牙设备的数据

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)
    })

#返回参数

// 设备状态推送,返回数据格式:
{ 
    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:"失败原因描述"
}
posted on 2024-12-16 09:44  AtlasLapetos  阅读(19)  评论(0)    收藏  举报