WICG / serial

Serial ports API for the platform.
https://wicg.github.io/serial/
Other
255 stars 46 forks source link

Inconsistent Web USB Communication on Windows Machines #201

Closed sagar-bhedodkar closed 2 months ago

sagar-bhedodkar commented 2 months ago

I use the web usb for communication with the usb device having three sensors. It working fine on some of the windows and all mac os machines. But in some windows machine it get lags and sometimes works fine in same machine. I capture the data continuously. So what is the problem in this. The code which is use is below :

const CMD1 = new Uint8Array([78, 84, 83, 83, 84, 65, 82, 84, 76, 238, 167, 78, 84, 69]);

const CMD2 = new Uint8Array([78, 84, 83, 83, 84, 65, 82, 84, 68, 40, 166, 78, 84, 69]);

var port = null;
port = await navigator.serial.requestPort();
await port.open({
  baudRate: 115200
});
var selectedDevice = port.getInfo();
if (selectedDevice.usbProductId != 10 || selectedDevice.usbVendorId != 1240) {
  const { writable, readable } = port;
  await writer.write(CMD1);
  await writer.write(CMD2);
  writer = writable.getWriter();
  reader = readable.getReader();
  while (true) {
    startLoopTimer();
    const { value, done } = await reader.read();
    if (done) break;
    console.log('Received data:', value);
  }

IMPORTANT : The issue is happening on most Windows machines with 8GB of RAM.

My device details showing in chrome://device-log is:- SerialEvent[11:05:11] Serial device added: path=COM5 instance_id=USB\VID_04D8&PID_000A\5&2C179895&0&2 vid=04D8 pid=000A

USBUser[11:05:11] USB device added: path=\?\usb#vid_04d8&pid_000a#5&2c179895&0&2#{a5dcbf10-6530-11d2-901f-00c04fb951ed} vendor=1240 "Microchip Technology Inc.", product=10 "Simple CDC Device Demo", serial="", driver="usbser", guid=f02c59af-8c78-431d-888b-6a987c1ed8e8

SerialEvent[11:05:10] Serial device removed: path=COM5

USBUser[11:05:10] USB device removed: path=\?\usb#vid_04d8&pid_000a#5&2c179895&0&2#{a5dcbf10-6530-11d2-901f-00c04fb951ed} guid=3959900e-8309-4393-9be0-8c65dde53689

reillyeon commented 2 months ago

This issue appears off-topic for this repository because it is either an API implementation bug (which should be filed in the Chromium Issue Tracker or an issue with the device.

For these kinds of USB communication issues I recommend using a tool like Wireshark to capture the USB traffic. This will show you the low-level communication between the host and device and may make the issue clearer. For example, if the host driver is not requesting data regularly or if the device is pausing unusually before responding to the request.

Your code looks generally reasonable though a bit out-of-order since it calls write() before getWriter(). I assume that is a copy-paste error.

sagar-bhedodkar commented 2 months ago

Ok sorry this is copy paste mistake `const CMD1 = new Uint8Array([78, 84, 83, 83, 84, 65, 82, 84, 76, 238, 167, 78, 84, 69]);

const CMD2 = new Uint8Array([78, 84, 83, 83, 84, 65, 82, 84, 68, 40, 166, 78, 84, 69]);

var port = null; port = await navigator.serial.requestPort(); await port.open({ baudRate: 115200 }); var selectedDevice = port.getInfo(); if (selectedDevice.usbProductId != 10 || selectedDevice.usbVendorId != 1240) { const { writable, readable } = port; writer = writable.getWriter(); reader = readable.getReader(); await writer.write(CMD1); await writer.write(CMD2); while (true) { startLoopTimer(); const { value, done } = await reader.read(); if (done) break; console.log('Received data:', value); }`

this is my exact code so I can't able to find the issue so can you please provide me the solution. Also I find that there is issue in most of the windows machines of 8gb Ram but on 16gb ram windows machine it working fine but on some 16gb ram windows machines it also losses some in between data.

sagar-bhedodkar commented 2 months ago

And I think the web serial communation happens locally. But I have one question the good internet connection is always required for the communication or not. Please provide me the solution.

sagar-bhedodkar commented 2 months ago

@reillyeon I stuck in the issue I implemented the web serial according to the documentation in chrome developer section but I stuck in this issue so please help me in this.

larsgk commented 2 months ago

@sagar-bhedodkar this repo and issue tracker might not be the best to get it sorted, but feel free to ping me on @denladeside@mastodon.social and I can try to help out

sagar-bhedodkar commented 2 months ago

@larsgk Thank you and I mailed you so please help me.