• Lv0
    粉丝0

积分2 / 贡献0

提问1答案被采纳0文章0

作者动态

    ArkTS usbManager.bulkTransfer API 与设备通信失败,数据无法发送成功 精华

    young8 显示全部楼层 发表于 2024-3-7 18:58:30

    执行usb.bulkTransfer 错误, 下面是日志打印 错误,这是什么错误? 请大神给看看

    image.png

    附代码实现,

     initCard() {
        let devicesList: Array<usb.USBDevice> = usb.getDevices();
        console.log(`devicesList = ${devicesList}`);
        for (let index = 0; index < devicesList.length; index++) {
          const device = devicesList[index];
          if (device.vendorId == 1285) {
            let right: boolean = usb.hasRight(device.name);
            if (!right) {
              usb.requestRight(device.name).then((ret) => {
                if (ret) {
                  this.initRfid(device)
                }
              });
            } else {
              this.initRfid(device)
            }
          }
        }
      }
    initRfid(device) {
        usbDevicePipe = usb.connectDevice(device);
        interfaces = device.configs[0].interfaces[0];
        let ret1 = usb.releaseInterface(usbDevicePipe, interfaces);
        let cret: number = usb.claimInterface(usbDevicePipe, interfaces, true);
        if (cret != 0) {
          return
        }
        let outEndpoint: usb.USBEndpoint = interfaces.endpoints[0].direction == 0 ? interfaces.endpoints[0] : interfaces.endpoints[1];
        let inEndpoint: usb.USBEndpoint = interfaces.endpoints[0].direction == 0 ? interfaces.endpoints[1] : interfaces.endpoints[0];
    
        var arr = '117E550E00000100F400120100B7010032D8'
        var buffer = new Uint8Array(arr.match(/[\da-f]{2}/gi).map(function (h) {
          return parseInt(h, 16)
        }))
        let param = {
          request: 0,
          reqType: 0,
          target: 0,
          value: 0,
          index: 0,
          data: new Uint8Array(18)
        };
        usb.bulkTransfer(usbDevicePipe, outEndpoint, buffer, 15000).then((ret: number) => {
          if (ret == -1) {
            prompt.showToast({
              message: "配置读写器失败!"
            });
          } else {
            prompt.showToast({
              message: "打开配置读写器成功!"
            });
    
          }
        }).catch((error) => {
          console.info("usb writeData error : " + JSON.stringify(error));
        });
      }

    您尚未登录,无法参与评论,登录后可以:
    参与开源共建问题交流
    认同或收藏高质量问答
    获取积分成为开源共建先驱

    Copyright   ©2023  OpenHarmony开发者论坛  京ICP备2020036654号-3 |技术支持 Discuz!

    返回顶部