# @mangar2/serialhelper

> Serial connection to microcontroller

Latest version **2.0.1** (published 2022-12-11) · LGPL-3.0-or-later license · 0 weekly downloads

## Install

```sh
npm install @mangar2/serialhelper
pnpm add @mangar2/serialhelper
yarn add @mangar2/serialhelper
bun add @mangar2/serialhelper
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2022-12-11 |
| First published | 2020-10-19 |
| Weekly downloads | 0 |
| License | LGPL-3.0-or-later |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 9.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Volker Böhm |
| Maintainers | mangar2 |
| Keywords | serial, arduino, esp8266 |

## Links

- npm: https://www.npmjs.com/package/@mangar2/serialhelper
- Repository: https://github.com/Mangar2/yaha.git#master
- Homepage: https://github.com/Mangar2/yaha.git
- Issues: https://github.com/Mangar2/yaha/issues
- npm.io page: https://npm.io/package/@mangar2/serialhelper

## Dependencies (2)

- [serialport](https://npm.io/package/serialport.md) 10.x.x
- [@mangar2/utils](https://npm.io/package/@mangar2/utils.md) latest

## Recent versions

- 2.0.1 (latest) — 2022-12-11
- 2.0.0 — 2022-12-11
- 1.0.1 — 2020-11-14
- 1.0.0 — 2020-10-19

## README

<!-- This file is generated by jsmddoc version 0.1 -->

# Abstract

## Contents

- [Meta](#Meta)
- [Class SerialConnection](#Class-SerialConnection)
  - [Methods](#SerialConnection-Methods)
    - [close](#close)
    - [listAvailablePorts](#listAvailablePorts)
    - [on](#on)
    - [open](#open)
    - [sendData](#sendData)

## Meta

## Callback definitions

### Data

Called when at least one byte has been read from the serial connection

## Class SerialConnection

`new SerialConnection()`

Class shielding the serial port class and provides async interfaces The functions open , close , and send data are async functions . Read data by registering the callback 'data' with the on function

### SerialConnection Methods

#### close

`async close ()`

Closes the serial port

#### listAvailablePorts

`async listAvailablePorts ()`

Lists all available ports to console

#### on

`on (event, callback)`

Sets a callback .

##### on Parameters

| Name | Type | Description |
| ---------- | ------------ | ----------------- |
| `event` | `string` | event name ( not case sensitive ) for the callback ( supports 'data' ) | |
| `callback` | `Data` | function ( . . . parameter ) | |

##### on throws

| Type | Description |
| ---- | ----------- |
| `Error` | if the event is not supported |
| `Error` | if the callback is not 'function' |

#### open

`async open (serialPortName, baudRate) => {Promise}`

Opens the serial port

##### open Parameters

| Name | Type | Description |
| ---------- | ------------ | ----------------- |
| `serialPortName` | `string` | name of the serial port ( example "COM1" ) | |
| `baudRate` | `number` | baud rate ( example 9600 ) | |

##### open returns

| Type | Description |
| ---- | ----------- |
| `Promise` |  |

#### sendData

`async sendData (byteArray) => {}`

Sends data to the serial port

##### sendData Parameters

| Name | Type | Description |
| ---------- | ------------ | ----------------- |
| `byteArray` | `Array.<byte>` | serial data as byte stream | |

##### sendData returns

| Type | Description |
| ---- | ----------- |
| `` | true , if sending was successful |

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