import { Event, EventTarget } from './lib/event-target'; import { ReadableStreamImpl as ReadableStream, WritableStreamImpl as WritableStream } from './lib/web-streams'; import type { SerialTransport } from './transport'; /** * @see https://wicg.github.io/serial/#dom-paritytype * * none - No parity bit is sent for each data word. * even - Data word plus parity bit has even parity. * odd - Data word plus parity bit has odd parity. */ export type Parity = 'none' | 'even' | 'odd'; /** * @see https://wicg.github.io/serial/#dom-flowcontroltype * none - No flow control is enabled. * hardware - Hardware flow control using the RTS and CTS signals is enabled. */ type FlowControl = 'none' | 'hardware'; /** * @see https://wicg.github.io/serial/#dom-serialoptions */ export type SerialOptions = { /** * A positive, non-zero value indicating the baud rate at which serial * communication should be established. * * Note: baudRate is the only required member of this dictionary. While there * are common default for other connection parameters it is important for * developers to consider and consult with the documentation for devices they * intend to connect to determine the correct values. While some values are * common there is no standard baud rate. Requiring this parameter reduces the * potential for confusion if an arbitrary default were chosen by this * specification. */ baudRate: number; /** * The number of data bits per frame. Either 7 or 8. */ dataBits?: 7 | 8; /** * The number of stop bits at the end of a frame. Either 1 or 2. */ stopBits?: 1 | 2; /** * The parity mode. */ parity?: Parity; /** * A positive, non-zero value indicating the size of the read and write * buffers that should be created. */ bufferSize?: number; /** * The flow control mode. */ flowControl?: FlowControl; }; /** * @see https://wicg.github.io/serial/#dom-serialoutputsignals */ export type SerialOutputSignals = { /** * Data Terminal Ready (DTR) */ dataTerminalReady?: boolean; /** * Request To Send (RTS) */ requestToSend?: boolean; /** * Break */ break?: boolean; }; /** * @see https://wicg.github.io/serial/#dom-serialinputsignals */ export type SerialInputSignals = { /** * Data Carrier Detect (DCD) */ dataCarrierDetect: boolean; /** * Clear To Send (CTS) */ clearToSend: boolean; /** * Ring Indicator (RI) */ ringIndicator: boolean; /** * Data Set Ready (DSR) */ dataSetReady: boolean; }; /** * @see https://wicg.github.io/serial/#serialportinfo-dictionary */ export type SerialPortInfo = { /** USB Vendor ID */ usbVendorId: number; /** USB Product ID */ usbProductId: number; bluetoothServiceClassId?: never; } | { usbVendorId?: never; usbProductId?: never; /** Bluetooth service class ID */ bluetoothServiceClassId: number | string; }; /** * @see https://wicg.github.io/serial/#dom-serialportfilter */ export type SerialPortFilter = { /** USB Vendor ID */ usbVendorId?: number; /** USB Product ID */ usbProductId?: number; /** Bluetooth service class ID */ bluetoothServiceClassId?: number | string; }; /** * @see https://wicg.github.io/serial/#dom-serialportrequestoptions */ export type SerialPortRequestOptions = { /** * Filters for serial ports */ filters?: SerialPortFilter[]; /** * A list of BluetoothServiceUUID values representing Bluetooth service class * IDs. Bluetooth ports with custom service class IDs are excluded from the * list of ports presented to the user unless the service class ID is included * in this list. */ allowedBluetoothServiceClassIds?: (number | string)[]; }; /** * Methods on this interface typically complete asynchronously, queuing work on * the serial port task source. * * The get the parent algorithm for SerialPort returns the same Serial instance * that is returned by the SerialPort's relevant global object's Navigator * object's serial getter. * * Instances of SerialPort are created with the internal slots described in the * following table: * * @see https://wicg.github.io/serial/#serialport-interface */ export declare class SerialPort extends EventTarget { #private; constructor(usb: SerialTransport, deviceId: number, portNumber: number, usbVendorId: number, usbProductId: number); /** * @see https://wicg.github.io/serial/#dom-serialport-onconnect */ get onconnect(): ((event: Event) => void) | null; set onconnect(fn: ((event: Event) => void) | null); /** * @see https://wicg.github.io/serial/#dom-serialport-ondisconnect */ get ondisconnect(): ((event: Event) => void) | null; set ondisconnect(fn: ((event: Event) => void) | null); /** * @see https://wicg.github.io/serial/#dom-serialport-connected */ get connected(): boolean; /** * @see https://wicg.github.io/serial/#dom-serialport-readable */ get readable(): ReadableStream | null; /** * @see https://wicg.github.io/serial/#dom-serialport-writable */ get writable(): WritableStream | null; /** * @see https://wicg.github.io/serial/#dom-serialport-getinfo */ getInfo(): SerialPortInfo; /** * Before communicating on a serial port it must be opened. Opening the port * allows the site to specify the necessary parameters which control how data * is transmitted and received. Developers should check the documentation for * the device they are connecting to for the appropriate parameters. * * await port.open({ baudRate: 115200 }); * * Once open() has resolved the readable and writable attributes can be * accessed to get the ReadableStream and WritableStream instances for * receiving data from and sending data to the connected device. * @see https://wicg.github.io/serial/#dom-serialport-open */ open(options: SerialOptions): Promise; /** * @see https://wicg.github.io/serial/#dom-serialport-close */ close(): Promise; /** * @see https://wicg.github.io/serial/#dom-serialport-forget */ forget(): Promise; /** * @see https://wicg.github.io/serial/#dom-serialport-setsignals */ setSignals(signals?: SerialOutputSignals): Promise; /** * @see https://wicg.github.io/serial/#dom-serialport-getsignals */ getSignals(): Promise; } /** * @see https://wicg.github.io/serial/#serial-interface */ export declare class Serial extends EventTarget { #private; /** * @param transport Optional transport override. When provided, this `Serial` * talks to it instead of the global native module — the transport override used by tests * and the virtual serial device harness (`new Serial(new InMemorySerialTransport())`). * Omit it for the normal native-backed instance; the singleton `serial` * export is created this way and can still be redirected globally via * `setUsbSerial()`. */ constructor(transport?: SerialTransport); /** * Subscribing to "connect"/"disconnect" must wire up the native USB state * listeners, so a consumer can receive attach/detach/permission events * without first calling getPorts()/requestPort(). */ addEventListener(...args: Parameters): void; /** * @see https://wicg.github.io/serial/#dom-serial-onconnect */ get onconnect(): ((event: Event) => void) | null; set onconnect(fn: ((event: Event) => void) | null); /** * @see https://wicg.github.io/serial/#dom-serial-ondisconnect */ get ondisconnect(): ((event: Event) => void) | null; set ondisconnect(fn: ((event: Event) => void) | null); /** * @see https://wicg.github.io/serial/#dom-serial-getports */ getPorts(): Promise; /** * @see https://wicg.github.io/serial/#dom-serial-requestport */ requestPort(options?: SerialPortRequestOptions): Promise; } export declare const serial: Serial; export {}; //# sourceMappingURL=WebSerial.d.ts.map