Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript WebBluetooth在Windows(但不是OSX)上的写入特性失败_Javascript_Google Chrome_Bluetooth_Web Bluetooth - Fatal编程技术网

Javascript WebBluetooth在Windows(但不是OSX)上的写入特性失败

Javascript WebBluetooth在Windows(但不是OSX)上的写入特性失败,javascript,google-chrome,bluetooth,web-bluetooth,Javascript,Google Chrome,Bluetooth,Web Bluetooth,我正在尝试通过web蓝牙向可编程设备发送一个十六进制字符串示例 这个字符串在OSX上发送得非常好,但是当我尝试在windows上发送它时,我得到以下错误: Uncaught (in promise) DOMException: GATT operation failed for unknown reason. 下面是我用来发送字符串并将其转换的代码: event.target.writeValue(str2ab(":100000000C9434000C943E000C943E0

我正在尝试通过web蓝牙向可编程设备发送一个十六进制字符串示例

这个字符串在OSX上发送得非常好,但是当我尝试在windows上发送它时,我得到以下错误:

Uncaught (in promise) DOMException: GATT operation failed for unknown reason.
下面是我用来发送字符串并将其转换的代码:

        event.target.writeValue(str2ab(":100000000C9434000C943E000C943E000C943E0082*"));
以下是我的str2ab函数:

 function str2ab(str) {
  var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
  var bufView = new Uint16Array(buf);
  for (var i=0, strLen=str.length; i<strLen; i++) {
    bufView[i] = str.charCodeAt(i);
  }
  return buf;
}
函数str2ab(str){
var buf=new ArrayBuffer(str.length*2);//每个字符2个字节
var bufView=新UINT16阵列(buf);

对于(var i=0,strLen=str.length;i,所以对于windows,似乎有20字节的限制

为了纠正这个问题,我使用了一个写缓冲区,并递归地检查它,直到所有的比特都被写入

function writeBuffer(string) {
  writeOut(string, 0);
}

function writeOut(string, start) {
  if(start >= string.length) return;
  myCharacteristic.writeValue(str2ab(string.substring(start, (start+20)))).then(foo => {
    writeOut(string, (start+20));
  });
}

我在Windows上也看到了同样的问题,你并不孤单!@EL45我已经将问题缩小到Windows上一次只能发送20个字节!我将重写发送数据的方式并将其作为解决方案发布。@EL45我刚刚发布了一个修复程序!你在哪里发现Windows有20个字节的限制?