# @ridge18/web-serial-monitor

> JavaScript library to interact with serial devices using the Web Serial API.

Latest version **0.1.3** (published 2023-10-17) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install @ridge18/web-serial-monitor
pnpm add @ridge18/web-serial-monitor
yarn add @ridge18/web-serial-monitor
bun add @ridge18/web-serial-monitor
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2023-10-17 |
| First published | 2023-02-04 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 14 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Pablo Marozzi |
| Maintainers | ridge18 |
| Keywords | browser, web, serial, api, monitor |

## Links

- npm: https://www.npmjs.com/package/@ridge18/web-serial-monitor
- Repository: https://github.com/PabloMarozzi/Web-Serial-Monitor
- Issues: https://github.com/PabloMarozzi/Web-Serial-Monitor/issues
- npm.io page: https://npm.io/package/@ridge18/web-serial-monitor

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.1.3 (latest) — 2023-10-17
- 0.1.2 — 2023-02-10
- 0.1.1 — 2023-02-04
- 0.1.0 — 2023-02-04

## README

# WebSerialMonitor

JavaScript library to interact with serial devices using the Web Serial API in the browser.
The library allow to send data and receive data in text or binary modes.

**Please note** that this library requires the WebSerial browser API. Check https://developer.mozilla.org/en-US/docs/Web/API/Web_Serial_API for browser compatibility.

* [Installation](#installation)
* [Usage](#usage)
* [Test](#test)
* [License](#license)

## Installation

Use npm to install this library in a nodejs project:
```bash
npm install @ridge18/web-serial-monitor
```

## Usage

Init in text mode (defaut)
```js
import SerialMonitor from '@ridge18/web-serial-monitor';

const serial = new SerialMonitor({mode: "text"});
```

Init in text mode with line parser (line break: '\n')
```js
import SerialMonitor from '@ridge18/web-serial-monitor';

const serial = new SerialMonitor({mode: "text", parseLines: true});
```

Init in binary mode
```js
import SerialMonitor from '@ridge18/web-serial-monitor';

const serial = new SerialMonitor({mode: "byte", hex: true});
```

Connect to a device
```js
// serial is an instance of a extended EventTarget class
// you can listen to events emited by it.
const handleSerialEvent = (ev) => {
    console.log(ev.detail);
}
serial.addEventListener('serial-connected', handleSerialEvent);

serial.addEventListener('serial-disconnected', handleSerialEvent);

serial.addEventListener('serial-error', handleSerialEvent);

serial.addEventListener('serial-data', handleSerialEvent);

// This will open a browser dialog which prompts the user to select a serial device.
// If no device is selected, then a serial-error event is fired.
serial.connect(57600).then(() => { // connect at 57600 bauds rate.
	serial.send("Hello serial\n");
}).catch(() => {
	console.log("Something went wrong...");
}); 

serial.disconnect();
```

## Test

This test use a simple node web server to load the library directly into the browser, no module bundler needed.
```bash
npm run test
```

## License

The project is licensed under the [GNU General Public License v3 (GPL-3)](https://tldrlegal.com/license/gnu-general-public-license-v3-(gpl-3))

---
_Source: https://npm.io/package/@ridge18/web-serial-monitor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
