Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danchitnis/comport
A simple package for using W3C Serial Api
https://github.com/danchitnis/comport
api arduino browser chrome com communication comport edge embedded ftdi hardware javascript microbit microcontroller port serial typescript w3c
Last synced: about 1 month ago
JSON representation
A simple package for using W3C Serial Api
- Host: GitHub
- URL: https://github.com/danchitnis/comport
- Owner: danchitnis
- License: mit
- Created: 2019-12-29T04:12:23.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-11-10T04:28:17.000Z (about 2 years ago)
- Last Synced: 2024-10-13T02:04:48.874Z (about 1 month ago)
- Topics: api, arduino, browser, chrome, com, communication, comport, edge, embedded, ftdi, hardware, javascript, microbit, microcontroller, port, serial, typescript, w3c
- Language: TypeScript
- Homepage: https://danchitnis.github.io/Serial-API-Examples/
- Size: 223 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ComPort
A simple package to use the new [Serial Api](https://wicg.github.io/serial/) available in Chrome (also Edge based on Chromium)
๐ฅ **Notice** : Serial Api is under Chrome's experimental flag since Chrome 79 and on Origins Trail since Chrome 80. The API is unstable.
## Why Serial Api
Although [WebUSB](https://wicg.github.io/webusb/) has been around for some years, it is mainly targeted at companies intending to developed web-based firmwares. A major downside of WebUSB is once a native driver is installed on the OS, the device will no longer be recognized by WebUSB. Unlike WebUSB, the [Serial Api](https://wicg.github.io/serial/) is intended for use as a traditional COM port (Serial port) which includes many microcontroller based devices and USB-to-Serial devices such as FTDI and Cypress chipsets. Additionally, you can still implement your own USB CDC protocol, and have the OS driver and Web driver co-exist. The Serial Api opens doors for new and exciting web-based front-ends for small and medium sized embedded projects.
## Why ComPort
ComPort makes it easy for embedded developers to quickly build a modern front-end for their applications. It removes the hassle of dealing with async/await functions. This package is not intended for high-performance and high data-rate applications, but for quick and simple development. If high-performance is required then a browser based app is probably the wrong choice.
## Potential use cases
all serial communication to and from embedded hardware via USB-to-Serial bridges like FTDI cables and Arduino boards.
## How to enable Serial Api (Chrome 79 and above)
Enable it in: chrome://flags/#enable-experimental-web-platform-features
## Build instructions
```bash
npm i
npm run build
```## installation
```bash
npm i @danchitnis/comport
```## Example
import the library
```javascript
import { ComPort } from "@danchitnis/ComPort";
```initialize:
```javascript
const port = new ComPort();
port.connect(9600);
port.addEventListener("rx", dataRX);
```data RX event:
```javascript
function dataRX(e) {
log(e.detail + "\n");
}
```## API documentation
[See here ๐งพ](https://danchitnis.github.io/ComPort/)
## Demos
See [here](https://github.com/danchitnis/Serial-API-Examples) examples tested with [Arduino Nano 33 BLE](https://store.arduino.cc/arduino-nano-33-ble), but also extendable to other boards as it is simply using serial communication.
## Useful links
- [W3C Serial Api working draft](https://wicg.github.io/serial/)
- [Serial Api Chrome status](https://www.chromestatus.com/feature/6577673212002304)
- [Google Serial Api example](https://codelabs.developers.google.com/codelabs/web-serial/#0)
- [Serial Api Explainer](https://github.com/WICG/serial/blob/gh-pages/EXPLAINER.md)