55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace EM.LowLevel
|
|
{
|
|
/// <summary>
|
|
/// Generic high-level controller that composes a PortStream, an ICommandBuilder and an
|
|
/// IDataDecoder to provide a complete peripheral control workflow.
|
|
/// </summary>
|
|
/// <typeparam name="TPort">
|
|
/// Concrete transport deriving from PortStream
|
|
/// </typeparam>
|
|
/// <typeparam name="TBuilder">
|
|
/// Concrete command builder
|
|
/// </typeparam>
|
|
/// <typeparam name="TDecoder">
|
|
/// Concrete data decoder
|
|
/// </typeparam>
|
|
public interface IPortController<TPort, TBuilder, TDecoder> where TPort: PortStream where TBuilder: ICommandBuilder
|
|
where TDecoder: IDataDecoder
|
|
{
|
|
|
|
TBuilder CommandBuilder { get; }
|
|
|
|
TDecoder Decoder { get; }
|
|
|
|
TPort Port { get; }
|
|
|
|
/// <summary>
|
|
/// Close the underlying port.
|
|
/// </summary>
|
|
void Close();
|
|
|
|
/// <summary>
|
|
/// Ensure the underlying port is opened and ready (delegates to Port.OpenAsync).
|
|
/// </summary>
|
|
ValueTask OpenAsync(CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Build a command, send it via the port and decode the response into a model.
|
|
/// </summary>
|
|
ValueTask<TResponse> RoundTripAsync<TCommand, TResponse>(
|
|
TCommand command,
|
|
CancellationToken cancellationToken = default)
|
|
where TCommand: notnull;
|
|
|
|
/// <summary>
|
|
/// Build a command and send it without expecting a typed response.
|
|
/// </summary>
|
|
ValueTask WriteAsync<TCommand>(TCommand command, CancellationToken cancellationToken = default)
|
|
where TCommand: notnull;
|
|
|
|
}
|
|
}
|