Open petewall opened 6 years ago
I tried to delay the call to connect by doing this:
const { Cyton } = require('openbci-observable');
async function init () {
const cyton = new Cyton({ verbose: true });
setTimeout(async function () {
await cyton.connect();
await cyton.start();
cyton.stream.subscribe(sample =>
console.log('sample', sample)
);
}, 1000);
}
init();
However, I noticed that the call to connect() is actually blowing away the portName.
Cyton.prototype.connect = function (portName) {
...
this.portName = portName;
if (this.options.verbose) console.log('using real board ' + portName);
this.serial = new SerialPort(portName, {
...
So, calling connect()
with no arguments will not work.
I changed the line in my code to await cyton.connect(cyton.portName);
, now will use the auto discovered serial port.
This however doesn't solve the problem of connect(portName)
being called before the constructor has resolved the port in the constructor's call to the init() function. Since a constructor doesn't return a promise, I don't know if we can await
it. However, if I just resign to auto-discover the port a second time, I can await
on that.
This is my code that can successfully connect to my Cyton board and stream data:
const { Cyton } = require('openbci-observable');
async function init () {
const cyton = new Cyton({ verbose: true });
await cyton.autoFindOpenBCIBoard();
await cyton.connect(cyton.portName);
await cyton.start();
cyton.stream.subscribe(sample =>
console.log('sample', sample)
);
}
init();
If it helps. I'm using Mac OS X 10.13.3, with node version 9.8.0.
I'm trying to run the Cyton example code and I'm getting a "No path specified" exception
Here's the code that I'm using:
Inside
new Cyton()
, the init function callsautoFindOpenBCIBoard()
, which tries to find a valid serial port. If successful, it ends with this code:However, this doesn't block the call to
await cyton.connect();
which tries to connect toportName
which is undefined.