36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace EM.LowLevel
|
|
{
|
|
/// <summary>
|
|
/// High-level transport abstraction for device communication. Derives from Stream and
|
|
/// encapsulates initialization/handshake and frame (header/tail/checksum) handling as needed
|
|
/// by the device. Implementations may wrap SerialPort, Sockets, USB, etc.
|
|
/// </summary>
|
|
public abstract class PortStream : Stream
|
|
{
|
|
|
|
/// <summary>
|
|
/// Optional bytes available hint if the transport can provide it.
|
|
/// </summary>
|
|
public virtual long? BytesAvailable => null;
|
|
|
|
/// <summary>
|
|
/// Close the underlying transport and release resources.
|
|
/// </summary>
|
|
public abstract override void Close();
|
|
|
|
/// <summary>
|
|
/// Ensure the port is opened and ready. Idempotent. May perform device-specific
|
|
/// handshakes.
|
|
/// </summary>
|
|
public abstract ValueTask OpenAsync(CancellationToken cancellationToken = default);
|
|
|
|
// Concrete transports must implement Stream's abstract members.
|
|
// Seek-related members are typically not supported and should throw NotSupportedException.
|
|
}
|
|
}
|