Node.js library to open serial ports for reading and writing
This lib probably doesn't work with Node 1 or higher. It was originally designed for Node v0.10 or v0.12. node-serialport has come a long way in terms of reliability and stability, so I'd recommend using that lib instead.
- Linux - Works
- Mac OSX - May work with a few minor tweaks
- Windows - It should work using the [
MODE
] (http://www.computerhope.com/modehlp.htm) command instead ofstty
. Checkout this StackOverflow post
Node doesn't really support talking to serial ports at the moment.
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.
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 thestty
command (defaults to /bin/stty)initTimeout
- maximum initialization duration (defaults to 10 seconds); set tonull
to allow an infinite amount of timesttyArgs
- an array of additional arguments to pass to thestty
command
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)
.
Closes the serial port. If cb
is specified, it is called when the port
has been closed. cb
is of the form cb(err)
.
The SerialPort
class inherits all of the methods and events of [Readable]
(http://nodejs.org/api/stream.html#stream_class_stream_readable) and [Writable]
(http://nodejs.org/api/stream.html#stream_class_stream_writable) interfaces.