mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-26 02:47:17 +00:00
* upgrade to non deprecated buffer methods * Don't lint on node 4 as it's now broken I really wish packages would keep things working on LTS platforms.
33 lines
835 B
JavaScript
Executable file
33 lines
835 B
JavaScript
Executable file
#!/usr/bin/env node
|
|
'use strict';
|
|
|
|
const args = require('commander');
|
|
const Buffer = require('safe-buffer').Buffer;
|
|
const SerialPort = require('../');
|
|
const version = require('../package.json').version;
|
|
|
|
const readyData = Buffer.from('READY');
|
|
|
|
args
|
|
.version(version)
|
|
.usage('-p <port>')
|
|
.description('A basic terminal interface for communicating over a serial port. Pressing ctrl+c exits.')
|
|
.option('-p, --port <port>', 'Path or Name of serial port')
|
|
.parse(process.argv);
|
|
|
|
if (!args.port) {
|
|
args.outputHelp();
|
|
args.missingArgument('port');
|
|
process.exit(-1);
|
|
}
|
|
|
|
const port = new SerialPort(args.port);
|
|
|
|
port.on('open', () => {
|
|
console.log(`echo: Port open: ${args.port}`);
|
|
setTimeout(() => {
|
|
console.log('echo: READY!');
|
|
port.on('data', data => port.write(data));
|
|
port.write(readyData);
|
|
}, 250);
|
|
});
|