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

时间:2014-12-02 19:50:30

标签: javascript google-chrome-app hid

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

并不是说我认为这与被问到的问题非常相关,但是这里是我send命名空间中的COMMS方法,以防出现明显错误,我应该注意:< / p>

// 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);
      });
    }
  });
}

1 个答案:

答案 0 :(得分:0)

对于HidDeviceInfo读取"maxInputReportSize":64,"maxOutputReportSize":64属性的设备,似乎不是chrome.hid.send强加的额外限制。但看似有些事情错了。

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