繁体   English   中英

chrome.hid.send在第二次使用时失败

[英]chrome.hid.send fails on second use

我对chrome.hid.send使用似乎使总线处于不良状态。 我始终无法使我的API调用再次起作用。 有时,它在第一次使用时也会失败。 使用完全相同的代码,我可以再试一会(也许10分钟),然后第一次发送就可以了。

我正在使用的设备不会对发送给它的所有消息返回响应。 例如,测试消息只是设备忽略的虚拟消息。 我已经在Mac和PC上进行了测试。 在我的应用程序中,我的调用堆栈深度为2(实际上,第一个通过单击按钮开始,然后setTimeout在5s之后调用相同的方法)。

我正在测试发送缓冲区的长度为64Bytes和58Bytes。 HidDeviceInfo对象的属性读取为“ maxInputReportSize”:64,“ maxOutputReportSize”:64

首次使用的参数:

在此处输入图片说明

二次使用的参数:

在此处输入图片说明

我真的无法确定我如何错误地使用API​​。 当消息确实成功时,我可以在设备端看到它们。

// 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;
  var dummyUint8Array = new Uint8Array(outData);
  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);
      });
    }
  });
}


// Example usage
var testMessage = new Uint8Array(58);
var testTransmission = function() {
  message[0] = 123;
  COMMS.send(message.buffer, null, null);
  setTimeout(testTransmission, 5000);
};
testTranmission();

问题是Windows要求缓冲区必须是设备期望的完整报告大小。 我针对Chromium提交了一个错误 ,以跟踪添加变通办法或至少找到更好的错误消息来查明问题。

通常,通过使用--enable-logging --v=1命令行选项启用详细日志记录,您可以从chrome.hid API中获取更详细的错误消息。 有关Chrome日志记录的完整文档,请参见此处

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM