node-serialport-bindings-cpp/examples/readline.js
Francis Gulotta c40c24972a Reorganize files for clarity
- Move Parsers into a directory
- Move Bindings into a directory
- Add a linter for require calls
2017-01-07 00:23:20 -05:00

26 lines
530 B
JavaScript

/* eslint-disable require-path-exists/exists */
'use strict';
// Use a Readline parser
const SerialPort = require('serialport');
const parsers = SerialPort.parsers;
// Use a `\r\n` as a line terminator
const parser = new parsers.Readline({
delimiter: '\r\n'
});
const port = new SerialPort('/dev/tty-usbserial1', {
baudRate: 57600
});
port.pipe(parser);
port.on('open', () => console.log('Port open'));
parser.on('data', console.log);
port.write('ROBOT PLEASE RESPOND\n');
// The parser will emit any string response