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

ngx-serial

v1.0.1

Published

NgxSerial eases the use of the Serial Web API in Angular.

Downloads

924

Readme

NgxSerial

NgxSerial eases the use of the Serial Web API in Angular.

You can establish a bidirectional communication with any device supporting RS232 protocol (native or over USB) using only a web browser, forget running local applications !

Examples of devices could be Arduino like boards, PLC's, Smart Card Readers, Access control devices.

This Video show the library in action

Installation

First, install the package using npm install

npm install ngx-serial

Use

You have available ngx-serial on your project, add the following import in your component.

import { NgxSerial } from 'ngx-serial';

You can use the class as follow.

serial: NgxSerial;

constructor() {
    this.serial = new NgxSerial(this.dataHandler);
}

Data Handler will receive read data, so here you can implement your read logic. It will read until LF (can be changed passing the string to the constructor) is received.

dataHandler(data: string) {
    console.log(data);
}

To request permissions to use the COM port and connect , use the method connect().

this.serial.connect(); 

To use connect() a user interaction is required, for example call this method when the user click a button.

To send data to the serial device use sendData(), this method accept a string as paremeter.

this.serial.sendData("Data\n");

To free resources execute the method close()

this.serial.close();

Default options values are.

baudRate: 9600, dataBits: 8, parity: 'none', bufferSize: 256, flowControl: 'none'

In the constructor you can pass optionally an options Object and the control character (\n by default).

let options = { baudRate: 9600, dataBits: 8, parity: 'none', bufferSize: 256, flowControl: 'none' };
this.serial = new NgxSerial(this.dataHandler, options, "\n");

connect() and close() accept a callback function returning the serial port. Can be used to check the connection state.

if(!this.port){
    this.serial.connect((port:any)=>{
    this.port = port;
});

if(this.port)
    this.serial.sendData("L1\n");

if(this.port)
    this.serial.close((port:any)=>{
    this.port = port;
});


 <div *ngIf="this.port">
    <span class = "greendot"></span>
    <span>Connected</span>
</div>
<div *ngIf="!this.port">
    <span class = "reddot"></span>
    <span>Disconnected</span>
</div>

To check an example application made on Angular click here The Arduino Code is located on src/assets/ngx-serial-example.ino

Broswer support

At this moment (21/06/2021) Chrome, Opera and Edge are supporting Web Serial API