2014-12-02 120 views
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); 
     }); 
    } 
    }); 
} 
+0

什麼類型的HID設備?它的USB描述符是什麼說最大的數據包大小是? – duskwuff 2014-12-02 19:54:08

+0

不幸的是一個自定義設備。來自HidDeviceInfo對象的屬性讀取「maxInputReportSize」:64,「maxOutputReportSize」:64 – tarabyte 2014-12-02 20:02:25

+0

設備本身可能有故障嗎?你確定它可以接受並正確處理64字節的數據包嗎? – duskwuff 2014-12-02 22:01:08

回答

0

對於一個設備的屬性從HidDeviceInfo改爲"maxInputReportSize":64,"maxOutputReportSize":64,那裏似乎不是chrome.hid.send施加的額外限制。但似乎有些東西是錯誤的。

使用OP中的方法,我可以成功發送一條消息,提示從設備返回。我目前無法僅發送傳出消息。我希望chrome.lastError.messageTransfer Failed更詳細一些。

相關問題