mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-26 02:47:17 +00:00
- Move Parsers into a directory - Move Bindings into a directory - Add a linter for require calls
26 lines
530 B
JavaScript
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
|