Interface
public interface ITransport : IAsyncDisposable
Namespace: SharpMeter.Transport
Defines the transport layer interface for PSEM communication. Implementations handle the physical send/receive of raw bytes over serial, TCP, or in-memory channels.
Inheritance
Implements: IAsyncDisposable
Properties
| Name | Description |
|---|---|
IsConnected abstract |
Gets a value indicating whether the transport connection is open. |
IsConnected
bool ITransport.IsConnected { get; }
Gets a value indicating whether the transport connection is open.
Methods
| Name | Description |
|---|---|
ConnectAsync(CancellationToken cancellationToken) abstract |
Opens the transport connection. |
DisconnectAsync(CancellationToken cancellationToken) abstract |
Closes the transport connection. |
ReceiveAsync(Memory<byte> buffer, CancellationToken cancellationToken) abstract |
Receives raw bytes from the transport. |
SendAsync(ReadOnlyMemory<byte> data, CancellationToken cancellationToken) abstract |
Sends raw bytes over the transport. |
SendControlAsync(byte controlByte, CancellationToken cancellationToken) abstract |
Sends a single control byte (ACK, NAK, CAN). |
ConnectAsync(CancellationToken cancellationToken)
ValueTask<Result<bool>> ITransport.ConnectAsync(CancellationToken cancellationToken = null)
Opens the transport connection.
Parameters
| Name | Type | Description |
|---|---|---|
cancellationToken | CancellationToken | Cancellation token. |
Returns: A result indicating success or transport error.
DisconnectAsync(CancellationToken cancellationToken)
ValueTask ITransport.DisconnectAsync(CancellationToken cancellationToken = null)
Closes the transport connection.
Parameters
| Name | Type | Description |
|---|---|---|
cancellationToken | CancellationToken | Cancellation token. |
ReceiveAsync(Memory buffer, CancellationToken cancellationToken)
ValueTask<Result<int>> ITransport.ReceiveAsync(Memory<byte> buffer, CancellationToken cancellationToken = null)
Receives raw bytes from the transport.
Parameters
| Name | Type | Description |
|---|---|---|
buffer | Memory<byte> | The buffer to receive into. |
cancellationToken | CancellationToken | Cancellation token. |
Returns: A result containing the number of bytes received, or a transport error.
SendAsync(ReadOnlyMemory data, CancellationToken cancellationToken)
ValueTask<Result<bool>> ITransport.SendAsync(ReadOnlyMemory<byte> data, CancellationToken cancellationToken = null)
Sends raw bytes over the transport.
Parameters
| Name | Type | Description |
|---|---|---|
data | ReadOnlyMemory<byte> | The data to send. |
cancellationToken | CancellationToken | Cancellation token. |
Returns: A result indicating success or transport error.
SendControlAsync(byte controlByte, CancellationToken cancellationToken)
ValueTask ITransport.SendControlAsync(byte controlByte, CancellationToken cancellationToken = null)
Sends a single control byte (ACK, NAK, CAN).
Parameters
| Name | Type | Description |
|---|---|---|
controlByte | byte | The control byte to send. |
cancellationToken | CancellationToken | Cancellation token. |
Type Relationships
classDiagram
style ITransport fill:#f9f,stroke:#333,stroke-width:2px
ITransport ..|> IAsyncDisposable : implements
EmulatorTransport --|> ITransport : inherits
LoopbackTransport ..|> ITransport : implements
SerialTransport ..|> ITransport : implements
TcpTransport ..|> ITransport : implements
View Source
/// <summary>
/// Defines the transport layer interface for PSEM communication.
/// Implementations handle the physical send/receive of raw bytes over serial, TCP, or in-memory channels.
/// </summary>
public interface ITransport : IAsyncDisposable
{
/// <summary>Gets a value indicating whether the transport connection is open.</summary>
bool IsConnected { get; }
/// <summary>
/// Opens the transport connection.
/// </summary>
/// <param name = "cancellationToken">Cancellation token.</param>
/// <returns>A result indicating success or transport error.</returns>
ValueTask<Result<bool>> ConnectAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Closes the transport connection.
/// </summary>
/// <param name = "cancellationToken">Cancellation token.</param>
ValueTask DisconnectAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Sends raw bytes over the transport.
/// </summary>
/// <param name = "data">The data to send.</param>
/// <param name = "cancellationToken">Cancellation token.</param>
/// <returns>A result indicating success or transport error.</returns>
ValueTask<Result<bool>> SendAsync(ReadOnlyMemory<byte> data, CancellationToken cancellationToken = default);
/// <summary>
/// Receives raw bytes from the transport.
/// </summary>
/// <param name = "buffer">The buffer to receive into.</param>
/// <param name = "cancellationToken">Cancellation token.</param>
/// <returns>A result containing the number of bytes received, or a transport error.</returns>
ValueTask<Result<int>> ReceiveAsync(Memory<byte> buffer, CancellationToken cancellationToken = default);
/// <summary>
/// Sends a single control byte (ACK, NAK, CAN).
/// </summary>
/// <param name = "controlByte">The control byte to send.</param>
/// <param name = "cancellationToken">Cancellation token.</param>
ValueTask SendControlAsync(byte controlByte, CancellationToken cancellationToken = default);
}