0.0.5 • Published 12 years ago

serialport2 v0.0.5

Weekly downloads
9
License
MIT
Repository
github
Last release
12 years ago

SerialPort2

Node.js serial port driver. Works on Windows, OSX, and linux.

Install

npm install serialport2

Quick Example

var SerialPort = require('../').SerialPort;
var port = new SerialPort();

port.on('data', function(data) {
  console.log(data.toString());
});

port.on('error', function(err) {
  console.log(err);
});

port.open('COM4', {
  baudRate: 9600,
  dataBits: 8,
  parity: 'none',
  stopBits: 1
}, function(err) {
  port.write("hello world");
  port.close();
});
var sp = require('../');
sp.list(function(err, ports) {
  console.log(ports);
});

API

SerialPort

new SerialPort()

Creates the serial port.

open(portName, options, callback)

Open the serial port.

Arguments

  • portName - The name of the port to open. Example: Windows 'COM1', Linux '/dev/ttyUSB0'.
  • options - Options for open
  • callback(err) - Callback called after opening the port.

write(buffer, callback)

Writes data to the serial port.

Arguments

  • buffer - This can be a node Buffer object or a string.
  • callback(err, byteWritten) - Callback called after writing bytes.

close(callback)

Closes the serial port.

Arguments

  • callback(err) - Callback called after the port is closed.

Event: data

Event emitted by SerialPort when data is available. The first argument will contain a Buffer with the data.

Event: error

Event emitted by SerialPort if an error occurs. The first argument will contain the error.

list(callback)

Lists the serial ports on the machine.

Arguments

  • callback(err, ports) - Callback called after the list is retrieved.
0.0.5

12 years ago

0.0.4

12 years ago

0.0.3

12 years ago

0.0.2

12 years ago

0.0.1

12 years ago