API reference

Types

Enums, option and result types of tauri-plugin-serialplugin-api, generated from guest-js/types.ts.

Everything tauri-plugin-serialplugin-api exports besides SerialPort, generated from guest-js/types.ts and guest-js/logger.ts. Only names re-exported by guest-js/index.ts are listed.

Constants

DEFAULT_SERIAL_TIMEOUT_MS

Default read/write timeout (ms) when opening a port on desktop.

export const DEFAULT_SERIAL_TIMEOUT_MS = 1000;

LogLevel

export const LogLevel = {
  None: 'None',
  Error: 'Error',
  Warn: 'Warn',
  Info: 'Info',
  Debug: 'Debug',
} as const;

export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];

Enums

DataBits

MemberValue
Five'Five'
Six'Six'
Seven'Seven'
Eight'Eight'

FlowControl

MemberValue
None'None'
Software'Software'
Hardware'Hardware'

Parity

MemberValue
None'None'
Odd'Odd'
Even'Even'

StopBits

MemberValue
One'One'
Two'Two'

ClearBuffer

MemberValue
Input'Input'
Output'Output'
All'All'

Interfaces

PortInfo

Port metadata; the port path is the key of the record it comes in.

PropertyTypeDescription
path?stringDeprecated. Never sent by the native side; use the record key.
manufacturer'Unknown' | string
pid'Unknown' | string
product'Unknown' | string
serial_number'Unknown' | string
type'PCI' | string
vid'Unknown' | string

BlePortInfo

A SerialPort.scanBlePorts() result; the ble://… path is the record key.

PropertyTypeDescription
rssistringSignal strength in dBm as a decimal string; empty when the platform did not report it.

Capabilities

PropertyTypeDescription
transport'desktop' | 'mobile'
platformstring
versionstring

WatchOptions

PropertyTypeDescription
timeout?numberBatch coalescing window (ms). Default ~20 ms; not the port's read timeout.
size?numberMax bytes per read chunk; a batch is also flushed once this many bytes are buffered.
serialDataFlushIntervalMs?numberBatch flush interval (ms); takes precedence over timeout. All platforms.
decode?booleanDefault true — stream-decode with TextDecoder.
routeUrc?booleanWhen true, native hub line-routes idle RX so AT URC lines become onUrc events (and are removed from onData). Default: true if onUrc is provided, else false (raw byte stream — required for binary / NMEA). Ignored on CMUX channels (openMuxChannel()), as is size.
parser?ParserOptionsFrame RX natively (Node @serialport/parser-* semantics): each complete frame becomes exactly one onData call and the batch window (timeout, serialDataFlushIntervalMs) no longer applies. With decode (default) each frame is decoded on its own. An invalid config rejects watch() before the watch starts. With routeUrc / onUrc, URC lines are split off first and only the other lines reach the parser. On unwatch(), close() or a disconnect, the parser's buffered partial frame is delivered as a last onData call (before onDisconnect). Auto-reconnect restores the watch with the same parser.

WatchHandlers

PropertyTypeDescription
onData(data: string | Uint8Array) => void
onUrc?(line: string) => voidUnsolicited AT line (+CREG: etc.) when watch stays active during AT.
onDisconnect?(reason: string) => void
onError?(message: string) => void

WatchHandle

PropertyTypeDescription
channelIdnumber
unwatch(): Promise<void>

AvailablePortsOptions

PropertyTypeDescription
singlePortPerDevice?boolean

WatchPortsOptions

PropertyTypeDescription
singlePortPerDevice?booleanSame as available_ports({ singlePortPerDevice }). Default: false
pollIntervalMs?numberPoll interval (ms). Desktop default 2000; Android uses USB events + poll fallback.

WatchPortsHandlers

PropertyTypeDescription
onSnapshot?(ports: Record<string, PortInfo>) => void
onAdded?(path: string, info: PortInfo) => void
onRemoved?(path: string) => void

SerialportOptions

PropertyTypeDescription
dtr?booleanDTR level on open. false keeps Arduino-style boards from resetting when the port opens (Linux still pulses DTR briefly). Default: platform default (desktop: unchanged, Android: asserted).
rts?booleanRTS level on open. Default: platform default (desktop: unchanged, Android: asserted).
pathstring
baudRatenumber
encoding?string
dataBits?DataBits
flowControl?FlowControl
parity?Parity
stopBits?StopBits
timeout?number
size?number
serialDataFlushIntervalMs?number
atSession?AtSessionOptionsDefault AT session options applied on open() via native configureAtSession.

