When opening a serial port, specify (in this order)
- Path to Serial Port - required.
- Options - optional and described below.
SerialPort object immediately opens a port. While you can read and write at any time (it will be queued until the port is open), most port functions require an open port. There are three ways to detect when a port is opened.
openevent is always emitted when the port is opened.
- The constructor's openCallback is passed to
.open(), if you haven't disabled the
autoOpenoption. If you have disabled it, the callback is ignored.
.open()function takes a callback that is called after the port is opened. You can use this if you've disabled the
autoOpenoption or have previously closed an open port.
Detecting open errors can be moved to the constructor's callback.
When disabling the
autoOpen option you'll need to open the port on your own.
Get updates of new data from the serial port as follows:
You can write to the serial port by sending a string or buffer to the write method:
Enjoy and do cool things with this code.