npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

serial-io

v1.2.0

Published

serialport interface for batch style commands

Downloads

44

Readme

serial-io

npm version Build Status Coverage Status Greenkeeper badge Known Vulnerabilities Outdated dependencies

serialport interface for batch style commands

This module is a promise based wrapper for the node-serialport package. It allows you to interact with devices on a command & response basis. Based on a defined terminator or timing behavior the end of a response is deterimed and the complete response returned as a resolved Promise.

Install

$ npm install --save serial-io

Usage

const serialIo = require('serial-io');

// this will send HELLO to the device and resolve with
//  anything that gets received within 100ms
serialIo.send('thisPortName', 'HELLO')
.then(response => console.log(`device responded:\n${response}`))

// if you don't know the devices port name try
serialIo.ports().then(console.log.bind(console))

// will show the response of a device on port '/dev/cu.usbmodem1411' (assuming it reacts to 'version\n')
serialIo.send('/dev/cu.usbmodem1411', 'version\n').then(console.log.bind(console))

API

The package exposes two APIs with different abstraction levels. Directly interacting with the serialIo objects gives you the highest level of abstraction.

If you use serialIo.connect() you get a Connection object returned that allows you to do things like multiple requests without re-connecting every time. Using the Connection API is recommended for programmatic use cases, whereas the high level serialIO.send() API is great for handling events that are triggered by humans i.e. low frequency.

All methods are promise-based.

serialIo.ports()

Resolves to a list of available serial ports. Refer to the serialport documentation for a specification of the returned data.

serialIo.send(portName, content, {options})

Single interaction with a device. Opens up a connection, transmits the content and waits for the response to resolve the returned Promise.

portName

Type: string

A valid portname.

content

Type: string

Payload to send.

options

terminator

Type: string Default: none

If the specified terminator string/character is found within the response the Promise is resolved immediately with the capture data. The returned data includes the terminator.

timeoutInit

Type: number in ms Default: 100

Time to listen to the device for a (first) response.

timeoutRolling

Type: number in ms Default: 10

Time to wait after receiving a data chunk until the next one arrives. If the timer runs out the response is resolved.

serialIo.connect(portName, {options})

Opens up a Connection to the given port. This method is NOT promise-based it will return the Connection object directly.

portName

Type: string

A valid portname.

options

Refer to serialport openOptions for an overview of available options.

connection.close()

Closes the Connection instance.

connection.send(content, {options})

Send content over the connection and wait for an answer. The method returns a Promise that will resolve to the received answer. Using options you can define how listening to answer is done.

content

Type: string

Payload to send.

options

terminator

Type: string Default: none

If the specified terminator string/character is found within the response the Promise is resolved immediately with the capture data. The returned data includes the terminator.

timeoutInit

Type: number in ms Default: 100

Time to listen to the device for a (first) response.

timeoutRolling

Type: number in ms Default: 10

Time to wait after receiving a data chunk until the next one arrives. If the timer runs out the response is resolved.

connection.getState()

Tells you something about the current connection.

License

MIT © anoff