MulAvailable

This commit is contained in:
Nitload
2025-12-16 23:13:17 +08:00
parent 28ea5d1d1e
commit 3486375470
2637 changed files with 23787 additions and 838773 deletions
+54
View File
@@ -0,0 +1,54 @@
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;
}
}