chrome.hid.send的ArrayBuffer大小是否有限制

Is there a limit to the ArrayBuffer size of chrome.hid.send?

本文关键字:是否 有限制 ArrayBuffer hid send chrome      更新时间:2023-09-26

文档似乎没有提到任何此类限制,但是当我尝试发送64字节长的消息时,我遇到了奇怪的错误。 所有其他邮件传输似乎都可以正常工作。

并不是说我认为它与所问的问题真正相关,但这是我在 COMMS 命名空间中的send方法,以防出现我应该注意的明显错误:

// Transmits the given data
//
// @param[in] outData,       The data to send as an ArrayBuffer
// @param[in] onTxCompleted, The method called on completion of the outgoing transfer.  The return
//                           code is passed as a string.
// @param[in] onRxCompleted, The method called on completion of the incoming transfer.  The return
//                           code is passed as a string along with the response as an ArrayBuffer.
send: function(outData, onTxCompleted, onRxCompleted) {
  if (-1 === connection_) {
    console.log("Attempted to send data with no device connected.");
    return;
  }
  if (0 == outData.byteLength) {
    console.log("Attempted to send nothing.");
    return;
  }
  if (COMMS.receiving) {
    console.log("Waiting for a response to a previous message.  Aborting.");
    return;
  }
  if (COMMS.transmitting) {
    console.log("Waiting for a previous message to finish sending.  Aborting.");
    return;
  }
  COMMS.transmitting = true;
  chrome.hid.send(connection_, REPORT_ID, outData, function() {
    COMMS.transmitting = false;
    if (onTxCompleted) {
      onTxCompleted(chrome.runtime.lastError ? chrome.runtime.lastError.message : '');
    }
    if (chrome.runtime.lastError) {
      console.log('Error in COMMS.send: ' + chrome.runtime.lastError.message);
      return;
    }
    // Register a response handler if one is expected
    if (onRxCompleted) {
      COMMS.receiving = true;
      chrome.hid.receive(connection_, function(reportId, inData) {
        COMMS.receiving = false;
        onRxCompleted(chrome.runtime.lastError ? chrome.runtime.lastError.message : '', inData);
      });
    }
  });
}
对于其

属性从HidDeviceInfo读取"maxInputReportSize":64,"maxOutputReportSize":64的设备,似乎没有chrome.hid.send施加的额外限制。 但似乎确实有些不对劲。

使用 OP 中的方法,我可以成功发送一条消息,提示从设备返回。 我目前无法仅发送传出消息。 我希望chrome.lastError.messageTransfer Failed更详细一点。