Skip to content

Commit

Permalink
Done #14
Browse files Browse the repository at this point in the history
  • Loading branch information
niklauslee committed Jul 7, 2020
1 parent 14bf4d2 commit 0b37609
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,18 @@ Here are some commands which can be sent to Kameleon Agent.
#### cmd:list

* `callback`: `<Function>`
* `err` : `<Error>`
* `devices` : `<Array<DeviceObject>>`

Request a list of available devices (ready to open -- _already plugged to USB or discovered wirelessly_) connected via serial ports.

```js
socket_client.emit('cmd:list', (deviceObjects) => {
console.log(deviceObjects)
socket_client.emit('cmd:list', (err, deviceObjects) => {
if (err) {
// handle error
} else {
console.log(deviceObjects)
}
})
```

Expand Down
4 changes: 3 additions & 1 deletion lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,18 @@ class Session extends EventEmitter {

/**
* List all available devices
* @param {(err: Error, devices) => void} cb
*/
list (cb) {
SerialPort.list((err, portInfos) => {
if (err) {
if (cb) cb(err);
this.socket.emit('event:error', err)
} else {
this.portInfoArray = portInfos
.filter(p => isSupported(p))
.map(p => toDeviceObject(p))
if (cb) cb(this.portInfoArray)
if (cb) cb(null, this.portInfoArray)
this.portInfoArray.forEach(p => {
logger.info(` [cmd:list] ${p.comName}`)
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kameleon-agent",
"version": "0.8.0",
"version": "0.8.1",
"author": "Minkyu Lee",
"engines": {
"node": "10.15.3"
Expand Down

0 comments on commit 0b37609

Please sign in to comment.