내 용도에 대해 chrome.hid.send
이 나쁜 상태로 버스를 떠나는 것 같습니다. 일관되게 작동하도록 API 호출을 두 번째로 사용할 수 없습니다. 때로는 첫 번째 사용시에도 실패합니다. 정확히 같은 코드를 사용하면 나중에 돌아와서 (아마도 10 분) 한 번 시도해 볼 수 있으며 첫 번째 전송이 작동합니다.두 번째 사용시 chrome.hid.send가 실패합니다.
내가 사용중인 장치가 보낸 모든 메시지에 대한 응답을 반환하지 않습니다. 예를 들어, 테스트 메시지는 장치에 의해 무시되는 단순한 메시지입니다. 나는이 두 Mac 및 PC에서 테스트했습니다. 내 응용 프로그램의이 시점에서 통화 스택 깊이는 2입니다 (첫 번째 문자는 버튼 클릭으로 시작되고 setTimeout
은 5 초 후에 동일한 메소드를 호출 함).
길이가 64Bytes이고 버퍼 크기가 58Bytes 인 송신 버퍼를 테스트했습니다. 64 "maxOutputReportSize": 제 사용량 64 개
에 Params : 제 사용량에
에 Params :
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();
몇 가지 질문이 있습니다. 실행중인 Chrome 버전은 무엇입니까? 두 번째 사용의 결과는 무엇입니까? 콜백이 실행되지 않았습니까? chrome.runtime.lastError가 오류로 설정 되었습니까? –
버전 41.0.2240.0 카나리아 (64 비트). 그것이 실패하고 onTxCompleted에 대한 메소드를 지정하면, 전달 된 콜백은 잘 실행됩니다. – tarabyte
나는 또한 안정되어있는 (일정한) 크롬에있는 문제를 역시 얻는다. – tarabyte