Home Reference Source Test Repository
import {UART} from 'nextion/src/uart.js'
public class | source

UART

Extends:

EventEmitter → UART

Wraps a SerialPort or similar object; provides convenience methods for interaction with a Nextion over UART.

Static Method Summary

Static Public Methods
public static

Convenience wrapper of UART.fromPort and UART.fromSerial.

public static

Given a serial port name or path, or object containing one, create a Serialport instance, open the serial port, then return a {@link UART} instance.

public static

fromSerial(serialPort: Serialport | Duplex | *, opts: NextionOptions): Promise<UART>

Given a Serialport-like object, create a UART wrapper.

Constructor Summary

Public Constructor
public

Sets some default options

Member Summary

Public Members
public

true once we've successfully began listening via UART#bind.

Method Summary

Public Methods
public

Begins listening for data on the open serial port.

public

Makes a request to a Nextion device, expecting a response.

public

setValue(variableName: string, value: *): Promise<ResponseResult, Error>

Set variable variableName to value value.

Static Public Methods

public static from(port: string | Duplex | Serialport, opts: NextionOptions): Promise<UART> source

Convenience wrapper of UART.fromPort and UART.fromSerial.

Params:

NameTypeAttributeDescription
port string | Duplex | Serialport
  • optional

Port name or object

opts NextionOptions
  • optional

Options

Return:

Promise<UART>

New UART instance

public static fromPort(portName: string | NextionOptions, opts: NextionOptions): Promise<UART> source

Given a serial port name or path, or object containing one, create a Serialport instance, open the serial port, then return a {@link UART} instance. If no port name is present, we'll try to autodetect the port.

Params:

NameTypeAttributeDescription
portName string | NextionOptions
  • optional

Serial port name or path, or options

opts NextionOptions
  • optional
  • default: {}

Options

Return:

Promise<UART>

New UART instance

public static fromSerial(serialPort: Serialport | Duplex | *, opts: NextionOptions): Promise<UART> source

Given a Serialport-like object, create a UART wrapper. Synchronous, but returns a Promise for consistency.

Params:

NameTypeAttributeDescription
serialPort Serialport | Duplex | *

Serialport-like object

opts NextionOptions
  • optional
  • default: {}

Options

Return:

Promise<UART>

New UART instance

Public Constructors

public constructor(port: EventEmitter | Duplex, opts: NextionOptions) source

Sets some default options

Params:

NameTypeAttributeDescription
port EventEmitter | Duplex

Serial port interface

opts NextionOptions
  • optional
  • default: {}

Options

Public Members

public ready: boolean source

true once we've successfully began listening via UART#bind.

Public Methods

public bind(port: EventEmitter | Duplex): Promise<UART> source

Begins listening for data on the open serial port. If an event is emitted from the Nextion device, an event with a human-readable name will be emitted, along with any extra data, if present. Errors bubble up from the serial port object thru the UART instance.

Params:

NameTypeAttributeDescription
port EventEmitter | Duplex
  • optional

Serialport-like object to listen for data and errors on. Defaults to UART#port.

Return:

Promise<UART>

This UART instance

public request(commands: string[] | string, timeout: number): Promise<ResponseResult[]|ResponseResult, Error> source

Makes a request to a Nextion device, expecting a response.

Params:

NameTypeAttributeDescription
commands string[] | string

Command(s) to execute

timeout number
  • optional
  • default: 1000

How long to wait for response (in ms)

Return:

Promise<ResponseResult[]|ResponseResult, Error>

Result or array of results, or Error if device is not ready.

public setValue(variableName: string, value: *): Promise<ResponseResult, Error> source

Set variable variableName to value value. Boolean values true and false become 1 and 0, respectively.

Params:

NameTypeAttributeDescription
variableName string

Name of variable, component, system var, page, etc.

value *
  • optional

Will be coerced to a string.

Return:

Promise<ResponseResult, Error>

Result of setting value, or Error if device is not ready.