# xbee-serial-stream

> XBee serial protocol implementation

Latest version **0.0.4** (published 2020-12-22) · ISC license · 0 weekly downloads

## Install

```sh
npm install xbee-serial-stream
pnpm add xbee-serial-stream
yarn add xbee-serial-stream
bun add xbee-serial-stream
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2020-12-22 |
| First published | 2020-12-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 19.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | kapetan |

## Links

- npm: https://www.npmjs.com/package/xbee-serial-stream
- Repository: https://github.com/kapetan/xbee-serial-stream
- Homepage: https://github.com/kapetan/xbee-serial-stream#readme
- Issues: https://github.com/kapetan/xbee-serial-stream/issues
- npm.io page: https://npm.io/package/xbee-serial-stream

## Dependencies (2)

- [mutexify](https://npm.io/package/mutexify.md) ^1.3.1
- [duplexify](https://npm.io/package/duplexify.md) ^4.1.1

## Recent versions

- 0.0.4 (latest) — 2020-12-22
- 0.0.3 — 2020-12-20
- 0.0.2 — 2020-12-20
- 0.0.1 — 2020-12-13

## README

# xbee-serial-stream

XBee serial protocol implementation.

    npm install xbee-serial-stream

## Usage

This library is transport agnostic. It implements the XBee serial protocol for sending AT commands. The following example shows how to use it with the [serialport](https://serialport.io) module.

```javascript
const DeviceStream = require('xbee-serial-stream')
const SerialPort = require('serialport')

const stream = new DeviceStream()
const port = new SerialPort('/dev/tty.usbserial-1420', {
  baudRate: 9600
})

stream.pipe(port).pipe(stream)

// Get value for SH (serial number high)
const sh = await stream.command('SH')
```

The `FS PUT` command is supported using `createWriteStream` method. It initiates an YMODEM file transfer session and returns a writable stream which can be written to.

```javascript
const writeStream = stream.createWriteStream('/flash/test.txt', 11)

writeStream.write('hello')
writeStream.write(' ')
writeStream.write('world')
writeStream.end()
```

Similarly `FS GET` is supported with the `createReadStream` method.

```javascript
const readStream = stream.createReadStream('/flash/test.txt')

// The file event is emitted before any data events
readStream.on('file', ({ name, length }) => {})
readStream.on('data', data => {})
```

## API

#### Class: `DeviceStream()`

Create new instance of the protocol stream. The class implements the `Duplex` stream interface, everything written to an instance is treated as incoming data from the remote endpoint and everything read is outgoing to data to the endpoint.

##### `async command(cmd, [terminator])`

- `cmd` AT command to execute. Usually two characters long, but may be longer, for example `FS LS`. The command may also optionally be followed by a setting value (separated by a space).
- `terminator` (optional) The terminator condition for the command response. By default all text before the first carriage return is returned as the response. In some cases an empty string should be used as a the terminator, e.g. `FS LS` returns multiple lines (separated by carriage return) with an empty terminator line.
- Returns: `Array` of strings. Each entry is a line received from the device.

Execute an AT command on the device and await the response.

##### `createWriteStream(name, length)`

- `name` Name of the file on the device.
- `length` The length of the file.
- Returns: `Writable` stream

##### `createReadStream(name)`

- `name` Name of the file on the device.
- Returns: `Readable` stream. The readable stream emits a `file` event, when name and length of the file has been read from the YMODEM header.

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