javascriptwebapiwebusbweb-serial-api

webAPI - Serial Device via USB converter


I am experimenting with connecting devices via webAPI for the first time. I am in the process of purchasing a set of scales which has weight indicator. The plan is to connect it my webApp and use javascript to directly read the weight into my app.

This has a RS232 serial output but as new computers these don't have serial inputs I plan to connect it my computer via USB converter.

The question I have is with the WebAPI do I use the webUSB or webSerial API to connect to the device. If using webUSB any advice on how to decode or interpret data which will be sent as R232?

I am a complete newbie for this so any advice however basic it is, very welcome. Thanks in advance.


Solution

  • If the device appears to the computer as a serial port (which may require installing drivers specific to the USB converter) then it will work with the Web Serial API.

    Even if you did want to use the WebUSB API to talk to the device (such as if the drivers aren't installed) then you should take a look at the web-serial-polyfill project which aims to collect all the low-level USB code you need to talk to a serial device with WebUSB and present it using the same Web Serial API interface.