1
docs似乎沒有提到任何這樣的限制,但當我嘗試發送一個64字節長的消息時出現奇怪的錯誤。所有其他消息傳輸似乎工作正常。chrome.hid.send的ArrayBuffer大小是否有限制?
不,我認爲這是真正的問題有關被問,但這裏是我send
萬一COMMS
命名空間中的方法有一個明顯的錯誤,我應該知道的:
// 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);
});
}
});
}
什麼類型的HID設備?它的USB描述符是什麼說最大的數據包大小是? – duskwuff 2014-12-02 19:54:08
不幸的是一個自定義設備。來自HidDeviceInfo對象的屬性讀取「maxInputReportSize」:64,「maxOutputReportSize」:64 – tarabyte 2014-12-02 20:02:25
設備本身可能有故障嗎?你確定它可以接受並正確處理64字節的數據包嗎? – duskwuff 2014-12-02 22:01:08