[英]chrome.hid.send fails on second use
Something about my use of chrome.hid.send
seems to be leaving the bus in a bad state. 我对chrome.hid.send
使用似乎使总线处于不良状态。 I consistently can NOT get my second usage of the API call to work. 我始终无法使我的API调用再次起作用。 Sometimes, it will also fail on the first usage. 有时,它在第一次使用时也会失败。 WITH THE EXACT SAME CODE, I can come back and try a while later (maybe 10min) and the first send will work. 使用完全相同的代码,我可以再试一会(也许10分钟),然后第一次发送就可以了。
The device I'm working with does not return a response to all messages sent to it. 我正在使用的设备不会对发送给它的所有消息返回响应。 The test message for example, is just a dummy message that is ignored by the device. 例如,测试消息只是设备忽略的虚拟消息。 I've tested this both on a mac and a PC. 我已经在Mac和PC上进行了测试。 My call stack depth is 2 at this point in my application (literally first one is kicked off by a button click and then a setTimeout
calls the same method 5s later). 在我的应用程序中,我的调用堆栈深度为2(实际上,第一个通过单击按钮开始,然后setTimeout
在5s之后调用相同的方法)。
I've testing sending buffers of length 64Bytes as well as 58Bytes. 我正在测试发送缓冲区的长度为64Bytes和58Bytes。 The properties from the HidDeviceInfo object read "maxInputReportSize":64,"maxOutputReportSize":64 HidDeviceInfo对象的属性读取为“ maxInputReportSize”:64,“ maxOutputReportSize”:64
Params on first usage: 首次使用的参数:
Params on second usage: 二次使用的参数:
I really can't identify how I'm using the API incorrectly. 我真的无法确定我如何错误地使用API。 When messages do succeed, I can see them on the device side. 当消息确实成功时,我可以在设备端看到它们。
// 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();
The issue is that Windows requires buffers to be the full report size expected by the device. 问题是Windows要求缓冲区必须是设备期望的完整报告大小。 I have filed a bug against Chromium to track adding a workaround or at least a better error message to pinpoint the problem. 我针对Chromium提交了一个错误 ,以跟踪添加变通办法或至少找到更好的错误消息来查明问题。
In general you can get more detailed error messages from the chrome.hid API by enabling verbose logging with the --enable-logging --v=1
command line options. 通常,通过使用--enable-logging --v=1
命令行选项启用详细日志记录,您可以从chrome.hid API中获取更详细的错误消息。 Full documentation of Chrome logging is here . 有关Chrome日志记录的完整文档,请参见此处 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.