微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用Web蓝牙API将495字节数组的长度写入设备

如何解决使用Web蓝牙API将495字节数组的长度写入设备

我正在调用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");
});

我收到以下错误

enter image description here

我还尝试通过如下方式将字节数组分成多个块来进行编写:

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)

现在正在工作!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。