l***@163.com
l***@163.com
  • 发布:2024-12-30 14:23
  • 更新:2024-12-30 14:32
  • 阅读:58

【报Bug】uni.writeBLECharacteristicValue这个Api发送数据过长时不会正确报错

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: windows10

HBuilderX类型: 正式

HBuilderX版本号: 4.43

手机系统: Android

手机系统版本号: Android 14

手机厂商: vivo

手机机型: vivox 70

页面类型: vue

vue版本: vue3

打包方式: 云端

项目创建方式: HBuilderX

示例代码:

command的长度超过300的时候就会出现这个问题


    async writeBLECharacteristicValue({  
        commit,  
        state  
    }, command) {  
        try {  
            let value = str2ab(command)  
            const response = await new Promise((resolve, reject) => {  
                uni.writeBLECharacteristicValue({  
                    deviceId: state.deviceId,  
                    serviceId: state.serviceId,  
                    characteristicId: state.writeCharacteristicId,  
                    value: value,  
                    writeType: "writeNoResponse",  
                    success: resolve,  
                    fail: reject  
                })  
            })  
            uni.showLoading({  
                title: "指令发送成功",  
                mask: true  
            })  
            commit("SET_COMMAND", command)  
            console.log("发送指令成功回调", response)  
            console.log("发送指令成功", command)  
            console.log("value", value)  
        } catch (e) {  
            console.log(e)  
            console.log("发送指令失败", command)  
            //TODO handle the exception  
        }  

    }  

```js

操作步骤:

command的长度超过300的时候就会出现这个问题


    async writeBLECharacteristicValue({  
        commit,  
        state  
    }, command) {  
        try {  
            let value = str2ab(command)  
            const response = await new Promise((resolve, reject) => {  
                uni.writeBLECharacteristicValue({  
                    deviceId: state.deviceId,  
                    serviceId: state.serviceId,  
                    characteristicId: state.writeCharacteristicId,  
                    value: value,  
                    writeType: "writeNoResponse",  
                    success: resolve,  
                    fail: reject  
                })  
            })  
            uni.showLoading({  
                title: "指令发送成功",  
                mask: true  
            })  
            commit("SET_COMMAND", command)  
            console.log("发送指令成功回调", response)  
            console.log("发送指令成功", command)  
            console.log("value", value)  
        } catch (e) {  
            console.log(e)  
            console.log("发送指令失败", command)  
            //TODO handle the exception  
        }  

    }  

```js

预期结果:

如果成功请提示发送成功,因为过长发送失败请提示发送失败

实际结果:

无论什么情况都是成功

bug描述:

当使用uni.writeBLECharacteristicValue这个api时,当传输的数据过长时,会提示成功,但是实际上并没有成功。
command的长度超过300的时候就会出现这个问题


    async writeBLECharacteristicValue({  
        commit,  
        state  
    }, command) {  
        try {  
            let value = str2ab(command)  
            const response = await new Promise((resolve, reject) => {  
                uni.writeBLECharacteristicValue({  
                    deviceId: state.deviceId,  
                    serviceId: state.serviceId,  
                    characteristicId: state.writeCharacteristicId,  
                    value: value,  
                    writeType: "writeNoResponse",  
                    success: resolve,  
                    fail: reject  
                })  
            })  
            uni.showLoading({  
                title: "指令发送成功",  
                mask: true  
            })  
            commit("SET_COMMAND", command)  
            console.log("发送指令成功回调", response)  
            console.log("发送指令成功", command)  
            console.log("value", value)  
        } catch (e) {  
            console.log(e)  
            console.log("发送指令失败", command)  
            //TODO handle the exception  
        }  

    }  

```js
2024-12-30 14:23 负责人:无 分享
已邀请:
l***@163.com

l***@163.com (作者)

有人看到吗,回复一下呗

要回复问题请先登录注册