Options

PropertyTypeDescription
dtr?booleanDTR level on open. false keeps Arduino-style boards from resetting when the port opens (Linux still pulses DTR briefly). Default: platform default (desktop: unchanged, Android: asserted).
rts?booleanRTS level on open. Default: platform default (desktop: unchanged, Android: asserted).
path?string
baudRate?number
dataBitsDataBits
flowControlFlowControl
parityParity
stopBitsStopBits
size?number
timeoutnumber
serialDataFlushIntervalMs?number

ReadOptions

PropertyTypeDescription
timeout?number
size?number

AutoReconnectOptions

PropertyTypeDescription
interval?number
maxAttempts?number | null
onReconnect?(success: boolean, attempt: number) => void

AutoReconnectInfo

PropertyTypeDescription
enabledboolean
intervalnumber
maxAttemptsnumber | null
currentAttemptsnumber
hasCallbackboolean

ExchangeOptions

Options passed to native exchange (write + read-until).

PropertyTypeDescription
timeoutMs?number
maxBytes?number
terminators?string[]
idleMs?number
rxPrepare?RxPrepareMode
drainIdleMs?number
drainMaxMs?number
completionMode?ExchangeCompletionMode
resultFormat?AtResultFormat
command?string
solicitedPrefixes?string[]

ExchangeResponse

Structured native exchange response.

PropertyTypeDescription
rawUint8Array
matchedExchangeMatch
linesstring[]
statusAtParseStatus
solicitedBodystring[]
urcLinesstring[]

AtSessionOptions

PropertyTypeDescription
defaultTimeoutMs?number
defaultTerminators?string[]
defaultIdleMs?number
defaultRxPrepare?RxPrepareMode
defaultSolicitedPrefixes?string[]
stopOnError?booleanStop processing queue on first error. Default: true
expectOk?booleanReject promise when native status is not ok. Default: false
appendCr?booleanAppend \r when command has no line ending. Default: true
resultFormat?AtResultFormatVerbose (ATV1) vs numeric (ATV0) result lines. Default: verbose

AtPhase

PropertyTypeDescription
writestring | Uint8Array
completionMode?ExchangeCompletionMode
resultFormat?AtResultFormat
timeoutMs?number
command?string
rxPrepare?RxPrepareMode

SendSmsPduOptions

PropertyTypeDescription
timeoutMs?number
resultFormat?AtResultFormat

AtCommandOptions

PropertyTypeDescription
timeoutMs?number
terminators?string[]
idleMs?number
rxPrepare?RxPrepareMode
completionMode?ExchangeCompletionMode
resultFormat?AtResultFormat
solicitedPrefixes?string[]
appendCr?boolean

AtCommandResult

PropertyTypeDescription
commandstring
responsestring
rawUint8Array
statusAtParseStatus
linesstring[]
solicitedBodystring[]
urcLinesstring[]
matchedExchangeMatch
timedOutboolean

Type aliases

SerialEvent

export type SerialEvent =
  | { kind: 'data'; path: string; data: number[]; size: number }
  | { kind: 'urc'; path: string; line: string }
  | { kind: 'disconnect'; path: string; reason: string }
  | { kind: 'error'; path: string; message: string };

ByteSeq

Bytes as a UTF-8 string, a byte array or a Uint8Array.

export type ByteSeq = string | number[] | Uint8Array;

ParserOptions

Native parser selection for watch({ parser }). maxBufferSize (default 65536) caps bytes buffered without a complete frame; see each variant for what happens at the cap. Unknown keys make watch fail (a typo would otherwise fall back to a default).

