Web USB将数据从设备传输到浏览器不起作用

问题描述

enter image description here

上面是我的设备配置。我试图从中获取数据,我正在使用下面的代码获取数据

document.getElementById("request").onclick = function() {

  navigator.usb.requestDevice({
      filters: [{
        vendorId: 1659
      }]
    })
    .then((requestedDevice) => {
      device = requestedDevice;
    }).then(() => {
      console.log(device);
      console.log(JSON.stringify(device));
      return device.open();
    }).then(() => device.selectConfiguration(1)) // Select configuration #1 for the device.
    .then(() => {

      return device.reset();
    }).then(() => device.claimInterface(0))
    .then(() => {

      return device.transferIn(3,64)
    })
    .then((data) => {
      debugger;
      console.log(data)

    }).catch(err => {
      console.log(err);
    });

}

我正在选择endPointnumber,并且接口正确,但是它似乎不起作用,我在这里缺少什么吗?请帮忙。我没有收到任何错误消息,设备似乎已连接,但没有发生从机器到浏览器的数据传输。

我看到了这个问题,它与我的WEBUSB getting serial data PL2303具有相同的情况

但就我而言,我什至没有任何数据。

我在node js中尝试了该驱动程序https://github.com/tidepool-org/pl2303,它可以工作,但是我想通过web usb api来实现。

编辑-我正在处理它,现在数据似乎一直在不断发送

async function Get()
{

  let device= await navigator.usb.requestDevice({ filters: [{ vendorId: 0x067b,productId:0x2303 }]})
console.log(device);
  await device.open({ baudrate: 9600 });
  await device.selectConfiguration(1);
  await device.claimInterface(0);

while(true)
{

  let result =  await device.transferIn(3,64);
  
  var string = new TextDecoder("utf-8").decode(result.data.buffer);

console.log("hii",string);
}

唯一的问题,我现在面临的问题是,当我使用node js驱动程序发送数据时,直到将某些数据发送到设备后,数据传输才开始,并且可以正常工作,并且我接收到数据,但只有使用Web USB API才能正常工作

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)