[英]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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.