API reference

SerialPort

Every public member of the SerialPort class, generated from guest-js/serial-port.ts.

The SerialPort class exported by tauri-plugin-serialplugin-api. Signatures and descriptions come straight from guest-js/serial-port.ts; for how the pieces fit together see the JavaScript API guide. Option and result types are on the types page.

MethodDescription
SerialPort.getCapabilities(): Promise<Capabilities>Native build info (transport, platform, plugin version); cached after the first call.
SerialPort.available_ports(options?: AvailablePortsOptions): Promise<Record<string, PortInfo>>List serial ports, keyed by path. singlePortPerDevice keeps one path per USB device.
SerialPort.watchAvailablePorts(handlers: WatchPortsHandlers, options?: WatchPortsOptions): Promise<WatchHandle>Subscribe to available-port hotplug (attach/detach). Sends an initial snapshot, then added / removed events. Call unwatch() on the returned handle to stop.
SerialPort.scanBlePorts(options?: { timeoutMs?: number }): Promise<Record<string, BlePortInfo>>Scan for Bluetooth LE devices that advertise the Nordic UART Service (desktop, iOS and Android; the Rust side needs the plugin's ble feature). Keys are ble://<id> paths that new SerialPort({ path }) can open.
SerialPort.managed_ports(): Promise<string[]>Paths of the ports this plugin currently holds open.
SerialPort.forceClose(path: string): Promise<void>Close a port by path without a SerialPort instance (stops its watch too).
SerialPort.closeAll(): Promise<void>Close every port this plugin holds open.
SerialPort.setLogLevel(level: LogLevel): Promise<void>Set the native and JS log level.
SerialPort.getLogLevel(): Promise<LogLevel>Current native log level (also applied to the JS logger).
watch(handlers: WatchHandlers, options?: WatchOptions): Promise<WatchHandle>Stream received data through a native channel; one watch per port instance. Without parser, bytes are batched (~20 ms window or size bytes per event); with parser, each complete frame is one onData call. onUrc turns on URC routing. Auto-reconnect re-creates the watch with the same handlers and options.
change(options: { path?: string; baudRate?: number }): Promise<void>Switch path and/or baud rate: closes, reopens and restores an active watch.
close(): Promise<void>Stop the watch and auto-reconnect, cancel a pending read and close the port.
enableAutoReconnect(options: AutoReconnectOptions = {}): voidReopen (and re-watch) after a disconnect every interval ms (default 5000), up to maxAttempts (default 10, null = unlimited).
disableAutoReconnect(): voidStop auto-reconnect and forget the saved watch session.
getAutoReconnectInfo(): AutoReconnectInfoCurrent auto-reconnect settings and attempt count.
manualReconnect(): Promise<boolean>Reopen now and restore the saved watch; resolves false instead of throwing on failure.
open(): Promise<string>Open the port with the constructor settings. Resolves to the canonical path (e.g. a tcp:// or ble:// path as the native side names it).
read(options?: ReadOptions): Promise<string>Read up to size bytes within timeout ms and decode them with encoding (a split multi-byte character is kept for the next read). Not allowed while a watch is active.
readBinary(options?: ReadOptions): Promise<Uint8Array>Read raw bytes: waits up to timeout ms to fill size bytes, resolves with what arrived, rejects if nothing did. Not allowed while a watch is active.
setBaudRate(value: number | BaudRate): Promise<void>Change the baud rate of the open port (kept for reopen).
setDataBits(value: DataBits): Promise<void>Change the data bits of the open port (kept for reopen).
setFlowControl(value: FlowControl): Promise<void>Change flow control of the open port (kept for reopen).
setParity(value: Parity): Promise<void>Change parity of the open port (kept for reopen).
setStopBits(value: StopBits): Promise<void>Change stop bits of the open port (kept for reopen).
setTimeout(value: number): Promise<void>Change the port read/write timeout in ms (kept for reopen).
writeRequestToSend(level: boolean): Promise<void>Set the RTS line.
writeDataTerminalReady(level: boolean): Promise<void>Set the DTR line.
readClearToSend(): Promise<boolean>Read the CTS line.
readDataSetReady(): Promise<boolean>Read the DSR line.
readRingIndicator(): Promise<boolean>Read the RI line.
readCarrierDetect(): Promise<boolean>Read the CD line.
bytesToRead(): Promise<number>Bytes waiting in the input buffer.
bytesToWrite(): Promise<number>Bytes still waiting in the output buffer.
clearBuffer(buffer: ClearBuffer): Promise<void>Discard the input, output or both buffers.
exchange(value: string, options?: ExchangeOptions): Promise<ExchangeResponse>Write and read until terminators, idle silence, or timeout (native exchange).
exchangeBinary(value: Uint8Array, options?: ExchangeOptions): Promise<ExchangeResponse>Binary write + read-until (e.g. CMGS PDU + Ctrl+Z).
enableMux(options?: { command?: string; timeoutMs?: number; }): Promise<void>Enter GSM 07.10 CMUX mode on this physical port.
openMuxChannel(dlci: number): Promise<SerialPort>Open a virtual AT/data channel after CMUX is enabled. Returns a new SerialPort.
disableMux(): Promise<void>Tear down CMUX and close all virtual channels on this physical port.
cancelExchange(): Promise<void>Cancel an in-flight exchange / AT job on this port.
cancelAt(): Promise<void>Alias for cancelExchange — cancels native AT transaction queue.
configureAtSession(session: AtSessionOptions): Promise<void>Configure AT session defaults (native queue). Call after open if not using constructor atSession.
sendAt(command: string, options?: AtCommandOptions): Promise<AtCommandResult>Send one AT command through the native FIFO queue.
sendAtPhases(phases: AtPhase[]): Promise<AtCommandResult[]>Multi-phase AT flow (e.g. CMGS) as one atomic native queue job.
sendSmsPdu(length: number, pdu: Uint8Array, options?: SendSmsPduOptions): Promise<AtCommandResult[]>Built-in CMGS recipe: AT+CMGS=n → > → PDU + Ctrl+Z.
setBreak(): Promise<void>Start a break condition on TX.
clearBreak(): Promise<void>End the break condition.
write(value: string): Promise<number>Write a string (UTF-8). Resolves to the number of bytes written.
writeBinary(value: Uint8Array | number[]): Promise<number>Write raw bytes. Resolves to the number of bytes written.

Constructor

new SerialPort()

constructor(options: SerialportOptions)

Describe a port; nothing is opened until open().

Properties

isOpen

isOpen: boolean

encoding

encoding: string

options

options: Options

size

get size(): number

Default read chunk size in bytes (size option, 1024 if unset).

activeWatch

get activeWatch(): WatchHandle | null

Active watch handle, if any.

Static methods

SerialPort.getCapabilities()

static async getCapabilities(): Promise<Capabilities>

Native build info (transport, platform, plugin version); cached after the first call.

SerialPort.available_ports()

static async available_ports(options?: AvailablePortsOptions): Promise<Record<string, PortInfo>>

List serial ports, keyed by path. singlePortPerDevice keeps one path per USB device.

SerialPort.watchAvailablePorts()

static async watchAvailablePorts(handlers: WatchPortsHandlers, options?: WatchPortsOptions): Promise<WatchHandle>

Subscribe to available-port hotplug (attach/detach). Sends an initial snapshot, then added / removed events. Call unwatch() on the returned handle to stop.

SerialPort.scanBlePorts()

static async scanBlePorts(options?: { timeoutMs?: number }): Promise<Record<string, BlePortInfo>>

Scan for Bluetooth LE devices that advertise the Nordic UART Service (desktop, iOS and Android; the Rust side needs the plugin's ble feature). Keys are ble://<id> paths that new SerialPort({ path }) can open.

SerialPort.managed_ports()

static async managed_ports(): Promise<string[]>

Paths of the ports this plugin currently holds open.

SerialPort.forceClose()

static async forceClose(path: string): Promise<void>

Close a port by path without a SerialPort instance (stops its watch too).

SerialPort.closeAll()

static async closeAll(): Promise<void>

Close every port this plugin holds open.

SerialPort.setLogLevel()

static async setLogLevel(level: LogLevel): Promise<void>

Set the native and JS log level.

SerialPort.getLogLevel()

static async getLogLevel(): Promise<LogLevel>

Current native log level (also applied to the JS logger).

Instance methods

watch()

async watch(handlers: WatchHandlers, options?: WatchOptions): Promise<WatchHandle>

Stream received data through a native channel; one watch per port instance. Without parser, bytes are batched (~20 ms window or size bytes per event); with parser, each complete frame is one onData call. onUrc turns on URC routing. Auto-reconnect re-creates the watch with the same handlers and options.

change()

async change(options: { path?: string; baudRate?: number }): Promise<void>

Switch path and/or baud rate: closes, reopens and restores an active watch.

close()

async close(): Promise<void>

Stop the watch and auto-reconnect, cancel a pending read and close the port.

enableAutoReconnect()

enableAutoReconnect(options: AutoReconnectOptions = {}): void

Reopen (and re-watch) after a disconnect every interval ms (default 5000), up to maxAttempts (default 10, null = unlimited).

disableAutoReconnect()

disableAutoReconnect(): void

Stop auto-reconnect and forget the saved watch session.

getAutoReconnectInfo()

getAutoReconnectInfo(): AutoReconnectInfo

Current auto-reconnect settings and attempt count.

manualReconnect()

async manualReconnect(): Promise<boolean>

Reopen now and restore the saved watch; resolves false instead of throwing on failure.

open()

async open(): Promise<string>

Open the port with the constructor settings. Resolves to the canonical path (e.g. a tcp:// or ble:// path as the native side names it).

read()

async read(options?: ReadOptions): Promise<string>

Read up to size bytes within timeout ms and decode them with encoding (a split multi-byte character is kept for the next read). Not allowed while a watch is active.

readBinary()

async readBinary(options?: ReadOptions): Promise<Uint8Array>

Read raw bytes: waits up to timeout ms to fill size bytes, resolves with what arrived, rejects if nothing did. Not allowed while a watch is active.

setBaudRate()

async setBaudRate(value: number | BaudRate): Promise<void>

Change the baud rate of the open port (kept for reopen).

setDataBits()

async setDataBits(value: DataBits): Promise<void>

Change the data bits of the open port (kept for reopen).

setFlowControl()

async setFlowControl(value: FlowControl): Promise<void>

Change flow control of the open port (kept for reopen).

setParity()

async setParity(value: Parity): Promise<void>

Change parity of the open port (kept for reopen).

setStopBits()

async setStopBits(value: StopBits): Promise<void>

Change stop bits of the open port (kept for reopen).

setTimeout()

async setTimeout(value: number): Promise<void>

Change the port read/write timeout in ms (kept for reopen).

writeRequestToSend()

async writeRequestToSend(level: boolean): Promise<void>

Set the RTS line.

writeDataTerminalReady()

async writeDataTerminalReady(level: boolean): Promise<void>

Set the DTR line.

readClearToSend()

async readClearToSend(): Promise<boolean>

Read the CTS line.

readDataSetReady()

async readDataSetReady(): Promise<boolean>

Read the DSR line.

readRingIndicator()

async readRingIndicator(): Promise<boolean>

Read the RI line.

readCarrierDetect()

async readCarrierDetect(): Promise<boolean>

Read the CD line.

bytesToRead()

async bytesToRead(): Promise<number>

Bytes waiting in the input buffer.

bytesToWrite()

async bytesToWrite(): Promise<number>

Bytes still waiting in the output buffer.

clearBuffer()

async clearBuffer(buffer: ClearBuffer): Promise<void>

Discard the input, output or both buffers.

exchange()

async exchange(value: string, options?: ExchangeOptions): Promise<ExchangeResponse>

Write and read until terminators, idle silence, or timeout (native exchange).

exchangeBinary()

async exchangeBinary(value: Uint8Array, options?: ExchangeOptions): Promise<ExchangeResponse>

Binary write + read-until (e.g. CMGS PDU + Ctrl+Z).

enableMux()

async enableMux(options?: { command?: string; timeoutMs?: number; }): Promise<void>

Enter GSM 07.10 CMUX mode on this physical port.

openMuxChannel()

async openMuxChannel(dlci: number): Promise<SerialPort>

Open a virtual AT/data channel after CMUX is enabled. Returns a new SerialPort.

disableMux()

async disableMux(): Promise<void>

Tear down CMUX and close all virtual channels on this physical port.

cancelExchange()

async cancelExchange(): Promise<void>

Cancel an in-flight exchange / AT job on this port.

cancelAt()

async cancelAt(): Promise<void>

Alias for cancelExchange — cancels native AT transaction queue.

configureAtSession()

async configureAtSession(session: AtSessionOptions): Promise<void>

Configure AT session defaults (native queue). Call after open if not using constructor atSession.

sendAt()

async sendAt(command: string, options?: AtCommandOptions): Promise<AtCommandResult>

Send one AT command through the native FIFO queue.

sendAtPhases()

async sendAtPhases(phases: AtPhase[]): Promise<AtCommandResult[]>

Multi-phase AT flow (e.g. CMGS) as one atomic native queue job.

sendSmsPdu()

async sendSmsPdu(length: number, pdu: Uint8Array, options?: SendSmsPduOptions): Promise<AtCommandResult[]>

Built-in CMGS recipe: AT+CMGS=n → > → PDU + Ctrl+Z.

setBreak()

async setBreak(): Promise<void>

Start a break condition on TX.

clearBreak()

async clearBreak(): Promise<void>

End the break condition.

write()

async write(value: string): Promise<number>

Write a string (UTF-8). Resolves to the number of bytes written.

writeBinary()

async writeBinary(value: Uint8Array | number[]): Promise<number>

Write raw bytes. Resolves to the number of bytes written.