bulkTransfer“转移失败。”

时间:2014-10-18 00:06:37

标签: javascript google-chrome-app

我的Chrome应用程序和一个简单的设备之间没有任何类型的转移,只是等待数据进入其uart rx线。设备界面的端点类型为bulk,但我已尝试了所有可用的转移类型(controlbulkisochronousinterrupt)。来自here的示例。我也试过声称使用该设备,但如果使用findDevices这似乎不适用,并且也失败了。

我假设通过查找设备,我知道它已被发现,权限已经确定并且已经打开确定。

我在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);
  });
};

1 个答案:

答案 0 :(得分:1)

该UART-to-USB适配器的相应API为chrome.serial,而非chrome.usb

https://developer.chrome.com/apps/app_serial