interface DeviceConnection {
    status: ConnectionStatus;
    type: string;
    addEventListener(
        type: "status",
        listener: (data: ConnectionStatusChange) => void,
    ): void;
    addEventListener(
        type: "backgrounderror",
        listener: (data: BackgroundErrorData) => void,
    ): void;
    addEventListener(type: "beforerequestdevice", listener: () => void): void;
    addEventListener(type: "afterrequestdevice", listener: () => void): void;
    addEventListener(type: "flash", listener: () => void): void;
    checkAvailability(): Promise<ConnectionAvailabilityStatus>;
    clearDevice(): void | Promise<void>;
    connect(options?: ConnectOptions): Promise<void>;
    disconnect(): Promise<void>;
    dispose(): void;
    flash(dataSource: FlashDataSource, options: FlashOptions): Promise<void>;
    getBoardVersion(): BoardVersion;
    initialize(): Promise<void>;
    removeEventListener(
        type: "status",
        listener: (data: ConnectionStatusChange) => void,
    ): void;
    removeEventListener(
        type: "backgrounderror",
        listener: (data: BackgroundErrorData) => void,
    ): void;
    removeEventListener(
        type: "beforerequestdevice",
        listener: () => void,
    ): void;
    removeEventListener(type: "afterrequestdevice", listener: () => void): void;
    removeEventListener(type: "flash", listener: () => void): void;
}

Hierarchy (View Summary)

Properties

type: string

Methods

  • Connects to a currently paired device or requests pairing.

    Parameters

    • Optionaloptions: ConnectOptions

      Optional connection options including progress callback and abort signal.

    Returns Promise<void>

    On connection failure. The error.code property indicates the failure type.

  • Flash the micro:bit.

    Not all connection types support flashing. For example, radio bridge connections do not support flashing, and Bluetooth connections only support flashing on native platforms (not Web).

    Post-flash connection state differs by transport:

    • USB: The connection remains in ConnectionStatus.Connected state. USB connects to the micro:bit's interface chip (running DAPLink firmware), which is not affected by flashing the application processor, so the connection persists and serial communication is automatically reinitialised.

    • Bluetooth: The connection is always left in ConnectionStatus.Disconnected state. Bluetooth connects to the application processor directly, which reboots after flashing, so the connection is necessarily lost. Callers must call connect again after flashing.

    Parameters

    Returns Promise<void>

    On flash failure. The error.code property indicates the failure type.

    If data preparation fails.