Search Results for

    Show / Hide Table of Contents

    Interface ITransport

    Abstraction over a byte-stream transport (e.g., Serial, Bluetooth, TCP). Implementations surface incoming bytes via BytesReceived and provide async connect/disconnect/send operations.

    Namespace: Wss.CoreModule
    Assembly: WSS_Core_Interface.dll
    Syntax
    public interface ITransport
    Remarks

    This interface is intentionally minimal and transport-agnostic so higher-level code can be reused with different physical links (UART/COM, RFCOMM, BLE GATT, sockets).

    Threading: Implementations typically raise BytesReceived from a background thread. If your application requires main-thread access, marshal the callback to the main thread.

    Chunking: Incoming chunks may contain partial frames, multiple frames, or arbitrary boundaries. Always pass chunks to a frame codec/deframer instead of assuming message boundaries align with reads.

    Properties

    IsConnected

    Gets whether the transport is currently connected/open.

    Declaration
    bool IsConnected { get; }
    Property Value
    Type Description
    bool

    Methods

    ConnectAsync(CancellationToken)

    Opens/initializes the transport connection (e.g., open a serial port, connect a socket, start BLE session).

    Declaration
    Task ConnectAsync(CancellationToken ct = default)
    Parameters
    Type Name Description
    CancellationToken ct

    Optional cancellation token to abort the connect attempt.

    Returns
    Type Description
    Task

    A task that completes when the transport is connected.

    Exceptions
    Type Condition
    ObjectDisposedException

    If the instance has been disposed.

    OperationCanceledException

    If ct is canceled.

    Exception

    Implementations may throw transport-specific exceptions (e.g., unauthorized port access, device not found).

    DisconnectAsync(CancellationToken)

    Closes the transport connection and stops any background receive loop.

    Declaration
    Task DisconnectAsync(CancellationToken ct = default)
    Parameters
    Type Name Description
    CancellationToken ct

    Optional cancellation token to abort a long-running disconnect.

    Returns
    Type Description
    Task

    A task that completes when the transport is fully disconnected.

    Exceptions
    Type Condition
    ObjectDisposedException

    If the instance has been disposed.

    OperationCanceledException

    If ct is canceled.

    SendAsync(byte[], CancellationToken)

    Sends a block of bytes over the transport.

    Declaration
    Task SendAsync(byte[] data, CancellationToken ct = default)
    Parameters
    Type Name Description
    byte[] data

    The bytes to write. Callers should provide a buffer that will not be mutated during send.

    CancellationToken ct

    Optional cancellation token to cancel the send before it is written. For some transports (e.g., synchronous serial writes), cancellation may only be observed before the write starts.

    Returns
    Type Description
    Task

    A task that completes when the bytes have been handed off to the transport.

    Exceptions
    Type Condition
    ObjectDisposedException

    If the instance has been disposed.

    InvalidOperationException

    If the transport is not connected.

    OperationCanceledException

    If ct is canceled.

    Events

    BytesReceived

    Raised whenever raw bytes arrive from the underlying transport. Each invocation may represent any number of bytes (including zero, depending on implementation), and may contain partial or multiple protocol frames.

    Declaration
    event Action<byte[]> BytesReceived
    Event Type
    Type Description
    Action<byte[]>
    Remarks

    Implementations should invoke this event promptly as data becomes available. Callers should treat the provided buffer as read-only and copy it if they need to retain it.

    This event is typically raised on a background thread. Consumers should marshal to the main thread if required by their environment.

    In this article
    Back to top Generated by DocFX