diff --git a/bin/actisense-file b/bin/actisense-file new file mode 100755 index 0000000..fb99f7f --- /dev/null +++ b/bin/actisense-file @@ -0,0 +1,47 @@ +#!/usr/bin/env node + +const { EventEmitter } = require('events'); + +var device + +const argv = require('minimist')(process.argv.slice(2), { + alias: { h: 'help' } +}) + +if ( argv['help'] ) { + console.error(`Usage: ${process.argv[0]} file + +Options: + -h, --help output usage information`) + process.exit(1) +} + +if ( argv['_'].length === 0 ) { + console.error('Please specify a file') + process.exit(1) +} + +const app = new EventEmitter(); + +const serial = new (require('../lib/serial'))({ app:app, plainText:true, disableSetTransmitPGNs: true, fromFile: true }) +const { Transform } = require('stream'); + +const toStringTr = new Transform({ + objectMode: true, + + transform(chunk, encoding, callback) { + this.push(chunk + "\n"); + callback(); + } +}); + +serial.pipe(toStringTr).pipe(process.stdout) + +filestream = require('fs').createReadStream(argv['_'][0]) +filestream.on('error', err => { + console.error(err.message) +}) +filestream.on('end', () => { + process.exit(0) +}) +filestream.pipe(serial) diff --git a/lib/serial.js b/lib/serial.js index 9009d04..b85d10b 100644 --- a/lib/serial.js +++ b/lib/serial.js @@ -609,7 +609,9 @@ function composeDisablePGN(pgn) { } SerialStream.prototype.end = function () { - this.serial.close() + if ( this.serial ) { + this.serial.close() + } } SerialStream.prototype._transform = function (chunk, encoding, done) {