bulkTransfer“传输失败。”
问题描述:
我没有在我的Chrome应用程序和一个简单的设备之间发生任何传输,只是等待数据进入其uart rx行。该设备的接口端点类型为bulk
,尽管我尝试了所有可用的传输类型(control
,bulk
,isochronous
和interrupt
)。来自here的示例。我也尝试过声称该设备,但如果使用findDevices
,则该设备似乎不适用,并且也会失败。bulkTransfer“传输失败。”
我假设通过查找设备,我知道它已被发现,权限是确定的,它已被打开确定。
我在Mac上使用的是UART-to-USB adapter。我已经使用pysusb和python脚本对相同的硬件设置进行了讲话,所以我知道它可以完成。
var DEVICE_INFO = {"vendorId": 1027, "productId": 24577};
var searchForUsbDevice = function() {
chrome.usb.findDevices(DEVICE_INFO, onDeviceFound);
}
var onDeviceFound = function(devices) {
if (devices) {
if (0 < devices.length) {
if (1 === devices.length) {
device_ = devices[0];
console.log("Device found. And opened?");
getInterfaces();
getConfiguration();
//claimDevice();
investigateDevice();
} else {
console.log("Ensure one and ONLY ONE device is plugged in.");
}
} else {
console.log("Device could not be found");
setTimeout(searchForUsbDevice, 1000);
}
} else {
console.log("Permission denied.");
}
};
var investigateDevice = function() {
testBulkTransfer();
//testIsochronousTransfer();
//testInterruptTransfer();
//testControlTransfer();
setTimeout(investigateDevice, 1000);
};
var testBulkTransfer = function() {
var transferInfo = {
"direction": "out",
"endpoint": 1,
"data": new Uint8Array([32, 2, 1, 2]).buffer
};
chrome.usb.bulkTransfer(device_, transferInfo, function(info) {
if (chrome.runtime.lastError) {
console.log("info: " + JSON.stringify(info));
console.log("runtime error: " + JSON.stringify(chrome.runtime.lastError.message));
return;
}
console.log("transfer result: " + ((0 === info.resultCode) ? "succeeded" : "failed"));
});
};
var getConfiguration = function() {
chrome.usb.getConfiguration(device_, function(config) {
if (chrome.runtime.lastError) {
console.log("runtime error: " + JSON.stringify(chrome.runtime.lastError.message));
return;
}
console.log("config: ");
console.log(config);
});
};
var getInterfaces = function() {
chrome.usb.listInterfaces(device_, function(descriptors) {
if (chrome.runtime.lastError) {
console.log("runtime error: " + JSON.stringify(chrome.runtime.lastError.message));
return;
}
console.log("descriptors: ");
console.log(descriptors);
});
};
您是否尝试过退出Chrome?如果您一直在调试代码,则很难确定Chrome进程处于哪种状态。退出Chrome(并确保您确实已退出计算机上的每个Chrome进程)会重置状态。 – sowbug 2014-10-18 03:52:00