new BaseBinding(options)
+ + + + + + +-
+
+
+
- Source: +
- + bindings/base.js, line 16 +
+
+
+
+
+
+ - Since: +
- 5.0.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Properties:
+ + + +Name | + + +Type | + + + + + +Description | +
---|---|---|
isOpen |
+
+
+ + + +boolean + + + + | + + + + + +Required property. |
+
You never have to use Binding
objects directly. SerialPort uses them to access the underlying hardware. This documentation is geared towards people who are making bindings for different platforms. This class can be inherited from to get type checking for each method.
Parameters:
+ + +Name | + + +Type | + + + + + +Description | +
---|---|---|
options |
+
+
+ + + +object + + + + | + + + + + ++ |
Throws:
+ + + +-
+
-
+ ++
When given invalid arguments, a
+TypeError
is thrown.
+
+ - +
- + Type + +
- + +TypeError + + + +
-
+
Methods
+ + + + + + +(static) list() → {Promise}
+ + + + + + +-
+
+
+
- Source: +
- + bindings/base.js, line 29 +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Retrieves a list of available serial ports with metadata. The comName
must be guaranteed, and all other fields should be undefined if unavailable. The comName
is either the path or an identifier (eg COM1
) used to open the serialport.
Returns:
+ + +resolves to an array of port info objects.
+-
+
- + Type + +
- + +Promise + + + +
close() → {Promise}
+ + + + + + +-
+
+
+
- Source: +
- + bindings/base.js, line 68 +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Closes an open connection
+Throws:
+ + + +-
+
-
+ ++
When given invalid arguments, a
+TypeError
is thrown.
+
+ - +
- + Type + +
- + +TypeError + + + +
-
+
Returns:
+ + +Resolves once the connection is closed.
+-
+
- + Type + +
- + +Promise + + + +
drain() → {Promise}
+ + + + + + +-
+
+
+
- Source: +
- + bindings/base.js, line 222 +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Drain waits until all output data is transmitted to the serial port. An in progress write should be completed before this returns.
+Throws:
+ + + +-
+
-
+ ++
When given invalid arguments, a
+TypeError
is thrown.
+
+ - +
- + Type + +
- + +TypeError + + + +
-
+
Returns:
+ + +Resolves once the drain operation finishes.
+-
+
- + Type + +
- + +Promise + + + +
flush() → {Promise}
+ + + + + + +-
+
+
+
- Source: +
- + bindings/base.js, line 209 +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Flush (discard) data received but not read, and written but not transmitted.
+Throws:
+ + + +-
+
-
+ ++
When given invalid arguments, a
+TypeError
is thrown.
+
+ - +
- + Type + +
- + +TypeError + + + +
-
+
Returns:
+ + +Resolves once the flush operation finishes.
+-
+
- + Type + +
- + +Promise + + + +
get() → {Promise}
+ + + + + + +-
+
+
+
- Source: +
- + bindings/base.js, line 182 +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Get the control flags (CTS, DSR, DCD) on the open port.
+Throws:
+ + + +-
+
-
+ ++
When given invalid arguments, a
+TypeError
is thrown.
+
+ - +
- + Type + +
- + +TypeError + + + +
-
+
Returns:
+ + +Resolves with the retrieved flags.
+-
+
- + Type + +
- + +Promise + + + +
getBaudRate() → {Promise}
+ + + + + + +-
+
+
+
- Source: +
- + bindings/base.js, line 196 +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Get the OS reported baud rate for the open port.
Used mostly for debugging custom baud rates.
Throws:
+ + + +-
+
-
+ ++
When given invalid arguments, a
+TypeError
is thrown.
+
+ - +
- + Type + +
- + +TypeError + + + +
-
+
Returns:
+ + +Resolves with the current baud rate.
+-
+
- + Type + +
- + +Promise + + + +
open(path, openOptions) → {Promise}
+ + + + + + +-
+
+
+
- Source: +
- + bindings/base.js, line 47 +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Opens a connection to the serial port referenced by the path.
+Parameters:
+ + +Name | + + +Type | + + + + + +Description | +
---|---|---|
path |
+
+
+ + + +string + + + + | + + + + + ++ |
openOptions |
+
+
+ + + +module:serialport~openOptions + + + + | + + + + + ++ |
Throws:
+ + + +-
+
-
+ ++
When given invalid arguments, a
+TypeError
is thrown.
+
+ - +
- + Type + +
- + +TypeError + + + +
-
+
Returns:
+ + +Resolves after the port is opened and configured.
+-
+
- + Type + +
- + +Promise + + + +
read(data, offset, length) → {Promise}
+ + + + + + +-
+
+
+
- Source: +
- + bindings/base.js, line 87 +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Request a number of bytes from the SerialPort. This function is similar to Node's fs.read
except it will always return at least one byte.
The in progress reads must error when the port is closed with an error object that has the property canceled
equal to true
. Any other error will cause a disconnection.
Parameters:
+ + +Name | + + +Type | + + + + + +Description | +
---|---|---|
data |
+
+
+ + + +buffer + + + + | + + + + + +Accepts a |
+
offset |
+
+
+ + + +integer + + + + | + + + + + +The offset in the buffer to start writing at. |
+
length |
+
+
+ + + +integer + + + + | + + + + + +Specifies the maximum number of bytes to read. |
+
Throws:
+ + + +-
+
-
+ ++
When given invalid arguments, a
+TypeError
is thrown.
+
+ - +
- + Type + +
- + +TypeError + + + +
-
+
Returns:
+ + +Resolves with the number of bytes read after a read operation.
+-
+
- + Type + +
- + +Promise + + + +
set(optionsopt) → {Promise}
+ + + + + + +-
+
+
+
- Source: +
- + bindings/base.js, line 166 +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Set control flags on an open port.
+Parameters:
+ + +Name | + + +Type | + + +Attributes | + + + + +Description | +||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
+
+
+ + + +object + + + + | + + +
+
+ <optional> + + + + + + |
+
+
+
+
+ All options are operating system default when the port is opened. Every flag is set on each call to the provided or default values. All options are always provided. +Properties+ + +
|
+
Throws:
+ + + +-
+
-
+ ++
When given invalid arguments, a
+TypeError
is thrown.
+
+ - +
- + Type + +
- + +TypeError + + + +
-
+
Returns:
+ + +Resolves once the port's flags are set.
+-
+
- + Type + +
- + +Promise + + + +
update(optionsopt) → {Promise}
+ + + + + + +-
+
+
+
- Source: +
- + bindings/base.js, line 139 +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Changes connection settings on an open port. Only baudRate
is supported.
Parameters:
+ + +Name | + + +Type | + + +Attributes | + + + + +Description | +||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
options |
+
+
+ + + +object + + + + | + + +
+
+ <optional> + + + + + + |
+
+
+
+
+ Only supports Properties+ + +
|
+
Throws:
+ + + +-
+
-
+ ++
When given invalid arguments, a
+TypeError
is thrown.
+
+ - +
- + Type + +
- + +TypeError + + + +
-
+
Returns:
+ + +Resolves once the port's baud rate changes.
+-
+
- + Type + +
- + +Promise + + + +
write(data) → {Promise}
+ + + + + + +-
+
+
+
- Source: +
- + bindings/base.js, line 120 +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Write bytes to the SerialPort. Only called when there is no pending write operation.
+The in progress writes must error when the port is closed with an error object that has the property canceled
equal to true
. Any other error will cause a disconnection.
Parameters:
+ + +Name | + + +Type | + + + + + +Description | +
---|---|---|
data |
+
+
+ + + +buffer + + + + | + + + + + +Accepts a |
+
Throws:
+ + + +-
+
-
+ ++
When given invalid arguments, a
+TypeError
is thrown.
+
+ - +
- + Type + +
- + +TypeError + + + +
-
+
Returns:
+ + +Resolves after the data is passed to the operating system for writing.
+-
+
- + Type + +
- + +Promise + + + +