Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@serialport/parser-readline

Package Overview
Dependencies
Maintainers
3
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@serialport/parser-readline

See our api docs See our api docs https://serialport.io/docs/api-parser-readline

  • 12.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
102K
decreased by-19.42%
Maintainers
3
Weekly downloads
 
Created

What is @serialport/parser-readline?

@serialport/parser-readline is a parser for the serialport library that reads data from a serial port and splits it into lines based on a delimiter. It is useful for applications that need to process data line-by-line from serial devices.

What are @serialport/parser-readline's main functionalities?

Basic Line Parsing

This feature allows you to read data from a serial port and split it into lines based on a specified delimiter. In this example, the delimiter is set to '\r\n'.

const SerialPort = require('serialport');
const Readline = require('@serialport/parser-readline');

const port = new SerialPort('/dev/tty-usbserial1', { baudRate: 9600 });
const parser = port.pipe(new Readline({ delimiter: '\r\n' }));

parser.on('data', line => {
  console.log(`Received line: ${line}`);
});

Custom Delimiter

This feature allows you to specify a custom delimiter for splitting the data into lines. In this example, the delimiter is set to ';'.

const SerialPort = require('serialport');
const Readline = require('@serialport/parser-readline');

const port = new SerialPort('/dev/tty-usbserial1', { baudRate: 9600 });
const parser = port.pipe(new Readline({ delimiter: ';' }));

parser.on('data', line => {
  console.log(`Received line: ${line}`);
});

Handling Errors

This feature demonstrates how to handle errors that may occur while reading data from the serial port. The error event is listened to on the port object.

const SerialPort = require('serialport');
const Readline = require('@serialport/parser-readline');

const port = new SerialPort('/dev/tty-usbserial1', { baudRate: 9600 });
const parser = port.pipe(new Readline({ delimiter: '\r\n' }));

parser.on('data', line => {
  console.log(`Received line: ${line}`);
});

port.on('error', err => {
  console.error('Error: ', err.message);
});
0

FAQs

Package last updated on 29 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc