https://github.com/eove/serial-console-com
Javascript lib to communicate with a unix console over a serial line
https://github.com/eove/serial-console-com
barebox cli console linux serial uboot unix
Last synced: about 1 month ago
JSON representation
Javascript lib to communicate with a unix console over a serial line
- Host: GitHub
- URL: https://github.com/eove/serial-console-com
- Owner: eove
- License: mit
- Created: 2019-09-11T12:32:45.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-08-29T15:14:43.000Z (9 months ago)
- Last Synced: 2025-08-29T18:29:21.427Z (9 months ago)
- Topics: barebox, cli, console, linux, serial, uboot, unix
- Language: TypeScript
- Homepage:
- Size: 435 KB
- Stars: 2
- Watchers: 0
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# `serial-console-com` [](https://www.travis-ci.org/eove/serial-console-com) [](https://badge.fury.io/js/%40eove%2Fserial-console-com) [](https://github.com/prettier/prettier)
Node.js lib to communicate with a unix-like console through a serial line
## Install
Node >= 8.12.0
`npm install`
## Usage...
### ...in your code
This lib exposes a communicator which may execute commands through the serial line.
```js
import { createSerialCommunicator } from '@eove/serial-console-com';
const communicator = createSerialCommunicator({
baudrate: 115200,
prompt: '/ #',
lineSeparator: '\n'
});
communicator
.connect('/dev/ttyUSB0')
.then(() => communicator.executeCommand('ls -al'))
.then(({ output, errorCode }) => {
console.log('error code:', errorCode);
console.log('output:', output.join('\n'));
});
.catch(e => console.error('error when running ls -al'))
.finally(() => communicator.disconnect())
```
The async `executeCommand` method returns an object with the following fields:
- `errorCode`: a number corresponding to the error code of the command
- `output`: a string array corresponding to the lines of the command output
### ...from a CLI 🔥
You can try it from the command line: `npx @eove/serial-console-com run 'ls -al /' -p /dev/ttyUSB0` (type `npx @eove/serial-console-com run --help` for the full list of options)
Note: the `npx` command exits with the given command error code:
```bash
npx @eove/serial-console-com run 'true' -p /dev/ttyUSB0
echo $?
0
```
```bash
npx @eove/serial-console-com run 'false' -p /dev/ttyUSB0
echo $?
1
```