Skip to content
This repository has been archived by the owner on Jul 29, 2020. It is now read-only.

UnhandledPromiseRejectionWarning: TypeError: No path specified #24

Open
petewall opened this issue Mar 18, 2018 · 3 comments
Open

UnhandledPromiseRejectionWarning: TypeError: No path specified #24

petewall opened this issue Mar 18, 2018 · 3 comments

Comments

@petewall
Copy link

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:

const { Cyton } = require('openbci-observable');

async function init () {
    const cyton = new Cyton();
    await cyton.connect();
    await cyton.start();

    cyton.stream.subscribe(sample =>
        console.log('sample', sample)
    );
}

init();

Inside new Cyton(), the init function calls autoFindOpenBCIBoard(), which tries to find a valid serial port. If successful, it ends with this code:

          if (this.options.verbose) console.log('auto found board');
          resolve(this.portName);

However, this doesn't block the call to await cyton.connect(); which tries to connect to portName which is undefined.

@petewall
Copy link
Author

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.

@petewall
Copy link
Author

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();

@petewall
Copy link
Author

If it helps. I'm using Mac OS X 10.13.3, with node version 9.8.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant