Skip to content
This repository has been archived by the owner on Jan 28, 2022. It is now read-only.
/ ez-serial-read Public archive

Makes reading the serial data of an Arduino and other serial devices really easy

License

Notifications You must be signed in to change notification settings

Sv443/ez-serial-read

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ez-serial-read

A package that makes the usage of the serialport package easier.



This package was made to make reading an Arduino serial comm easier as normally you have to write many lines of code and end up getting a buffer instead of a string.





Install:

>  npm i --save ez-serial-read












Usage:

(Arguments prefixed with ? are optional and will have a default value)

var success = ezSerial(comPort, ?baudRate, callback); // basic initialization
// typeof success = boolean


ezSerial.listAll(result => { // list all open serial ports
    // typeof result = object array
});









Example:

const ezSerial = require("ez-serial-read");

var success = ezSerial("COM4", 9600, data => { // serial port, baud rate, data callback - if you don't know your serial port, run the listAll method like demonstrated below this snippet
    // this function gets called every time a line is being received and the "data" variable contains that line
    console.log(data);
});

if(success) { // the ezSerial() function returns a boolean value that is true, if the connection could be established and false, if not
    console.log("Successfully connected to the serial port!");
}
else {
    console.log("Couldn't connect!");
}





If you don't know your COM ports, use this:

const ezSerial = require("ez-serial-read");

ezSerial.listAll(console.log);

This lists all serial ports to the console. It will look something like this:

[ { comName: 'COM3',
    manufacturer: 'FTDI',
    serialNumber: 'A702H5DS',
    pnpId: 'FTDIBUS\\VID_0403+PID_6001+A702H5DSA\\0000',
    locationId: undefined,
    vendorId: '0403',
    productId: '6001' },
  { comName: 'COM1',
    manufacturer: '(Standard port types)',
    serialNumber: undefined,
    pnpId: 'ACPI\\PNP0501\\0',
    locationId: undefined,
    vendorId: undefined,
    productId: undefined },
  { comName: 'COM4', //       <-           <-           <-           <- this is the actual port of our arduino we want to talk to, so we need to enter "COM4" in the initialization function
    manufacturer: 'Arduino LLC (www.arduino.cc)',
    serialNumber: '85633323530351905232',
    pnpId: 'USB\\VID_2341&PID_0043\\85633323530351905232',
    locationId: 'Port_#0003.Hub_#0003',
    vendorId: '2341',
    productId: '0043' } ]

Releases

No releases published

Packages

No packages published