/** * A fluent request/response client over a {@link SerialPort} — the host-side * driver every serial test otherwise hand-rolls (reader + writer, a pending * byte buffer, framed reads with timeouts). Works on ANY SerialPort: the * in-memory {@link InMemorySerialTransport}, a real USB device, or a * WebSocket-backed one — so the same test runs in Jest and on a device. * * @example * const {client} = await mountDeviceFixture(new MyDevice()); * await client.open({baudRate: 115200}); * await client.write('PING\n'); * expect(await client.readLine()).toBe('PONG'); * await client.close(); */ import type { SerialOptions, SerialPort } from '../WebSerial'; export type ReadOptions = { /** Per-call timeout in ms (overrides the client default). */ timeout?: number; }; export type SerialClientOptions = { /** Default per-read timeout in ms. Default 2000. */ defaultTimeoutMs?: number; }; export declare class SerialClient { #private; constructor(port: SerialPort, options?: SerialClientOptions); get port(): SerialPort; get isOpen(): boolean; /** True once the underlying stream has ended (device closed or lost). */ get ended(): boolean; /** Open the port (idempotent) and acquire reader + writer; start reading. */ open(options?: SerialOptions): Promise; /** Write bytes (string → char codes & 0xff). */ write(data: number[] | Uint8Array | string): Promise; /** Read exactly `n` bytes (fewer only if the stream ends first). */ readBytes(n: number, options?: ReadOptions): Promise; /** Read up to and including `delimiter`; returns the slice (incl. delimiter). */ readUntil(delimiter: number[] | Uint8Array | string, options?: ReadOptions): Promise; /** Read one `\n`-terminated line as text (trailing CR/LF stripped). */ readLine(options?: ReadOptions): Promise; /** * Frame a message: `predicate(buffer)` returns the number of leading bytes the * next frame occupies (consumed and returned), or `false` to wait for more. */ readMatching(predicate: (buffer: Uint8Array) => number | false, options?: ReadOptions): Promise; /** * Resolve with the next chunk of buffered inbound bytes (one or more), or an * empty array once the stream has ended. Rejects on timeout. Use this to layer * your own framing/decoder (SLIP, COBS, length-prefix, …) on the byte stream; * pair it with {@link ended} to stop when the device goes away. */ readAvailable(options?: ReadOptions): Promise; /** Assert no inbound bytes arrive for `ms`. Rejects if any do. */ expectIdle(ms: number): Promise; /** Drop any buffered-but-unread inbound bytes. */ drain(): void; /** Release reader + writer locks and close the port. Safe to call twice. */ close(): Promise; } /** Create a {@link SerialClient} for any SerialPort (virtual, real, or WS). */ export declare function createSerialClient(port: SerialPort, options?: SerialClientOptions): SerialClient; //# sourceMappingURL=serial-client.d.ts.map