mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-25 18:37:19 +00:00
[all] Add promise support to serialport-repl and improve docs
This commit is contained in:
parent
90931ddb04
commit
cc779624db
4 changed files with 99 additions and 13 deletions
|
|
@ -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.
|
||||
|
|
|
|||
48
README.md
48
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.
|
||||
|
|
|
|||
15
bin/repl.js
15
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)
|
||||
|
|
|
|||
|
|
@ -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": {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue