用微信小程序转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)
},
Geewoo_c
你也是这个问题?
2023-06-14 20:27