Search code examples
javascriptserial-portnode-serialport

Where is documentation for node-serialport new SerialPort options?


After searching carefully, I can't find documentation that tells me what options and what they do for the 2nd argument to new SerialPort()


Solution

  • Node Serialport documentation is quite terrible, for lack of a better description. It's laid out in a pretty nonsensical way and buries key information under strange or tangential subject headings.

    I think I understand what you're after; the openOptions you can pass after the path when creating a new Serialport object, right? Then it should be as follows:

    /**
     * @typedef {Object} openOptions
     * @property {boolean} [autoOpen=true] Automatically opens the port on `nextTick`.
     * @property {number=} [baudRate=9600] The baud rate of the port to be opened. This should match one of the commonly available baud rates, such as 110, 300, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, or 115200. Custom rates are supported best effort per platform. The device connected to the serial port is not guaranteed to support the requested baud rate, even if the port itself supports that baud rate.
     * @property {number} [dataBits=8] Must be one of these: 8, 7, 6, or 5.
     * @property {number} [highWaterMark=65536] The size of the read and write buffers defaults to 64k.
     * @property {boolean} [lock=true] Prevent other processes from opening the port. Windows does not currently support `false`.
     * @property {number} [stopBits=1] Must be one of these: 1 or 2.
     * @property {string} [parity=none] Must be one of these: 'none', 'even', 'mark', 'odd', 'space'.
     * @property {boolean} [rtscts=false] flow control setting
     * @property {boolean} [xon=false] flow control setting
     * @property {boolean} [xoff=false] flow control setting
     * @property {boolean} [xany=false] flow control setting
     * @property {object=} bindingOptions sets binding-specific options
     * @property {Binding=} Binding The hardware access binding. `Bindings` are how Node-Serialport talks to the underlying system. Will default to the static property `Serialport.Binding`.
     * @property {number} [bindingOptions.vmin=1] see [`man termios`](http://linux.die.net/man/3/termios) LinuxBinding and DarwinBinding
     * @property {number} [bindingOptions.vtime=0] see [`man termios`](http://linux.die.net/man/3/termios) LinuxBinding and DarwinBinding
     */
    

    So for example, to create a new SerialPort object with a baud of 9600 and no parity:

    var newPort = ("OS-appropriate comName here", { baudRate:9600, parity:"none"});
    

    This, for some reason, is buried here in the documentation instead of being front and centre: https://serialport.io/docs/api-stream