Communication pattern Recipes
This index maps serial communication goals to existing Guide pages and recipes. Prefer this page when you know the pattern you need (line protocol, command/reply, timeout, and so on). For framework-specific wiring, use the Examples instead.
Parent: #555 · Issue: #558
Scope
Item
Decision
Axis
Communication patterns , not device brands
Device names
Do not treat product names as a compatibility guarantee
New long pages
Prefer links to existing Guide / Recipe pages
Binary receive
Not supported — see #545 and Supported data
Catalog
Pattern
Primary APIs
Details
Basic text send / receive
connect$, lines$, send$, disconnect$ / dispose$
Quick Start
Line-oriented protocol
lines$, optionally receive$
Advanced Usage – Line framing · Stream selection
Terminal / carriage-return handling
terminalText$, receive$
Stream selection · Advanced Usage
Command / Response
lines$ / receive$, send$
Request / Response
Timeout
RxJS timeout on connect$ / waits
Timeout / cancel / retry – Connect timeout
Cancellation
takeUntil, unsubscribe, teardown
Timeout / cancel / retry – Cancel
Reconnect policy
state$, connect$, new session after dispose$
Timeout / cancel / retry – disposed · Advanced Usage – Reconnect
Fake SerialSession testing
Fake implementing SerialSession
Hardware-free testing
Binary send with Uint8Array
send$(Uint8Array)
Supported data
Basic text send / receive
APIs
createSerialSession, connect$, lines$, send$, disconnect$ / dispose$, state$, errors$
Good for
First connect, log-style line receive, simple string send
Not for
Custom framing, command/reply correlation, binary wire protocols
Details
Quick Start · choose streams in Stream selection
Line-oriented protocol
APIs
lines$ (default); receive$ + RxJS when built-in framing is not enough
Good for
Newline-delimited logs, JSON Lines, one-line status replies
Not for
Prompts without a newline, \r redraw terminals (prefer receive$ / terminalText$)
Details
Advanced Usage – Line framing · Stream selection
Terminal / carriage-return handling
APIs
terminalText$, receive$ (and SerialSessionOptions.terminalBuffer)
Good for
Binding a terminal-like viewport; folding \r redraws; optional ANSI strip
Not for
Strict line parsers (use lines$); expecting wire Uint8Array receive
Details
Stream selection · Advanced Usage · createTerminalBuffer
Command / Response
APIs
lines$ or receive$, send$ (compose wait-then-send; no core request$)
Good for
Send a command, wait for a matching line / prompt, serialize with concatMap
Not for
Fire-and-forget logs only; assuming past emissions replay on late subscribe
Details
Request / Response recipes
Timeout
APIs
RxJS timeout around connect$ or response waits (app policy, not a core lease)
Good for
Bounding port picker / connect waits and reply waits
Not for
Treating every timeout as “safe to resend” non-idempotent commands
Details
Connect timeout · Response-wait timeout
Cancellation
APIs
takeUntil, unsubscribe, component / hook teardown
Good for
Stopping work when the UI tears down; distinguishing user cancel from device failure
Not for
Auto-reopening the port picker after OPERATION_CANCELLED
Details
Cancel with takeUntil · Cancel on teardown
Reconnect policy
Fake SerialSession testing
APIs
A Fake that matches the swappable SerialSession contract (not published on npm)
Good for
Unit / integration tests without USB hardware; injecting failures in CI
Not for
Replacing the real Web Serial stack in production
Details
Hardware-free testing · Swappable public contract
Binary send with Uint8Array
APIs
send$(Uint8Array) — bytes written as-is
Good for
Sending opaque binary payloads the peer already understands
Not for
Binary receive (no receiveBytes$ / Uint8Array receive stream); Modbus RTU / COBS / SLIP as a library feature
Details
Supported data · design notes #545
Short example (send only; receive remains UTF-8 text):
import { firstValueFrom } from 'rxjs' ; import { createSerialSession } from '@gurezo/web-serial-rxjs' ; const session = createSerialSession ({ baudRate: 115200 }); await firstValueFrom ( session . connect$ ()); const payload = new Uint8Array ([ 0x01 , 0x02 , 0x03 ]); await firstValueFrom ( session . send$ ( payload ));
Copy