This package has been deprecated

Author message:

Probably doesn't work in Node 1+. Use serialport lib instead.

trivial-port

0.3.2 • Public • Published

trivial-port

Node.js library to open serial ports for reading and writing

Operating System Support

  • Linux - Works
  • Mac OSX - May work with a few minor tweaks
  • Windows - It should work using the MODE command instead of stty. Checkout this StackOverflow post

Why?

Node doesn't really support talking to serial ports at the moment.

Usage

var SerialPort = require("trivial-port");
var port = new SerialPort();
port.initialize();
port.on("data", function(chunk) {
    console.log("Incoming:", chunk);
})
port.write("Hello, World!");

Trivial-port implements a Duplex stream for reading from and writing to a serial port.

This implementation uses stty to initialize the stream; then, it simply reads from or writes to the serial port using the tty Node.js library.

var port = new SerialPort(options);

The options object allows you to pass named options to the serial port during initialization. The valid attributes for the options object are the following:

  • serialPort - the serial port device name (required)
  • baudRate - Baud Rate (defaults to 9600)
  • dataBits - Data Bits - Must be one of: 8, 7, 6, or 5. (defaults to 8)
  • stopBits - Stop Bits - Must be one of: 1 or 2. (defaults to 1)
  • parity - Parity - Must be one of: 'none', 'odd', 'even', 'mark', 'space' (defaults to 'none')
  • sttyPath - the path to the stty command (defaults to /bin/stty)
  • initTimeout - maximum initialization duration (defaults to 10 seconds); set to null to allow an infinite amount of time
  • sttyArgs - an array of additional arguments to pass to the stty command

port.initialize([cb])

Sets the appropriate serial port options and opens the serial port. If cb is specified, it is called when the port has been opened. cb is of the form cb(err).

port.close([cb])

Closes the serial port. If cb is specified, it is called when the port has been closed. cb is of the form cb(err).

Lots more methods

The SerialPort class inherits all of the methods and events of Readable and Writable interfaces.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Published

Version History

  • Version
    Downloads (Last 7 Days)
    • Published

Package Sidebar

Install

npm i trivial-port

Weekly Downloads

0

Version

0.3.2

License

MIT

Last publish

Collaborators

  • bminer