mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-26 02:47:17 +00:00
- [unix] small changes to flushing data during port open and setup to prevent bad data - [all] mock binding flush now works - cleanup on mock-binding pending reads - add `serialport-repl` as a bin and npm command
42 lines
1,019 B
JavaScript
Executable file
42 lines
1,019 B
JavaScript
Executable file
#!/usr/bin/env node
|
|
'use strict';
|
|
|
|
const serialport = require('../');
|
|
const version = require('../package.json').version;
|
|
const args = require('commander');
|
|
|
|
args
|
|
.version(version)
|
|
.description('List available serial ports')
|
|
.option('-f, --format <type>', 'Format the output as text, json, or jsonline. default: text', /^(text|json|jsonline)$/i, 'text')
|
|
.parse(process.argv);
|
|
|
|
const formatters = {
|
|
text(err, ports) {
|
|
if (err) {
|
|
console.error(err);
|
|
process.exit(1);
|
|
}
|
|
ports.forEach((port) => {
|
|
console.log(`${port.comName}\t${port.pnpId || ''}\t${port.manufacturer || ''}`);
|
|
});
|
|
},
|
|
json(err, ports) {
|
|
if (err) {
|
|
console.error(JSON.stringify(err));
|
|
process.exit(1);
|
|
}
|
|
console.log(JSON.stringify(ports));
|
|
},
|
|
jsonline(err, ports) {
|
|
if (err) {
|
|
console.error(JSON.stringify(err));
|
|
process.exit(1);
|
|
}
|
|
ports.forEach((port) => {
|
|
console.log(JSON.stringify(port));
|
|
});
|
|
}
|
|
};
|
|
|
|
serialport.list(formatters[args.format]);
|