ReadonlyconnectedCheck if the port is currently open and connected.
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.
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
Get an Observable that emits data read from the serial port.
Returns an Observable stream that emits Uint8Array chunks as data is received from the serial port. The stream will continue until the port is disconnected or an error occurs.
An Observable that emits Uint8Array chunks containing data read from the serial port
SerialError with code SerialErrorCode.PORT_NOT_OPEN if the port is not open
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
Write a single chunk of data to the serial port.
Writes a single Uint8Array chunk to the serial port. For writing multiple chunks, consider using writeStream with an Observable instead.
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 data to the serial port from an Observable.
Writes data from an Observable stream to the serial port. The Observable should emit Uint8Array chunks that will be written sequentially to the port. If a previous write stream is active, it will be cancelled before starting the new one.
Observable that emits Uint8Array chunks to write to the serial port
An Observable that completes when all data has been written and the stream completes
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