0

WebUSB has very limited coverage, but that's okay for this project.

The navigator.usb.requestDevice method succeeds:

navigator.usb.requestDevice({
                    filters: [{
                        vendorId: RECEIVER_VENDOR_ID,
                        productId: RECEIVER_PRODUCT_ID
                    }]
                })

Chrome receives permission (via modal interaction) to access the device.

To the browser, the device exists:

console.log(device)

USBDevice {usbVersionMajor: 2, usbVersionMinor: 0, usbVersionSubminor: 0, deviceClass: 2, deviceSubclass: 2, …}
configuration: null
configurations: [USBConfiguration]
deviceClass: 2
deviceProtocol: 0
deviceSubclass: 2
deviceVersionMajor: 2
deviceVersionMinor: 0
deviceVersionSubminor: 0
manufacturerName: "STMicroelectronics"
opened: true
productId: 22336
productName: "STM32 Virtual ComPort"
serialNumber: "355837673037"
usbVersionMajor: 2
usbVersionMinor: 0
usbVersionSubminor: 0
vendorId: 1155
__proto__: etc...

The example receiver I am following echoes the Mozilla docs:

await usbDevice.selectConfiguration(1)

(ReceiverParcer is here)

Making my way through a Web.dev article on Accessing USB via the web, and hoping, meanwhile, for some SO Magic.

What am I not seeing/doing?

Thanks.

Update

Checking chrome://device-log (level Debug) returns:

USBUser[14:51:38] USB device added: vendor=1155 "STMicroelectronics", product=22336 "STM32 Virtual ComPort", serial="355837673037", guid=2bd99a9a-75bf-4782-8a0d-2f9e13b06e86

USBUser[14:51:30] USB device removed: guid=1b763328-45db-4152-9c56-9b592d614c3e

USBEvent[14:51:30] Failed to clear halt: Pipe error
MikeiLL
  • 6,282
  • 5
  • 37
  • 68
  • What platform are you running on? If you look in chrome://device-log (change the level to "debug") you should get a more detailed error about the failure to select a configuration. – Reilly Grant Oct 29 '20 at 19:48
  • @ReillyGrant thanks. Updated post, seeing "Failed to clear halt: Pipe error". – MikeiLL Oct 29 '20 at 19:55
  • 1
    That error points to a call to clearHalt() failing, not selectConfiguration(). Please check your code to make sure it is failing where you think it is. A failure to clear a halt condition may indicate a more fatal communication error with the device. If you check the kernel log (dmesg) there may be more errors indicating the source of the problem being encountered as this might indicate that the connection to the device is unstable. Try again with a different USB cable. – Reilly Grant Oct 30 '20 at 20:09
  • I think I have tried with a couple of different cables already and will try again, also with a reboot. Ourput of dmesg is https://gist.github.com/MikeiLL/85e8bdada20fff7c74d3461bc2ca48c8 if you have another moment to take a look. – MikeiLL Oct 30 '20 at 20:27

1 Answers1

0

Because USB–and even more so WebUSB–seems to be more fragile than the http connections I'm used, parallel to playing with the Javascript interface, I also worked at pulling in the data with PyUSB. The goal is to write data from the device to a CSV file so either could work.

In this related post I outline some additional steps in the process including:

  • rebooting the machine
  • with the device connected
  • a good USB cable
  • checking chrome://device-log at DEBUG level
  • using a demo of the Serial App
  • checking status with kexstat, "unclaiming" with kextunload
  • looking at kernel log with dmesg

I would love to accept a more robust "answer" than this, but I am finally seeing some data:

let rawStream = new Uint8Array(data.buffer)
console.log(rawstream)

Uint8Array(69) [51, 48, 49, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 48, 48, 48, 48, 48, 48, 48, 48, 32, 13, 10]

And

let segments = String.fromCharCode.apply(null, rawStream).split(' ')
console.log(segments)

 ["300", "V1.06", "585AEEDD", "00000000", "00000000", "00000000", "00000000", "00000000", "00000000", "
↵"]
MikeiLL
  • 6,282
  • 5
  • 37
  • 68
  • Apologies for not noticing earlier that you are dealing with a serial device. You could continue to fight with the operating system to get access to the device a the raw USB layer but I recommend taking advantage of the new [Web Serial API](https://github.com/WICG/serial/blob/gh-pages/EXPLAINER.md). This API is structured similarly to WebUSB but is specifically design for accessing serial devices, whether over USB or other transports such as Bluetooth. It will use the built-in macOS drivers that you are likely fighting with for control of the device and is what the "Serial" app likely uses. – Reilly Grant Nov 01 '20 at 00:04
  • This API is still in development so requires enabling the chrome://flags/#enable-experimental-web-platform-features flag or registering your domain for the Origin Trial here: https://developers.chrome.com/origintrials/#/view_trial/2992641952387694593 – Reilly Grant Nov 01 '20 at 00:05
  • François has written an excellent article about getting started with the Serial API: https://web.dev/serial/ – Reilly Grant Nov 01 '20 at 00:06