2014-12-03 2 views
1

내 용도에 대해 chrome.hid.send이 나쁜 상태로 버스를 떠나는 것 같습니다. 일관되게 작동하도록 API 호출을 두 번째로 사용할 수 없습니다. 때로는 첫 번째 사용시에도 실패합니다. 정확히 같은 코드를 사용하면 나중에 돌아와서 (아마도 10 분) 한 번 시도해 볼 수 있으며 첫 번째 전송이 작동합니다.두 번째 사용시 chrome.hid.send가 실패합니다.

내가 사용중인 장치가 보낸 모든 메시지에 대한 응답을 반환하지 않습니다. 예를 들어, 테스트 메시지는 장치에 의해 무시되는 단순한 메시지입니다. 나는이 두 Mac 및 PC에서 테스트했습니다. 내 응용 프로그램의이 시점에서 통화 스택 깊이는 2입니다 (첫 번째 문자는 버튼 클릭으로 시작되고 setTimeout은 5 초 후에 동일한 메소드를 호출 함).

길이가 64Bytes이고 버퍼 크기가 58Bytes 인 송신 버퍼를 테스트했습니다. 64 "maxOutputReportSize": 제 사용량 64 개

에 Params : 제 사용량에

enter image description here

에 Params :

enter image description here

HidDeviceInfo 객체의 속성은 "maxInputReportSize"를 읽어 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(); 
+0

몇 가지 질문이 있습니다. 실행중인 Chrome 버전은 무엇입니까? 두 번째 사용의 결과는 무엇입니까? 콜백이 실행되지 않았습니까? chrome.runtime.lastError가 오류로 설정 되었습니까? –

+0

버전 41.0.2240.0 카나리아 (64 비트). 그것이 실패하고 onTxCompleted에 대한 메소드를 지정하면, 전달 된 콜백은 잘 실행됩니다. – tarabyte

+0

나는 또한 안정되어있는 (일정한) 크롬에있는 문제를 역시 얻는다. – tarabyte

답변

2

문제는 Windows에서 버퍼가 장치에서 예상하는 전체 보고서 크기가되어야한다는 것입니다. 해결 방법 추가를 추적하거나 문제를 정확히 지적하기 위해 더 나은 오류 메시지를 표시하기 위해 Chromium에 a bug을 제출했습니다.

일반적으로 --enable-logging --v=1 명령 줄 옵션으로 자세한 로깅을 사용하도록 설정하면 chrome.hid API에서 자세한 오류 메시지를 가져올 수 있습니다. Chrome 로깅에 대한 전체 문서는 here입니다.

관련 문제