5

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

gANDALF
  • 360
  • 4
  • 21
  • How do you know that the device will produce data on that endpoint? Could it require a command sent on endpoint 2 first? Does it produce data when a button is pressed? – Reilly Grant Sep 26 '20 at 02:22
  • I have checked the manual ,the data flow is continuous .There is no data to be sent first @ReillyGrant :( – gANDALF Sep 28 '20 at 10:45
  • If you look at the Tidepool code there is an initialization sequence required to configure the device with baud rate and other parameters. – Reilly Grant Sep 29 '20 at 16:18
  • what do these lines ` console.log(device); console.log(JSON.stringify(device));` print? – Saar Davidson Oct 03 '20 at 10:20
  • th einformation in the image attached – gANDALF Oct 03 '20 at 12:21
  • I can get the data ,but I dnt know the process doesn't starts automatically .I think some data needs to be sent to the device to start the data flow and I dnt know what data is to be sent – gANDALF Oct 03 '20 at 15:50

0 Answers0