2014-10-18 71 views
0

我沒有在我的Chrome應用程序和一個簡單的設備之間發生任何傳輸,只是等待數據進入其uart rx行。該設備的接口端點類型爲bulk,儘管我嘗試了所有可用的傳輸類型(control,bulk,isochronousinterrupt)。來自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); 
    }); 
}; 
+0

您是否嘗試過退出Chrome?如果您一直在調試代碼,則很難確定Chrome進程處於哪種狀態。退出Chrome(並確保您確實已退出計算機上的每個Chrome進程)會重置狀態。 – sowbug 2014-10-18 03:52:00

回答