Class Transport

Wrapper class around Webserial API to communicate with the serial device.

Param

Requested device prompted by the browser.

const port = await navigator.serial.requestPort();

Hierarchy

  • Transport

Constructors

  • Parameters

    • device: SerialPort
    • tracing: boolean = false
    • enableSlipReader: boolean = true

    Returns Transport

Properties

SLIP_END: number = 0xc0
SLIP_ESC: number = 0xdb
SLIP_ESC_END: number = 0xdc
SLIP_ESC_ESC: number = 0xdd
_DTR_state: boolean = false
baudrate: number = 0
buffer: Uint8Array = ...
device: SerialPort
lastTraceTime: number = ...
reader: undefined | ReadableStreamDefaultReader<Uint8Array>
slipReaderEnabled: boolean = false
traceLog: string = ""
tracing: boolean = false

Methods

  • Append a buffer array after another buffer array

    Parameters

    • arr1: Uint8Array

      First array buffer.

    • arr2: Uint8Array

      magic hex number to select ROM.

    Returns Uint8Array

    Return a 8 bit unsigned array.

  • Connect to serial device using the Webserial open method.

    Parameters

    • baud: number = 115200

      Number baud rate for serial connection. Default is 115200.

    • serialOptions: SerialOptions = {}

      Serial Options for WebUSB SerialPort class.

    Returns Promise<void>

  • Detect if the data read from device is a Fatal or Guru meditation error.

    Parameters

    • input: Uint8Array

      Data read from device

    Returns void

  • Disconnect from serial device by running SerialPort.close() after streams unlock.

    Returns Promise<void>

  • Request the serial device vendor ID and Product ID as string.

    Returns string

    Return the device VendorID and ProductID from SerialPortInfo as formatted string.

  • Request the serial device product id from SerialPortInfo.

    Returns undefined | number

    Return the product ID.

  • Parameters

    • uint8Array: Uint8Array
    • autoSplit: boolean = true

    Returns string

  • Parameters

    • s: Uint8Array

    Returns string

  • Parameters

    • numBytes: number
    • timeout: number

    Returns Promise<Uint8Array>

  • Read from serial device without slip formatting.

    Returns AsyncGenerator<Uint8Array, any, unknown>

    Yields

    The next number in the Fibonacci sequence.

  • Take a data array and return the first well formed packet after replacing the escape sequence. Reads at least 8 bytes.

    Parameters

    • timeout: number

      Timeout read data.

    Returns AsyncGenerator<Uint8Array, any, unknown>

    Yields

    Formatted packet using SLIP escape sequences.

  • Parameters

    • timeout: number

    Returns AsyncGenerator<Uint8Array, any, unknown>

  • Parameters

    • ms: number

    Returns Promise<unknown>

  • Format data packet using the Serial Line Internet Protocol (SLIP).

    Parameters

    • data: Uint8Array

      Binary unsigned 8 bit array data to format.

    Returns Uint8Array

    Formatted unsigned 8 bit data array.

  • Format received or sent data for tracing output.

    Parameters

    • message: string

      Message to format as trace line.

    Returns void

  • Wait for a given timeout ms for serial device unlock.

    Parameters

    • timeout: number

      Timeout time in milliseconds (ms) to sleep

    Returns Promise<void>

  • Write binary data to device using the WebSerial device writable stream.

    Parameters

    • data: Uint8Array

      8 bit unsigned data array to write to device.

    Returns Promise<void>

Generated using TypeDoc