Readonlybytes$Get an Observable that emits received byte chunks.
This stream is driven by an internal read pump and becomes active after connect.
ReadonlyconnectedCheck if the port is currently open and connected.
Readonlyconnected$Reactive connection state stream.
Emits true when connected and false when disconnected.
ReadonlycurrentGet the current SerialPort instance.
Returns the currently connected SerialPort instance, or null if no port is open.
This allows direct access to the underlying Web Serial API SerialPort object if needed.
Readonlyerrors$Reactive error stream.
Emits all SerialError instances produced by this client.
Readonlylines$Get an Observable that emits newline-delimited text lines.
Lines are emitted without trailing newline characters.
Readonlystate$Reactive serial state stream.
Emits detailed connection lifecycle and error states.
Readonlytext$Get an Observable that emits decoded text chunks.
This stream decodes bytes with TextDecoder in streaming mode.
Execute a command and collect output until prompt.
Command text to send
Optionaloptions: SerialCommandOptionsPrompt matching and timeout options
An Observable that emits captured stdout
Connect to a serial port.
Opens the specified port (or requests one if not provided) and configures it with the options passed to createSerialClient. The port must be connected before reading or writing data.
Optionalport: SerialPortOptional SerialPort to connect to. If not provided, will call requestPort to prompt the user.
An Observable that completes when the port is successfully opened
SerialError with code SerialErrorCode.PORT_ALREADY_OPEN if a port is already open
SerialError with code SerialErrorCode.PORT_OPEN_FAILED if opening the port fails
SerialError with code SerialErrorCode.OPERATION_CANCELLED if the user cancels port selection
SerialError with code SerialErrorCode.BROWSER_NOT_SUPPORTED if the browser doesn't support Web Serial API
// Connect by requesting a port
client.connect().subscribe({
next: () => console.log('Connected!'),
error: (error) => console.error('Connection failed:', error),
});
// Connect to a specific port
client.getPorts().subscribe({
next: (ports) => {
if (ports.length > 0) {
client.connect(ports[0]).subscribe();
}
},
});
Disconnect from the serial port.
Closes the currently open port and stops all active read/write streams. This method is safe to call even if no port is currently open.
An Observable that completes when the port is successfully closed
SerialError with code SerialErrorCode.CONNECTION_LOST if closing the port fails
Get available serial ports that have been previously granted access.
This method returns an Observable that emits an array of SerialPort instances that the user has previously granted access to in this browser session.
An Observable that emits an array of available SerialPort instances
SerialError with code SerialErrorCode.PORT_NOT_AVAILABLE if getting ports fails
SerialError with code SerialErrorCode.BROWSER_NOT_SUPPORTED if the browser doesn't support Web Serial API
Request a serial port from the user.
This method opens the browser's port selection dialog and returns an Observable that emits the selected SerialPort when the user chooses a port.
An Observable that emits the selected SerialPort when the user selects a port
SerialError with code SerialErrorCode.OPERATION_CANCELLED if the user cancels the selection
SerialError with code SerialErrorCode.PORT_NOT_AVAILABLE if the port request fails
SerialError with code SerialErrorCode.BROWSER_NOT_SUPPORTED if the browser doesn't support Web Serial API
Enqueue serial data for ordered writes.
This API serializes all send operations internally so that concurrent calls are written to the port one-by-one in call order.
Text or bytes to write to the serial port
An Observable that completes when the enqueued payload is written
SerialError with code SerialErrorCode.PORT_NOT_OPEN if the port is not open
SerialError with code SerialErrorCode.WRITE_FAILED if writing fails
Get the browser support information for Web Serial API.
This method never throws. Use it to branch UI behavior before calling connect.
Browser support information
Execute a protocol transaction with custom response collector.
Transaction request options
An Observable that emits collected value
Write a single chunk of data to the serial port.
Writes a single Uint8Array chunk to the serial port immediately. For queued ordering semantics, prefer send$.
Uint8Array data to write to the serial port
An Observable that completes when the data has been written
SerialError with code SerialErrorCode.PORT_NOT_OPEN if the port is not open
SerialError with code SerialErrorCode.WRITE_FAILED if writing fails
Write text data to the serial port.
This is a convenience API on top of send$.
Text data to write to the serial port
An Observable that completes when the data has been written
SerialError with code SerialErrorCode.PORT_NOT_OPEN if the port is not open
SerialError with code SerialErrorCode.WRITE_FAILED if writing fails
SerialClient interface for interacting with serial ports using RxJS Observables.
This interface provides a reactive API for serial port communication, allowing you to connect to serial devices, read and write data using RxJS Observables.
Example