From cc779624dbd08bab5694e5058ad040cbac2a8a00 Mon Sep 17 00:00:00 2001 From: Francis Gulotta Date: Fri, 28 Jul 2017 19:10:29 -0700 Subject: [PATCH] [all] Add promise support to serialport-repl and improve docs --- .docs/README.hbs | 48 +++++++++++++++++++++++++++++++++++++++++++++--- README.md | 48 +++++++++++++++++++++++++++++++++++++++++++++--- bin/repl.js | 15 ++++++++------- package.json | 1 + 4 files changed, 99 insertions(+), 13 deletions(-) diff --git a/.docs/README.hbs b/.docs/README.hbs index 6426a79..8b3ccd2 100644 --- a/.docs/README.hbs +++ b/.docs/README.hbs @@ -70,6 +70,7 @@ In addition to reading the [article mentioned above](http://www.voodootikigod.co * [Command Line Tools](#command-line-tools) * [Serial Port List](#serial-port-list) * [Serial Port Terminal](#serial-port-terminal) + * [Serial Port Repl](#serial-port-repl) * [License](#license) *** @@ -353,15 +354,23 @@ DEBUG=* node myapp.js ``` You can enable core dumps on osx with; -``` +```bash ulimit -c unlimited for core dumps ``` You can "console.log" from c++ with; -``` +```c++ fprintf(stdout, "Hellow World num=%d str=%s\n", 4, "hi"); ``` +You can make use of the `serialport-repl` command with; +```bash +serialport-repl # to auto detect an arduino +serialport-repl /path/name # to connect to a specific port +``` + +It will load a serialport object with debugging turned on. + ### Error Handling All functions in Node-Serialport follow two conventions: @@ -408,7 +417,7 @@ $ serialport-list -f jsonline ``` ### Serial Port Terminal -`serialport-term provides a basic terminal interface for communicating over a serial port. `ctrl+c` will exit. +`serialport-term` provides a basic terminal interface for communicating over a serial port. `ctrl+c` will exit. ```bash $ serialport-term -h @@ -434,5 +443,38 @@ $ serialport-term -l /dev/cu.usbmodem1421 Arduino (www.arduino.cc) ``` +### Serial Port Repl +`serialport-repl` provides a nodejs repl for working with serialport. This is valuable when debugging. + +You can make use of the `serialport-repl` command with; +```bash +serialport-repl # to auto detect an arduino +serialport-repl /path/name # to connect to a specific port +``` + +It will load a serialport object with debugging turned on. +``` + serialport:binding:auto-detect loading DarwinBinding +0ms +port = SerialPort("/path/name", { autoOpen: false }) +globals { SerialPort, portName, port } +> SerialPort.list() + serialport:main .list +6s +[ { comName: '/path/name', + manufacturer: undefined, + serialNumber: undefined, + pnpId: undefined, + locationId: undefined, + vendorId: undefined, + productId: undefined } ] +> port.write('Calling all Autobots!') +true +> port.read() + serialport:main _read queueing _read for after open +1m +null +> port.open() + serialport:main opening path: serialport-repl +30s + serialport:bindings open +1ms +``` + ## License SerialPort is [MIT licensed](LICENSE) and all it's dependencies are MIT or BSD licensed. diff --git a/README.md b/README.md index 7d6f3e9..c9d22e8 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,7 @@ In addition to reading the [article mentioned above](http://www.voodootikigod.co * [Command Line Tools](#command-line-tools) * [Serial Port List](#serial-port-list) * [Serial Port Terminal](#serial-port-terminal) + * [Serial Port Repl](#serial-port-repl) * [License](#license) *** @@ -400,15 +401,23 @@ DEBUG=* node myapp.js ``` You can enable core dumps on osx with; -``` +```bash ulimit -c unlimited for core dumps ``` You can "console.log" from c++ with; -``` +```c++ fprintf(stdout, "Hellow World num=%d str=%s\n", 4, "hi"); ``` +You can make use of the `serialport-repl` command with; +```bash +serialport-repl # to auto detect an arduino +serialport-repl /path/name # to connect to a specific port +``` + +It will load a serialport object with debugging turned on. + ### Error Handling All functions in Node-Serialport follow two conventions: @@ -1138,7 +1147,7 @@ $ serialport-list -f jsonline ``` ### Serial Port Terminal -`serialport-term provides a basic terminal interface for communicating over a serial port. `ctrl+c` will exit. +`serialport-term` provides a basic terminal interface for communicating over a serial port. `ctrl+c` will exit. ```bash $ serialport-term -h @@ -1164,5 +1173,38 @@ $ serialport-term -l /dev/cu.usbmodem1421 Arduino (www.arduino.cc) ``` +### Serial Port Repl +`serialport-repl` provides a nodejs repl for working with serialport. This is valuable when debugging. + +You can make use of the `serialport-repl` command with; +```bash +serialport-repl # to auto detect an arduino +serialport-repl /path/name # to connect to a specific port +``` + +It will load a serialport object with debugging turned on. +``` + serialport:binding:auto-detect loading DarwinBinding +0ms +port = SerialPort("/path/name", { autoOpen: false }) +globals { SerialPort, portName, port } +> SerialPort.list() + serialport:main .list +6s +[ { comName: '/path/name', + manufacturer: undefined, + serialNumber: undefined, + pnpId: undefined, + locationId: undefined, + vendorId: undefined, + productId: undefined } ] +> port.write('Calling all Autobots!') +true +> port.read() + serialport:main _read queueing _read for after open +1m +null +> port.open() + serialport:main opening path: serialport-repl +30s + serialport:bindings open +1ms +``` + ## License SerialPort is [MIT licensed](LICENSE) and all it's dependencies are MIT or BSD licensed. diff --git a/bin/repl.js b/bin/repl.js index 8d66a94..e6a9793 100755 --- a/bin/repl.js +++ b/bin/repl.js @@ -1,5 +1,8 @@ #!/usr/bin/env node 'use strict'; +const repl = require('repl'); +const promirepl = require('promirepl').promirepl; + process.env.DEBUG = process.env.DEBUG || '*'; const SerialPort = require('../'); @@ -20,24 +23,22 @@ function findArduino() { } }); if (!resolved) { - reject(new Error('No arduinos found')); + reject(new Error('No arduinos found. You must specify a port to load.\n\nFor example:\n\tserialport-repl COM3\n\tserialport-repl /dev/tty.my-serialport')); } }); }); } -const repl = require('repl'); -// const { promirepl } = require('promirepl') - findArduino().then((portName) => { + console.log(`port = SerialPort("${portName}", { autoOpen: false })`); + console.log('globals { SerialPort, portName, port }'); const port = new SerialPort(portName, { autoOpen: false }); const spRepl = repl.start({ prompt: '> ' }); + promirepl(spRepl); spRepl.context.SerialPort = SerialPort; spRepl.context.portName = portName; spRepl.context.port = port; }).catch((e) => { - console.log(e.message); + console.error(e.message); process.exit(1); }); - -// promirepl(graphRepl) diff --git a/package.json b/package.json index 4071145..4ac608f 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "debug": "^2.6.6", "nan": "^2.6.2", "node-pre-gyp": "^0.6.36", + "promirepl": "^1.0.1", "safe-buffer": "^5.0.1" }, "devDependencies": {