mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-26 02:47:17 +00:00
This has always been the dream. Use `fs.read` and `fs.write` to do reading and writing. To make that happen I've created a cross platform `Poller` object that notifies us once on `readable` and `writable` states. - Reduce large write cpu usage from 100% to 1-2% - Replace ReadPoller with a multi purpose poller because you can only have a single uv_poll_t on a fd at a time because reasons - Experimented with doing this all in c++, maybe there are gains to doing that but I'd never finish. - Some unrelated eslint changes - Arduino echo should just echo, writing random bytes was messing it up - use a file to disable tests in envs - read and write errors can trigger disconnects - disconnect event only happens if there are listeners, otherwise error events will be triggered - a disconnect during write will always have a write error too - win32 bindings seem to only trigger disconnects on writes
26 lines
527 B
JavaScript
26 lines
527 B
JavaScript
/* eslint-disable node/no-missing-require */
|
|
'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
|