web-serial-rxjs API Documentation
    Preparing search index...

    Variable SerialErrorCodeConst

    SerialErrorCode: {
        BROWSER_NOT_SUPPORTED: "BROWSER_NOT_SUPPORTED";
        CONNECTION_LOST: "CONNECTION_LOST";
        INVALID_CONNECTION_OPTIONS: "INVALID_CONNECTION_OPTIONS";
        INVALID_FILTER_OPTIONS: "INVALID_FILTER_OPTIONS";
        INVALID_LINE_BUFFER_OPTIONS: "INVALID_LINE_BUFFER_OPTIONS";
        INVALID_RECEIVE_REPLAY_OPTIONS: "INVALID_RECEIVE_REPLAY_OPTIONS";
        INVALID_TERMINAL_BUFFER_OPTIONS: "INVALID_TERMINAL_BUFFER_OPTIONS";
        LINE_BUFFER_OVERFLOW: "LINE_BUFFER_OVERFLOW";
        OPERATION_CANCELLED: "OPERATION_CANCELLED";
        OPERATION_TIMEOUT: "OPERATION_TIMEOUT";
        PORT_ALREADY_OPEN: "PORT_ALREADY_OPEN";
        PORT_NOT_AVAILABLE: "PORT_NOT_AVAILABLE";
        PORT_NOT_OPEN: "PORT_NOT_OPEN";
        PORT_OPEN_FAILED: "PORT_OPEN_FAILED";
        READ_FAILED: "READ_FAILED";
        RECEIVE_REPLAY_BUFFER_OVERFLOW: "RECEIVE_REPLAY_BUFFER_OVERFLOW";
        SESSION_DISPOSED: "SESSION_DISPOSED";
        UNKNOWN: "UNKNOWN";
        WRITE_FAILED: "WRITE_FAILED";
    } = ...

    Error codes for serial port operations.

    These codes identify specific error conditions that can occur when working with serial ports. Each error code corresponds to a specific failure scenario, making it easier to handle errors programmatically.

    Type Declaration

    • ReadonlyBROWSER_NOT_SUPPORTED: "BROWSER_NOT_SUPPORTED"

      Browser does not support the Web Serial API.

      Emitted on connect$ when navigator.serial is unavailable.

      Suggested action: Inform the user to use a supported browser.

    • ReadonlyCONNECTION_LOST: "CONNECTION_LOST"

      Serial port connection was lost.

      This error occurs when the connection to the serial port is unexpectedly terminated, such as when the device is disconnected or the port is closed by another process.

      Suggested action: Check the physical connection and reconnect if needed.

    • ReadonlyINVALID_CONNECTION_OPTIONS: "INVALID_CONNECTION_OPTIONS"

      Invalid connection options provided.

      This error occurs when connection fields such as baudRate are out of range at session creation time.

      Suggested action: Verify connection options match the documented ranges and value types.

    • ReadonlyINVALID_FILTER_OPTIONS: "INVALID_FILTER_OPTIONS"

      Invalid filter options provided.

      This error occurs when port filter options are invalid, such as when filter values are out of range or missing required fields.

      Suggested action: Verify filter options match the expected format and value ranges.

    • ReadonlyINVALID_LINE_BUFFER_OPTIONS: "INVALID_LINE_BUFFER_OPTIONS"

      Invalid line buffer options provided.

      This error occurs when SerialSessionOptions.lineBuffer values are out of range, such as a negative or non-integer maxChars.

      Suggested action: Verify lineBuffer options match the documented ranges and value types.

    • ReadonlyINVALID_RECEIVE_REPLAY_OPTIONS: "INVALID_RECEIVE_REPLAY_OPTIONS"

      Invalid receive replay options provided.

      This error occurs when SerialSessionOptions.receiveReplay values are out of range, such as a non-integer bufferSize or maxChars.

      Suggested action: Verify receiveReplay options match the documented ranges and value types.

    • ReadonlyINVALID_TERMINAL_BUFFER_OPTIONS: "INVALID_TERMINAL_BUFFER_OPTIONS"

      Invalid terminal buffer options provided.

      This error occurs when SerialSessionOptions.terminalBuffer values are out of range, such as a negative or non-integer maxLines or maxChars.

      Suggested action: Verify terminalBuffer options match the documented ranges and value types.

    • ReadonlyLINE_BUFFER_OVERFLOW: "LINE_BUFFER_OVERFLOW"

      Internal line buffer exceeded its configured size limit.

      This error occurs when the incomplete line tail held by the SerialSession.lines$ framing buffer grows beyond SerialSessionOptions.lineBuffer maxChars. Leading characters are discarded to bound memory; the session remains connected.

      Suggested action: Increase lineBuffer.maxChars, handle framing on receive$, or ensure the device sends line terminators.

    • ReadonlyOPERATION_CANCELLED: "OPERATION_CANCELLED"

      Operation was cancelled by the user.

      This error occurs when the user cancels a port selection dialog or aborts an operation before it completes.

      Suggested action: This is a normal condition - no action required, but you may want to inform the user that the operation was cancelled.

    • ReadonlyOPERATION_TIMEOUT: "OPERATION_TIMEOUT"

      Operation timed out before completion.

      Reserved — not emitted in v3.x. No timeout / prompt detection / transaction API exists yet. Scheduled for removal in the next major version unless a future API adopts this code.

      Not emitted at runtime in v3.x. Will be removed in the next major version.

    • ReadonlyPORT_ALREADY_OPEN: "PORT_ALREADY_OPEN"

      Serial port is already open.

      Emitted on connect$ when the session is not in 'idle' or 'error' (non-fatal; session state is unchanged).

      Suggested action: Disconnect the current port before connecting a new one.

    • ReadonlyPORT_NOT_AVAILABLE: "PORT_NOT_AVAILABLE"

      Serial port is not available.

      Reserved — not emitted in v3.x. The current implementation uses only navigator.serial.requestPort; there is no getPorts API path. Scheduled for removal in the next major version.

      Suggested action: Handle port acquisition failures with SerialErrorCode.PORT_OPEN_FAILED or SerialErrorCode.OPERATION_CANCELLED instead.

      Not emitted at runtime in v3.x. Will be removed in the next major version.

    • ReadonlyPORT_NOT_OPEN: "PORT_NOT_OPEN"

      Serial port is not open.

      Emitted when send$ or disconnect$ is called in an invalid session state (for example before connect$ completes).

      Suggested action: Call SerialSession.connect$ before sending data.

    • ReadonlyPORT_OPEN_FAILED: "PORT_OPEN_FAILED"

      Failed to open the serial port.

      Emitted on connect$ when port.open() rejects.

      Suggested action: Verify connection parameters and check hardware connections.

    • ReadonlyREAD_FAILED: "READ_FAILED"

      Failed to read from the serial port.

      This error occurs when reading data from the port fails, typically due to connection loss, hardware issues, or stream errors.

      Suggested action: Check the connection and hardware, then retry the read operation.

    • ReadonlyRECEIVE_REPLAY_BUFFER_OVERFLOW: "RECEIVE_REPLAY_BUFFER_OVERFLOW"

      Receive replay buffer exceeded its configured character limit.

      This error occurs when buffered chunks on SerialSession.receiveReplay$ exceed SerialSessionOptions.receiveReplay maxChars. Oldest chunks are discarded to bound memory; the session remains connected.

      Suggested action: Increase receiveReplay.maxChars, reduce chunk size at the source, or subscribe earlier to avoid relying on a large replay buffer.

    • ReadonlySESSION_DISPOSED: "SESSION_DISPOSED"

      Session has been disposed and can no longer be used.

      This error occurs when calling SerialSession.connect$ or SerialSession.send$ after SerialSession.dispose$ has completed. Create a new session instead of reusing a disposed instance.

      Suggested action: Call SerialSession.dispose$ only when permanently tearing down a session, then create a new one if needed.

    • ReadonlyUNKNOWN: "UNKNOWN"

      Unknown error occurred.

      Emitted as a fallback when dispose or disconnect encounters an error that cannot be classified more specifically. The underlying failure is on context.cause.

      Suggested action: Check the error message and context.cause for more details.

    • ReadonlyWRITE_FAILED: "WRITE_FAILED"

      Failed to write to the serial port.

      This error occurs when writing data to the port fails, typically due to connection loss, hardware issues, or stream errors.

      Suggested action: Check the connection and hardware, then retry the write operation.

    try {
    await client.connect().toPromise();
    } catch (error) {
    if (error instanceof SerialError) {
    switch (error.code) {
    case SerialErrorCode.BROWSER_NOT_SUPPORTED:
    console.error('Please use a supported desktop browser (Chrome, Edge, Opera, or Firefox 151+)');
    break;
    case SerialErrorCode.OPERATION_CANCELLED:
    console.log('User cancelled port selection');
    break;
    // ... handle other error codes
    }
    }
    }