Web usb transfer data from device to browser not working

2k views Asked by At

enter image description here

Above is my device configuration.I am trying to get data from it ,I am using below code to to get the data

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

}

I am selecting the endPointnumber ,and the interface correctly but it doesn't seems to work ,am I missing something here ? .Please help .I am not getting any error ,device seems to connected but the data transfer is not happening from machine to browser.

I saw this question it has same exact scenario as mine WEBUSB getting serial data PL2303

But in my case I am not getting any data even .

I tried this driver https://github.com/tidepool-org/pl2303 in node js and it worked ,but I want to do it web usb api .

Edit -I worked on the it ,and now the data seems to be coming continuously

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

The only problem ,I am facing write now is the data transfer doesn't starts until some data is sent to the device ,when i am using node js driver to to send the data ,it works and I receive the data ,but only with web usb api it doesn't work

0

There are 0 answers