3***@qq.com
3***@qq.com
  • 发布:2022-10-15 23:44
  • 更新:2023-06-14 18:01
  • 阅读:746

uniapp蓝牙发送数据显示:"code":10013,"message":"invalid data,please check parameters"

分类:uni-app

用微信小程序转uniapp 发送数据时总是显示数据格式错误,同样的数据格式,小程序是正常的,uniapp不行,有谁知道问题吗?“代码如下:

gosend() {
if (!this.connected) {
this.showModalTips('请先连接BLE设备...');
return;
}

        var that = this;  
        var hex = this.sendText; //要发送的数据  
        var buffer1=new ArrayBuffer(8);  

        if (this.hexSend) {       
            //十六进制发送  
            var typedArray = new Uint8Array(hex.match(/[\da-f]{2}/gi).map(function (h) {  
                    return parseInt(h, 16);  
                })  
            );  
            console.log('hextobyte ', typedArray);  
            buffer1 = typedArray.buffer;  
        } else {  
            //string发送  

            var strbuf = new Uint8Array(stringToBytes(hex));  
            console.log('strtobyte ', strbuf);  
            buffer1 = strbuf.buffer;      
        }                 

        console.log('buffer1 = ', buffer1);  
       if (buffer1 == null) {  
            return;  
        }  
        const txlen = buffer1.byteLength;  
        console.log('txlen = ', txlen);  
        setTimeout(()=>{  
        plus.bluetooth.writeBLECharacteristicValue({  
        //uni.writeBLECharacteristicValue({  
            deviceId:this.deviceId,  
            serviceId:this.serviceId,  
            characteristicId: this.characteristicId,  
             value: buffer1,  

            success: function (res) {  
                // success  

                that.setData({  
                    txCount: that.txCount + txlen,  
                    timTX: that.timTX + txlen  
                });  
                console.log('success  指令发送成功');  
                console.log(res);  
            },  

            fail: function (res) {  
                // fail  
                console.log(res);  
                console.log('fail  指令发送失败');                      
            },  
            complete: function (res) {  
                // complete  
                 console.log('complete  指令发送完成');     
            }  
        });  
     },300)   
    },
2022-10-15 23:44 负责人:无 分享
已邀请:
8***@qq.com

8***@qq.com

大佬,问题解决了吗?

  • Geewoo_c

    你也是这个问题?

    2023-06-14 20:27

要回复问题请先登录注册