HarmonyOS usbManager.claimInterface返回-1?

1、getDevices返回设备列表,里面有对一个设备;

2、requestRight返回true;

3、connectDevice返回了USBDevicePipe;

4、读写需要的UsbEnpoint也已经找到;

5、setConfiguration返回0;

6、claimInterface返回-1;

let devicesList: Array<usbManager.USBDevice> = usbManager.getDevices();
devicesList.forEach((value: usbManager.USBDevice) => {

  if (value.vendorId == 0x5000 && value.productId == 0x500) {
    console.log("openDevice this._device 1");
    this._device = value
    return
  }
})
let right = usbManager.hasRight(this._device.name)
console.log("device hasRight " + right); //此处第一次返回false,requestRight后返回true
this._devicepipe = usbManager.connectDevice(this._device)
this._deviceInterface = this._device!!.configs[0].interfaces[0];
let endpoints = this._deviceInterface.endpoints
console.log("device endpoints " + endpoints.length); //有值
this._usbOut = endpoints.find(endpoint => endpoint.direction ==
  0)
console.log("usbOut " + JSON.stringify(this._usbOut)); //有值
this._usbIn = endpoints.find(endpoint => endpoint.direction ==
  128)
console.log("usbIn " + JSON.stringify(this._usbIn)); //有值
let config: usbManager.USBConfiguration = this._device!!.configs[0];
let ret1 = usbManager.setConfiguration(this._devicepipe, config);
console.log("device setConfiguration ret1 " + ret1); //返回0
let ret2: number = usbManager.claimInterface(this._devicepipe, this._deviceInterface);
console.log("device claimInterface ret2 " + ret2); //返回-1
ret2 = usbManager.setInterface(this._devicepipe, this._deviceInterface);
console.log("device setInterface ret2 " + ret2); //返回-1
阅读 546
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进