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

serialport-js

v1.1.0

Published

Serialport js - node.js serial duplex connection.

Downloads

19

Readme

serialport-js

Build Status Coverage Status

pure javascript serial port implementation for node.js, electron and nw.js.

Install

npm i --save serialport-js

Usage

const serialjs = require('serialport-js');

const init = async () => {
    const delimiter = '\n';
    const ports = await serialjs.find();
    if (ports.length) {
        let port = await serialjs.open(ports[0].port, delimiter);

        port.on('data', (data) => {
            console.log(data);
        });
        port.on('error', (error) => {
            console.error(error);
        });
        port.send('foo bar');
    }
};
init();

Methods

find()

Type: Promise<Object[]|Error>

Async function that returns a promise. When resolved it contains a list of the registered serial devices.

findById(id)

Id: String Type: Promise<Object|Error>

Async function that returns a promise. When resolved it contains the found serial device or null when not found.

open(path, delimiter = '\r\n')

Type: Promise<EventEmitter|Error>

Opens a Duplex connection to the serial device. Returns the Port(event.EventEmitter) Object

Port Events

data

Type: String

The data that has been read out of the serial connection.

error

The error that occured.

closed

Is emitted when the connection is closed.

Port Methods

port.send(data)

Sends the data to the serial device.

port.close();

Closes the connection to the serial device. When closed, the event closed is emitted.

Port Variables

  • isOpen
  • serialPort

#node-webkit, nw.js, and seperate node.js thread examples *The only difference with this is that the user must have node installed. It will spawn a node proxy using their local node version and run the pure js serialport implementation. This is great for consumer facing products as there is no need for compilers or dev tools to install the module with your app, users just need node.

    var serialjs=require('serialport-js').node(); //thats the only difference
    //the rest of the implementation is exactly the same.

    serialjs.find(serialDevicesPopulated);

    function serialDevicesPopulated(ports){
        //ports arg is a refrence to serialjs.ports
        console.log(
            ports
        );

        if(!ports[0])
            return;

        serialjs.open(ports[0].port,start,'\n');
    }

    function start(port){
        port.on(
            'data',
            gotData
        );
        
        //if this doesn't show up the port may need a few milliseconds to open
        port.send('howdy doody doo');
    }

    function gotData(data){
        console.log(data);
    }