问题描述
我正在调用python api端点,该端点向我发送要写入设备的数据。接收到的数据是加密格式,我正在使用下面的方法将其转换为字节数组
let codePoints = [];
for (let i = 0; i < encData.length; i++) {
codePoints.push(encData.codePointAt(i));
}
const arraybufferdata = Uint8Array.from(codePoints);
我正在尝试使用以下代码编写此字节数组:
characteristic
.writeValueWithoutResponse(arraybufferdata)
.then(() => {
console.log("successfully written to the device");
});
我收到以下错误:
我还尝试通过如下方式将字节数组分成多个块来进行编写:
writeOut(data,start) {
if (start >= data.byteLength) {
console.log("successfully written to the device");
return;
}
this.mychar
.writeValueWithoutResponse(data.slice(start,start + 256))
.then(() => {
this.writeOut(data,start + 256);
});
}
writeBuffer(data,start) {
this.writeOut(data,start);
}
this.writeBuffer(arraybufferdata,0);
这也引发错误。可能是什么问题?设备也不接受要写入的数据。
UI框架:Angular 7 作业系统:Windows 10 浏览器:Chrome 85
请帮助!
解决方法
发现了问题:
我写的是错误的特征! (facepalm)
现在正在工作!