new Nward()

Description

The Nward class provides methods to communicate via serial to an Arduino-compatible device. It extends the EventEmitter class from djipevents.

Details

Classes


new Nward()

Members


<readonly> connected :boolean

Description

Whether there is an active serial connection

Details
boolean

<readonly, nullable> connectionId :number

Description

The id of the current serial connection

Details
number

<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 to null.

Details
string

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 to true, 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

An array of Nward~DeviceInfo objects describing the devices found.

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

The promise is fulfilled with an array of Nward~ConnectionInfo objects.

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

The promise is fulfilled with a Nward~ConnectionInfo object providing details about the connection.

Details

<async> disconnect() → {Promise.<boolean>}

Description

Tries to disconnect the currently-active serial connection.

Returns

A promise fulfilled with a boolean value representing the result of the operation.

Details

<async> getConnectionInfo() → {Promise.<ConnectionInfo>}

Description

Retrieves the state of the currently-opened connection.

Returns

The promise is fulfilled with a Nward~ConnectionInfo object providing details about the connection.

Details

<async> send( data [, appendNewline ] ) → {Promise.<SendInfo>}

Description

Sends the specified data to the Arduino. The data can be a string or an ArrayBuffer. If it's a string, a newline will be appended at the end (unless appendNewline is set to false).

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
Object

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 to connect() 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
Object

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
Object

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
ConnectionInfo

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
object

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
object

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
SendInfo