node-serialport icon indicating copy to clipboard operation
node-serialport copied to clipboard

Incorrect Documentation of open()

Open hellerim opened this issue 2 years ago • 1 comments

SerialPort Version

10.4.0

Node Version

18.4.0

Electron Version

No response

Platform

No response

Architecture

No response

Hardware or chipset of serialport

No response

What steps will reproduce the bug?

Documentation states that open() receives an options object.

What happens?

If I use it with an empty object, open complan that callback is not a function.

What should have happened?

Document should state that a callback is expected.

Additional information

As open is defined in the SerialPortStream class, a quick look shows that, indeed, a callback function is expected. By the way, it would be nice if the doc was a little bit more explicit about callbacks - is a callback meant to be an error handler only, or does accept the usual two arguments (error, result) in the respective cases? Actually, I'd like to get things done and use a library instead of being forced to scan its source code (although, this might be instructive - if there is enough spare time).

hellerim avatar Aug 01 '22 17:08 hellerim

I've taken a look and am struggling to find anywhere that is requiring a callback, except perhaps if autoOpen is set: https://github.com/serialport/node-serialport/blob/cb2af2fca6689a1bd085731f85884ad1987bf3ab/packages/stream/lib/index.ts#L116-L118

If that is the case, do we just need to check if openCallback has been defined per the below? or am I misunderstanding the issue?:

if (this.settings.autoOpen) {
    if (openCallback) {
      this.open(openCallback)
    } else {
      this.open()
    }
}

If this is the case then it feels like a code fix rather than a documentation fix would be preferable

GazHank avatar Jun 27 '23 15:06 GazHank