new BaseBinding(options)
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 | options for the biding |
Properties:
Name | Type | Description |
---|---|---|
isOpen |
boolean | Required property. |
- Since:
- 5.0.0
- Source:
Throws:
-
When given invalid arguments, a
TypeError
is thrown. - Type
- TypeError
Methods
(static) list() → {Promise}
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.
- Source:
Returns:
resolves to an array of port info objects.
- Type
- Promise
close() → {Promise}
Closes an open connection
- Source:
Throws:
-
When given invalid arguments, a
TypeError
is thrown. - Type
- TypeError
Returns:
Resolves once the connection is closed.
- Type
- Promise
drain() → {Promise}
Drain waits until all output data is transmitted to the serial port. An in progress write should be completed before this returns.
- Source:
Throws:
-
When given invalid arguments, a
TypeError
is thrown. - Type
- TypeError
Returns:
Resolves once the drain operation finishes.
- Type
- Promise
flush() → {Promise}
Flush (discard) data received but not read, and written but not transmitted.
- Source:
Throws:
-
When given invalid arguments, a
TypeError
is thrown. - Type
- TypeError
Returns:
Resolves once the flush operation finishes.
- Type
- Promise
get() → {Promise}
Get the control flags (CTS, DSR, DCD) on the open port.
- Source:
Throws:
-
When given invalid arguments, a
TypeError
is thrown. - Type
- TypeError
Returns:
Resolves with the retrieved flags.
- Type
- Promise
getBaudRate() → {Promise}
Get the OS reported baud rate for the open port.
Used mostly for debugging custom baud rates.
- Source:
Throws:
-
When given invalid arguments, a
TypeError
is thrown. - Type
- TypeError
Returns:
Resolves with the current baud rate.
- Type
- Promise
open(path, options) → {Promise}
Opens a connection to the serial port referenced by the path.
Parameters:
Name | Type | Description |
---|---|---|
path |
string | the path or com port to open |
options |
openOptions | openOptions for the serialport |
- Source:
Throws:
-
When given invalid arguments, a
TypeError
is thrown. - Type
- TypeError
Returns:
Resolves after the port is opened and configured.
- Type
- Promise
read(buffer, offset, length) → {Promise}
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 |
---|---|---|
buffer |
buffer | Accepts a |
offset |
integer | The offset in the buffer to start writing at. |
length |
integer | Specifies the maximum number of bytes to read. |
- Source:
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}
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
|
- Source:
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}
Changes connection settings on an open port. Only baudRate
is supported.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
Only supports Properties
|
- Source:
Throws:
-
When given invalid arguments, a
TypeError
is thrown. - Type
- TypeError
Returns:
Resolves once the port's baud rate changes.
- Type
- Promise
write(buffer) → {Promise}
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 |
---|---|---|
buffer |
buffer | Accepts a |
- Source:
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