Class Transport

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

Param: device

Requested device prompted by the browser.

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

Constructors

  • Parameters

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

    Returns Transport

Properties

_DTR_state: boolean = false
baudrate: number = 0
device: SerialPort
lastTraceTime: number = ...
leftOver: Uint8Array = ...
reader: undefined | ReadableStreamDefaultReader<Uint8Array>
slipReaderEnabled: boolean = false
traceLog: string = ""
tracing: boolean = false

Methods

  • Concatenate buffer2 to buffer1 and return the resulting ArrayBuffer.

    Parameters

    • buffer1: ArrayBuffer

      First buffer to concatenate.

    • buffer2: ArrayBuffer

      Second buffer to concatenate.

    Returns ArrayBufferLike

    Result Array buffer.

  • Connect to serial device using the Webserial open method.

    Parameters

    • baud: number = 115200

      Number baud rate for serial connection.

    • serialOptions: SerialOptions = {}

      Serial Options for WebUSB SerialPort class.

    Returns Promise<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

  • Read from serial device without slip formatting.

    Parameters

    • timeout: number = 0

      Read timeout in milliseconds (ms)

    Returns Promise<undefined | Uint8Array>

    8 bit unsigned data array read from device.

  • Read from serial device using the device ReadableStream.

    Parameters

    • timeout: number = 0

      Read timeout number

    • minData: number = 12

      Minimum packet array length

    Returns Promise<Uint8Array>

    8 bit unsigned data array read from device.

  • Parameters

    • ms: number

    Returns Promise<unknown>

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

    Parameters

    • data: Uint8Array

      Unsigned 8 bit array from the device read stream.

    Returns Uint8Array

    Formatted packet using SLIP escape sequences.

  • 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>