Skip to content

Commit

Permalink
Merge pull request #17 from aj-ptw/master
Browse files Browse the repository at this point in the history
v1.1.3
  • Loading branch information
AJ Keller committed Apr 5, 2018
2 parents ff86180 + 96d7205 commit d50a5f5
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ hardwareVoltageOutputAll.txt
# For python
examples/python/dist/*
examples/python/openbci_node_python.egg-info/*

.vscode/
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.1.3

### Bug Fixes

* Connect function failed and forced close of port when serial port flushed too fast

# 1.1.2

### Bug Fixes
Expand Down
93 changes: 57 additions & 36 deletions examples/getStreaming/getStreaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,59 @@ let ourBoard = new Cyton({
verbose: verbose
});

ourBoard.autoFindOpenBCIBoard().then(portName => {
if (portName) {
/**
// If you know your port number then enter below if, you don't
// uncommecnt the listPorts function below to print the serial ports
// attached to your computer. You do need to have the FTDI VCP driver
// installed.
let portName = 'COM4';
// ourBoard.listPorts()
// .then((ports) => {
// console.log('ports', JSON.stringify(ports));
// });

// You can also pass the port name as a command line argument!
// i.e. windows
// > node .\examples\getStreaming\getStreaming.js COM5
// REMBEMER THE COM NUMBER CHANGES ON WINDOWS!!
// i.e. macOS
// $ node examples/getStreaming/getStreaming.js /dev/tty/usbserial-DB008JAM
const myArgs = process.argv.slice(2);
if (myArgs.length === 1) {
portName = myArgs[0];
}

ourBoard.on('sample', (sample) => {
/** Work with sample */
for (let i = 0; i < ourBoard.numberOfChannels(); i++) {
console.log(`Channel ${(i + 1)}: ${sample.channelData[i].toFixed(8)} Volts.`);
// prints to the console
// "Channel 1: 0.00001987 Volts."
// "Channel 2: 0.00002255 Volts."
// ...
// "Channel 8: -0.00001875 Volts."
}
});

/**
* Connect to the board with portName
* Only works if one board is plugged in
* i.e. ourBoard.connect(portName).....
*/
ourBoard.connect(portName) // Port name is a serial port name, see `.listPorts()`
.then(() => {
ourBoard.syncRegisterSettings()
.then((cs) => {
return ourBoard.streamStart();
})
.catch((err) => {
console.log('err', err);
return ourBoard.streamStart();
})
.catch((err) => {
console.log('fatal err', err);
process.exit(0);
});

ourBoard.on('sample', (sample) => {
/** Work with sample */
for (let i = 0; i < ourBoard.numberOfChannels(); i++) {
console.log(`Channel ${(i + 1)}: ${sample.channelData[i].toFixed(8)} Volts.`);
// prints to the console
// "Channel 1: 0.00001987 Volts."
// "Channel 2: 0.00002255 Volts."
// ...
// "Channel 8: -0.00001875 Volts."
}
});
});
} else {
/** Unable to auto find OpenBCI board */
console.log('Unable to auto find OpenBCI board');
}
});
ourBoard.connect(portName) // Port name is a serial port name, see `.listPorts()`
.then(() => {
return ourBoard.syncRegisterSettings();
})
.then((cs) => {
return ourBoard.streamStart();
})
.catch((err) => {
console.log('err', err);
return ourBoard.streamStart();
})
.catch((err) => {
console.log('fatal err', err);
process.exit(0);
});

function exitHandler (options, err) {
if (options.cleanup) {
Expand All @@ -67,7 +81,14 @@ function exitHandler (options, err) {
if (err) console.log(err.stack);
if (options.exit) {
if (verbose) console.log('exit');
ourBoard.disconnect().catch(console.log);
ourBoard.disconnect()
.then(() => {
process.exit(0);
})
.catch((err) => {
console.log(err);
process.exit(0);
});
}
}

Expand Down
2 changes: 0 additions & 2 deletions openBCICyton.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,6 @@ Cyton.prototype.connect = function (portName) {
}).then(() => {
if (this.options.verbose) console.log('Sending stop command, in case the device was left streaming...');
return this.write(k.OBCIStreamStop);
}).then(() => {
return new Promise(resolve => this.serial.flush(resolve));
}).then(() => {
// TODO: document why this 250 ms delay is needed
return new Promise(resolve => setTimeout(resolve, 250));
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": "openbci-cyton",
"version": "1.1.2",
"version": "1.1.3",
"description": "The official Node.js SDK for the OpenBCI Cyton with Dongle.",
"main": "openBCICyton.js",
"scripts": {
Expand Down

0 comments on commit d50a5f5

Please sign in to comment.