2014-12-02 123 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更详细一些。

相关问题