export type ParserOptions =
  /** Split on a byte sequence (`@serialport/parser-delimiter`). Full buffer is emitted as a frame. */
  | { type: 'delimiter'; delimiter: ByteSeq; includeDelimiter?: boolean; maxBufferSize?: number }
  /** Split on `delimiter`, default `"\n"` (`@serialport/parser-readline`). */
  | {
      type: 'readline';
      delimiter?: ByteSeq;
      includeDelimiter?: boolean;
      maxBufferSize?: number;
      /** Node's string-rendering option: accepted and ignored (frames are decoded by `watch`). */
      encoding?: string;
    }
  /** Fixed-size frames of `length` bytes (`@serialport/parser-byte-length`). */
  | { type: 'byteLength'; length: number }
  /**
   * A frame ends after `intervalMs` (alias `interval`) of silence (`@serialport/parser-inter-byte-timeout`).
   * Give exactly one of `intervalMs` / `interval`.
   */
  | { type: 'interByteTimeout'; intervalMs: number; interval?: never; maxBufferSize?: number }
  | { type: 'interByteTimeout'; interval: number; intervalMs?: never; maxBufferSize?: number }
  /**
   * Delimiter + little-endian length field (`@serialport/parser-packet-length`).
   * Defaults: delimiter 0xaa, delimiterBytes 1, packetOverhead 2, lengthBytes 1,
   * lengthOffset 1, maxLen 0xff, maxBufferSize 65536 (a packet that cannot complete
   * within it is emitted as a frame).
   */
  | {
      type: 'packetLength';
      delimiter?: number | number[];
      delimiterBytes?: number;
      packetOverhead?: number;
      lengthBytes?: number;
      lengthOffset?: number;
      maxLen?: number;
      maxBufferSize?: number;
    }
  /** Drop everything until `delimiter`, then pass data through (`@serialport/parser-ready`). */
  | { type: 'ready'; delimiter: ByteSeq }
  /** Split UTF-8 text on a regular expression (Rust `regex-lite` syntax, not a JS `RegExp`). */
  | {
      type: 'regex';
      regex: string;
      maxBufferSize?: number;
      /** Node's string-rendering option: accepted and ignored. */
      encoding?: string;
    }
  /** Frames between a start and an end marker (`@serialport/parser-start-end`). */
  | {
      type: 'startEnd';
      startDelimiter: ByteSeq;
      endDelimiter: ByteSeq;
      includeStartDelimiter?: boolean;
      includeEndDelimiter?: boolean;
      maxBufferSize?: number;
    }
  /** SLIP (RFC 1055) decoder (`@serialport/parser-slip-encoder` `SlipDecoder`); bytes default to RFC values. */
  | {
      type: 'slip';
      start?: number;
      esc?: number;
      end?: number;
      escStart?: number;
      escEnd?: number;
      escEsc?: number;
    }
  /** ccTalk frames, length in byte 1 (`@serialport/parser-cctalk`). A partial frame is dropped after `maxDelayMs` (default 50, 0 = never). */
  | { type: 'ccTalk'; maxDelayMs?: number };

PortListEvent

export type PortListEvent =
  | { kind: 'snapshot'; ports: Record<string, PortInfo> }
  | { kind: 'added'; path: string; info: PortInfo }
  | { kind: 'removed'; path: string };

BaudRate

export type BaudRate =
  | 110
  | 300
  | 600
  | 1200
  | 2400
  | 4800
  | 9600
  | 14400
  | 19200
  | 38400
  | 57600
  | 115200
  | 230400
  | 460800
  | 921600;

RxPrepareMode

export type RxPrepareMode = 'drain' | 'purge' | 'none';

AtResultFormat

export type AtResultFormat = 'verbose' | 'numeric';

ExchangeCompletionMode

export type ExchangeCompletionMode = 'atFinalLine' | 'atIntermediate' | 'substring';

AtParseStatus

export type AtParseStatus = 'ok' | 'error' | 'cme' | 'cms' | 'unknown';

ExchangeMatch

export type ExchangeMatch =
  | 'ok'
  | 'error'
  | 'idle'
  | 'noCarrier'
  | 'busy'
  | 'noAnswer'
  | 'noDialtone'
  | 'sendOk'
  | 'sendFail'
  /**
   * Verbose texts (`AT+CMEE=2`) are mapped to their numeric `code` (`"SIM busy"` → 14);
   * `code` is `null` only for text the parser does not know.
   */
  | { cmeError: { code?: number | null } }
  /** Same shape as `cmeError`, for `+CMS ERROR`. */
  | { cmsError: { code?: number | null } }
  | { intermediate: { line: string } }
  | { substring: { term: string } };