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
allparameter is set totrue, it will systematically return all serial devices.Parameters
Name Type Attributes Default Description allboolean <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
optionsparameter. 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 optionsObject <optional> {} Name Type Attributes Default Description portstring <optional> The port to connect to (
"COM3","/dev/cu.usbmodem2101", etc.)bitratestring <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
stringor anArrayBuffer. If it's a string, a newline will be appended at the end (unlessappendNewlineis set tofalse).Parameters
Name Type Attributes Default Description datastring | ArrayBuffer The data to send to the Arduino
appendNewlineboolean <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 commandstring valueint | Array.<int> <optional> Returns
Details
Type Definitions
-
ConnectionInfo
-
Description
The
ConnectionInfoobject 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 connectionIdinteger pausedboolean persistentboolean namestring bufferSizeinteger receiveTimeoutinteger sendTimeoutinteger bitrateinteger <optional> dataBitsDataBits <optional> parityBitParityBits <optional> StopBitsStopBits <optional> ctsFlowControlboolean <optional> Details
-
DeviceInfo
-
Description
This object provides information about a serial device.
Properties
Name Type Attributes Description pathstring The device's system path. This should be passed as the
pathargument toconnect()in order to connect to this device.vendorIdstring <optional> A PCI or USB vendor ID if one can be determined for the underlying device.
productIdstring <optional> A USB product ID if one can be determined for the underlying device.
displayNamestring <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 bytesSentinteger The number of bytes sent.
errorstring <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 connectionIdinteger pausedboolean persistentboolean namestring bufferSizeinteger receiveTimeoutinteger sendTimeoutinteger bitrateinteger <optional> dataBitsDataBits <optional> parityBitParityBits <optional> StopBitsStopBits <optional> ctsFlowControlboolean <optional> Details
-
disconnected
-
Description
Event fired when the serial connection has been disconnected
Properties
Name Type Description resultboolean Indicates whether or not the operation was successful
Details
-
received
-
Description
Event fired data has been received
Properties
Name Type Attributes Description typestring The type of message received
datastring <optional> The data
Details
-
sent
-
Description
Event fired when the data has been successfully sent
Properties
Name Type Attributes Description bytesSentinteger The number of bytes sent.
errorstring <optional> An error code if an error occurred (disconnected, pending, timeout or system_error).
Details