using System.Collections.Generic;
namespace AMWD.Protocols.Modbus.Common.Contracts
{
///
/// A definition of the capabilities an implementation of the Modbus protocol version should have.
///
public interface IModbusProtocol
{
///
/// Gets the protocol type name.
///
string Name { get; }
#region Read
///
/// Serializes a read request for s.
///
/// The unit id.
/// The starting address.
/// The number of coils to read.
/// The s to send.
IReadOnlyList SerializeReadCoils(byte unitId, ushort startAddress, ushort count);
///
/// Deserializes a read response for s.
///
/// The s received.
/// A list of s.
IReadOnlyList DeserializeReadCoils(IReadOnlyList response);
///
/// Serializes a read request for s.
///
/// The unit id.
/// The starting address.
/// The number of discrete inputs to read.
/// The s to send.
IReadOnlyList SerializeReadDiscreteInputs(byte unitId, ushort startAddress, ushort count);
///
/// Deserializes a read response for s.
///
/// The s received.
/// A list of s.
IReadOnlyList DeserializeReadDiscreteInputs(IReadOnlyList response);
///
/// Serializes a read request for s.
///
/// The unit id.
/// The starting address.
/// The number of holding registers to read.
/// The s to send.
IReadOnlyList SerializeReadHoldingRegisters(byte unitId, ushort startAddress, ushort count);
///
/// Deserializes a read response for s.
///
/// The s received.
/// A list of s.
IReadOnlyList DeserializeReadHoldingRegisters(IReadOnlyList response);
///
/// Serializes a read request for s.
///
/// The unit id.
/// The starting address.
/// The number of input registers to read.
/// The s to send.
IReadOnlyList SerializeReadInputRegisters(byte unitId, ushort startAddress, ushort count);
///
/// Deserializes a read response for s.
///
/// The s received.
/// A list of s.
IReadOnlyList DeserializeReadInputRegisters(IReadOnlyList response);
///
/// Serializes a read request for device identification.
///
/// The unit id.
/// The identification category to read.
/// The first object id to read.
/// The s to send.
IReadOnlyList SerializeReadDeviceIdentification(byte unitId, ModbusDeviceIdentificationCategory category, ModbusDeviceIdentificationObject objectId);
///
/// Deserializes a read response for device identification.
///
/// The s received.
/// The raw device identification information data.
DeviceIdentificationRaw DeserializeReadDeviceIdentification(IReadOnlyList response);
#endregion Read
#region Write
///
/// Serializes a write request for a single .
///
/// The unit id.
/// The coil to write.
/// The s to send.
IReadOnlyList SerializeWriteSingleCoil(byte unitId, Coil coil);
///
/// Deserializes a write response for a single .
///
/// The s received.
/// Should be the coil itself, as the response is an echo of the request.
Coil DeserializeWriteSingleCoil(IReadOnlyList response);
///
/// Serializes a write request for a single .
///
/// The unit id.
/// The holding register to write.
/// The s to send.
IReadOnlyList SerializeWriteSingleHoldingRegister(byte unitId, HoldingRegister register);
///
/// Deserializes a write response for a single .
///
/// The s received.
/// Should be the holding register itself, as the response is an echo of the request.
HoldingRegister DeserializeWriteSingleHoldingRegister(IReadOnlyList response);
///
/// Serializes a write request for multiple s.
///
/// The unit id.
/// The coils to write.
/// The s to send.
IReadOnlyList SerializeWriteMultipleCoils(byte unitId, IReadOnlyList coils);
///
/// Deserializes a write response for multiple s.
///
/// The s received.
/// A tuple containting the first address and the number of coils written.
(ushort FirstAddress, ushort NumberOfCoils) DeserializeWriteMultipleCoils(IReadOnlyList response);
///
/// Serializes a write request for multiple s.
///
/// The unit id.
/// The holding registers to write.
/// The s to send.
IReadOnlyList SerializeWriteMultipleHoldingRegisters(byte unitId, IReadOnlyList registers);
///
/// Deserializes a write response for multiple s.
///
/// The s received.
/// A tuple containting the first address and the number of holding registers written.
(ushort FirstAddress, ushort NumberOfRegisters) DeserializeWriteMultipleHoldingRegisters(IReadOnlyList response);
#endregion Write
#region Control
///
/// Checks whether the receive response bytes are complete to deserialize the response.
///
/// The already received response bytes.
/// when the response is complete, otherwise .
bool CheckResponseComplete(IReadOnlyList responseBytes);
///
/// Validates the response against the request and throws s if necessary.
///
/// The serialized request.
/// The received response.
void ValidateResponse(IReadOnlyList request, IReadOnlyList response);
#endregion Control
}
}