Mixin: AsciiHandler

AsciiHandler

Provides parsing of ASCII serial data, e.g. from a serial port or socket.

Members


<readonly> connected :bool

Returns true when successfully connected. The details of connected are defined by the class inheriting AsciiHandler.

Type:
  • bool
Since:
  • 1.0

delimAnd :bool

Gets/sets if all delimiters need to appear in order, or just one. True means all delimiters need to appear in order.

Type:
  • bool
Since:
  • 1.0
Default Value:
  • false
See:

<readonly> delimiter :Array.<number>

Gets/sets the delimiting characters.

When a delimiter is detected in the serial stream, the data read up until the delimiter is forwarded to the application via dataReceived. The delimiter itself is not included in the data if delimStrip is true. If the data is empty after stripping the delimiter and dropEmpty is true, no event will be generated.

If delimAnd is true, all of the specified delimiters, in the order specified, must appear in the stream to trigger dataReceived. Otherwise, any single delimiter from the list will trigger dataRecevied.

It is acceptable to set the delimiter to a string instead of a number array.

Type:
  • Array.<number>
Since:
  • 1.0
Default Value:
  • []

delimStrip :bool

Gets/sets if all the delimiter should be included in the data or stripped. True means the delimiter should be removed before generating the event.

Type:
  • bool
Since:
  • 1.0
Default Value:
  • false
See:

dropEmpty :bool

Gets/sets if an event will be generated even if there is no data. True will cause empty frames to be ignored.

Type:
  • bool
Since:
  • 1.0
Default Value:
  • false
See:

eomTime :number

Gets/sets the end of message time. The EOM time is the number of milliseconds to wait after becoming idle (no data received) before triggering the receive event. For example, to event the data every time there is a minimum gap of 100ms, set the eomTime to 100.

Set to 0 to disable.

Type:
  • number
Since:
  • 1.2
Default Value:
  • 0

frameLen :bool

Gets/sets the maximum frame length. The frame length is the maximum number of characters that can be received before triggering the receive event. If this number is reached, the event will be triggered event if the delimiters have not been detected or the timer expired.

Type:
  • bool
Since:
  • 1.0
Default Value:
  • 128

monitorMode :bool

Gets/sets monitor mode. Monitor mode, when enabled, will cause the dataSent event to emit all data sent by the application. A common use of this event is a monitoring program that shows all data sent and recieved.

Type:
  • bool
Since:
  • 2.1
Default Value:
  • false

paceTime :number

Gets/sets the pace time. The pace time is the number of milliseconds to wait between receiving a character into an empty buffer and triggering the receive event. For example, to make sure that data is evented a maximum of 100ms after it is received, set the paceTime to 100.

Set to 0 to disable.

Type:
  • number
Since:
  • 1.2
Default Value:
  • 0

Methods


close()

Attempts to close the serial device. The details of what happens on close are defined by the inheriting class.

Since:
  • 1.0

flush()

Ensures that all pending data has been written to the serial device. This is useful for synchronizing since it blocks until the data has been sent.

Since:
  • 1.2

open()

Attempts to open the serial device. The details of what happens on open are defined by the inheriting class.

Since:
  • 1.0
Returns:

Indicates if the open was successful (or started successfully)

Type
bool

push(bytes)

Sends data to the serial device.

Parameters:
Name Type Description
bytes Array.<number> | string

The data to send

Since:
  • 1.0
Returns:

Indicates if the bytes successfully started sending

Type
bool
Example
dev.push("Hello world");

reset()

Resets properties to the default value. Useful for resetting to a known state when re-configuring.

Since:
  • 1.0

Events


closed

Emitted when the device been closed.

Since:
  • 1.0

dataReceived

Indicates that data has been received. How often it fires and/or what data is emitted is defined by the configuration properties.

Type: object
Properties:
Name Type Description
str string

String representation of the data

bytes Array.<number>

Raw values of the bytes received

length number

Number of bytes received

Since:
  • 1.0
Example
dev.dataReceived.connect(function(data) {
   console.log("Read '" + data.str + "' from device");
});

dataSent

Indicates that data has been sent by the application. monitorMode must be enabled before this event will fire.

Type: object
Properties:
Name Type Description
str string

String representation of the data

bytes Array.<number>

Raw values of the bytes sent

length number

Number of bytes sent

Since:
  • 2.1
Example
dev.monitorMode = true;
dev.dataSent.connect(function(data) {
   console.log("Sent '" + data.str + "' to device");
});

opened

Emitted when the device has successfully opened.

Since:
  • 1.0