I am looking for some mechanism that would switch USB device to failsoft mode when connection to the site is broken (i.e. browser crashed, user closed tab with the site that communicates to the device or simply network connection is down). One of the option I can see is some kind of mechanism of sending keep-alives from browser to the device - unfortunately the only (simple) way of transferring data from browser I found is via CDC (which is using bulk transfer - that the slowest way of sending data). Is there any way to utilize interrupt transfer via WebUSB? Or maybe there is a better way than sending keep-alives to achieve desired behavior? Currently I am focused on Windows 10.
Asked
Active
Viewed 128 times
1 Answers
0
What you want to do is set up your interface with two alternate settings. Alternate setting 0 can be the failsafe mode and is selected by default. When your app opens the device it can call selectAlternateInterface() to select alternate setting 1 which would be your active mode. The OS will automatically send a SET_ALTERNATE(0) command to your interface when you call close(), the page is closed, or the browser crashes.

Reilly Grant
- 5,590
- 1
- 13
- 23
-
That seem to be quite nice way to handle that kind of the scenario. I am wondering if there is anything that can be done for scenario when web browser freezes and we want to go failsafe mode... – Grzegorz Suder Dec 10 '18 at 19:00
-
For that you'll need to implement some kind of heartbeat sent from your app to the device. – Reilly Grant Dec 10 '18 at 21:30
-
So it seems the only way to fullfill my requirements would be to implement keep alive mechanism. – Grzegorz Suder Dec 17 '18 at 21:45
-
hi @beca reilly , you know-how is way to communicate my scanner via webusb. I can connect but i don't know how to send to start the scan and receive img scanned? please help me. i fond it https://github.com/tidepool-org/uploader/blob/c9bc19a9af84cc39e54a3f250a8e8e340bc9f5cc/lib/drivers/onetouch/oneTouchVerio.js – Carlos Feb 10 '22 at 18:51