namespace ZB.MOM.WW.OtOpcUa.Driver.Modbus; /// /// Abstraction over the Modbus TCP socket. Takes a PDU (function code + data, excluding /// the 7-byte MBAP header) and returns the response PDU — the transport owns transaction-id /// pairing, framing, and socket I/O. Tests supply in-memory fakes. /// public interface IModbusTransport : IAsyncDisposable { /// Establishes a connection to the Modbus server. /// A cancellation token to observe for cancellation. /// A task representing the asynchronous connection operation. Task ConnectAsync(CancellationToken ct); /// /// Send a Modbus PDU (function code + function-specific data) and read the response PDU. /// Throws when the server returns an exception PDU /// (function code + 0x80 + exception code). /// /// The Modbus unit identifier (slave address). /// The protocol data unit (function code and data) to send. /// A cancellation token to observe for cancellation. /// A task representing the asynchronous send operation that returns the response PDU. Task SendAsync(byte unitId, byte[] pdu, CancellationToken ct); } /// Represents a Modbus protocol exception. public sealed class ModbusException(byte functionCode, byte exceptionCode, string message) : Exception(message) { /// Gets the Modbus function code that caused the exception. public byte FunctionCode { get; } = functionCode; /// Gets the Modbus exception code. public byte ExceptionCode { get; } = exceptionCode; }