Classes
Members
-
<readonly> connected :boolean
-
Description
Whether there is an active serial connection
Details
-
<readonly, nullable> connectionId :number
-
Description
The id of the current serial connection
Details
-
<readonly, nullable> port :string
-
Description
The serial port currently in use (e.g.
COM3
,/dev/cu.usbmodem2101
, etc.). When no connection is active, this is set tonull
.Details
Methods
-
<async, static> getDevices( [ all ] ) → {Promise.<array>}
-
Description
Returns a list of serial devices likely to be Arduino-compatible. This list will always include all Arduino-compatible devices but, depending on the platform, may also include other serial devices as well. If the
all
parameter is set totrue
, it will systematically return all serial devices.Parameters
Name Type Attributes Default Description all
boolean <optional> false Whether to return all serial devices or only Arduino-compatible devices.
Returns
Details
-
<async, static> getSerialConnections() → {Promise.<array>}
-
Description
Returns a promise fulfilled with an array of currently opened serial port connections owned by the application.
Returns
Details
-
<async> connect( [ options ] ) → {Promise.<ConnectionInfo>}
-
Description
Tries to open a serial connection to the Arduino-compatible device hooked up to the port specified in the
options
parameter. If no port is specified, it tries to connect to the last port in the list obtained by calling Nward.getDevices.This is an asynchronous operation. When it succeeds, it returns a promise fulfilled with a Nward~ConnectionInfo object providing information about the established connection.
Parameters
Name Type Attributes Default Description options
Object <optional> {} Name Type Attributes Default Description port
string <optional> The port to connect to (
"COM3"
,"/dev/cu.usbmodem2101"
, etc.)bitrate
string <optional> 57600 The requested bitrate of the connection to be opened. For compatibility with the widest range of hardware, this number should match one of commonly-available bitrates such as:
- 110
- 300
- 1200
- 2400
- 4800
- 9600
- 14400
- 19200
- 38400
- 57600 (default)
- 115200
Returns
Fires
Details
-
<async> disconnect() → {Promise.<boolean>}
-
Description
Tries to disconnect the currently-active serial connection.
Returns
Details
-
<async> getConnectionInfo() → {Promise.<ConnectionInfo>}
-
Description
Retrieves the state of the currently-opened connection.
Returns
Details
-
<async> send( data [, appendNewline ] ) → {Promise.<SendInfo>}
-
Description
Sends the specified data to the Arduino. The data can be a
string
or anArrayBuffer
. If it's a string, a newline will be appended at the end (unlessappendNewline
is set tofalse
).Parameters
Name Type Attributes Default Description data
string | ArrayBuffer The data to send to the Arduino
appendNewline
boolean <optional> false Whether to automatically append a newline character when a string is sent.
Returns
Details
-
<async> sendMessage( command [, value ] ) → {Promise.<SendInfo>}
-
Description
Sends a message to the connected Arduino-compatible device.
Parameters
Name Type Attributes Description command
string value
int | Array.<int> <optional> Returns
Details
Type Definitions
-
ConnectionInfo
-
Description
The
ConnectionInfo
object provides details about a serial connexion. You can view all details about the ConnectionInfo object of the Chrome App Serial documentation.Properties
Name Type Attributes Description connectionId
integer paused
boolean persistent
boolean name
string bufferSize
integer receiveTimeout
integer sendTimeout
integer bitrate
integer <optional> dataBits
DataBits <optional> parityBit
ParityBits <optional> StopBits
StopBits <optional> ctsFlowControl
boolean <optional> Details
-
DeviceInfo
-
Description
This object provides information about a serial device.
Properties
Name Type Attributes Description path
string The device's system path. This should be passed as the
path
argument toconnect()
in order to connect to this device.vendorId
string <optional> A PCI or USB vendor ID if one can be determined for the underlying device.
productId
string <optional> A USB product ID if one can be determined for the underlying device.
displayName
string <optional> A human-readable display name for the underlying device if one can be queried from the host driver.
Details
-
SendInfo
-
Description
This object provides information about the send operation.
Properties
Name Type Attributes Description bytesSent
integer The number of bytes sent.
error
string <optional> An error code if an error occurred (disconnected, pending, timeout or system_error).
Details
Events
-
connected
-
Description
Event fired when the serial connection has been successfully established
Properties
Name Type Attributes Description connectionId
integer paused
boolean persistent
boolean name
string bufferSize
integer receiveTimeout
integer sendTimeout
integer bitrate
integer <optional> dataBits
DataBits <optional> parityBit
ParityBits <optional> StopBits
StopBits <optional> ctsFlowControl
boolean <optional> Details
-
disconnected
-
Description
Event fired when the serial connection has been disconnected
Properties
Name Type Description result
boolean Indicates whether or not the operation was successful
Details
-
received
-
Description
Event fired data has been received
Properties
Name Type Attributes Description type
string The type of message received
data
string <optional> The data
Details
-
sent
-
Description
Event fired when the data has been successfully sent
Properties
Name Type Attributes Description bytesSent
integer The number of bytes sent.
error
string <optional> An error code if an error occurred (disconnected, pending, timeout or system_error).
Details