using System;
using System.Threading.Tasks;
namespace NModbus
{
///
/// Modbus master device.
///
public interface IModbusMaster : IDisposable
{
///
/// Transport used by this master.
///
IModbusTransport Transport { get; }
///
/// Reads from 1 to 2000 contiguous coils status.
///
/// Address of device to read values from.
/// Address to begin reading.
/// Number of coils to read.
/// Coils status.
bool[] ReadCoils(byte slaveAddress, ushort startAddress, ushort numberOfPoints);
///
/// Asynchronously reads from 1 to 2000 contiguous coils status.
///
/// Address of device to read values from.
/// Address to begin reading.
/// Number of coils to read.
/// A task that represents the asynchronous read operation.
Task ReadCoilsAsync(byte slaveAddress, ushort startAddress, ushort numberOfPoints);
///
/// Reads from 1 to 2000 contiguous discrete input status.
///
/// Address of device to read values from.
/// Address to begin reading.
/// Number of discrete inputs to read.
/// Discrete inputs status.
bool[] ReadInputs(byte slaveAddress, ushort startAddress, ushort numberOfPoints);
///
/// Asynchronously reads from 1 to 2000 contiguous discrete input status.
///
/// Address of device to read values from.
/// Address to begin reading.
/// Number of discrete inputs to read.
/// A task that represents the asynchronous read operation.
Task ReadInputsAsync(byte slaveAddress, ushort startAddress, ushort numberOfPoints);
///
/// Reads contiguous block of holding registers.
///
/// Address of device to read values from.
/// Address to begin reading.
/// Number of holding registers to read.
/// Holding registers status.
ushort[] ReadHoldingRegisters(byte slaveAddress, ushort startAddress, ushort numberOfPoints);
///
/// Asynchronously reads contiguous block of holding registers.
///
/// Address of device to read values from.
/// Address to begin reading.
/// Number of holding registers to read.
/// A task that represents the asynchronous read operation.
Task ReadHoldingRegistersAsync(byte slaveAddress, ushort startAddress, ushort numberOfPoints);
///
/// Reads contiguous block of input registers.
///
/// Address of device to read values from.
/// Address to begin reading.
/// Number of holding registers to read.
/// Input registers status.
ushort[] ReadInputRegisters(byte slaveAddress, ushort startAddress, ushort numberOfPoints);
///
/// Asynchronously reads contiguous block of input registers.
///
/// Address of device to read values from.
/// Address to begin reading.
/// Number of holding registers to read.
/// A task that represents the asynchronous read operation.
Task ReadInputRegistersAsync(byte slaveAddress, ushort startAddress, ushort numberOfPoints);
///
/// Writes a single coil value.
///
/// Address of the device to write to.
/// Address to write value to.
/// Value to write.
void WriteSingleCoil(byte slaveAddress, ushort coilAddress, bool value);
///
/// Asynchronously writes a single coil value.
///
/// Address of the device to write to.
/// Address to write value to.
/// Value to write.
/// A task that represents the asynchronous write operation.
Task WriteSingleCoilAsync(byte slaveAddress, ushort coilAddress, bool value);
///
/// Writes a single holding register.
///
/// Address of the device to write to.
/// Address to write.
/// Value to write.
void WriteSingleRegister(byte slaveAddress, ushort registerAddress, ushort value);
///
/// Asynchronously writes a single holding register.
///
/// Address of the device to write to.
/// Address to write.
/// Value to write.
/// A task that represents the asynchronous write operation.
Task WriteSingleRegisterAsync(byte slaveAddress, ushort registerAddress, ushort value);
///
/// Writes a block of 1 to 123 contiguous registers.
///
/// Address of the device to write to.
/// Address to begin writing values.
/// Values to write.
void WriteMultipleRegisters(byte slaveAddress, ushort startAddress, ushort[] data);
///
/// Asynchronously writes a block of 1 to 123 contiguous registers.
///
/// Address of the device to write to.
/// Address to begin writing values.
/// Values to write.
/// A task that represents the asynchronous write operation.
Task WriteMultipleRegistersAsync(byte slaveAddress, ushort startAddress, ushort[] data);
///
/// Writes a sequence of coils.
///
/// Address of the device to write to.
/// Address to begin writing values.
/// Values to write.
void WriteMultipleCoils(byte slaveAddress, ushort startAddress, bool[] data);
///
/// Asynchronously writes a sequence of coils.
///
/// Address of the device to write to.
/// Address to begin writing values.
/// Values to write.
/// A task that represents the asynchronous write operation.
Task WriteMultipleCoilsAsync(byte slaveAddress, ushort startAddress, bool[] data);
///
/// Performs a combination of one read operation and one write operation in a single Modbus transaction.
/// The write operation is performed before the read.
///
/// Address of device to read values from.
/// Address to begin reading (Holding registers are addressed starting at 0).
/// Number of registers to read.
/// Address to begin writing (Holding registers are addressed starting at 0).
/// Register values to write.
ushort[] ReadWriteMultipleRegisters(
byte slaveAddress,
ushort startReadAddress,
ushort numberOfPointsToRead,
ushort startWriteAddress,
ushort[] writeData);
///
/// Asynchronously performs a combination of one read operation and one write operation in a single Modbus transaction.
/// The write operation is performed before the read.
///
/// Address of device to read values from.
/// Address to begin reading (Holding registers are addressed starting at 0).
/// Number of registers to read.
/// Address to begin writing (Holding registers are addressed starting at 0).
/// Register values to write.
/// A task that represents the asynchronous operation
Task ReadWriteMultipleRegistersAsync(
byte slaveAddress,
ushort startReadAddress,
ushort numberOfPointsToRead,
ushort startWriteAddress,
ushort[] writeData);
///
/// Write a file record to the device.
///
/// Address of device to write values to
/// The Extended Memory file number
/// The starting register address within the file
/// The data to be written
void WriteFileRecord(byte slaveAdress, ushort fileNumber, ushort startingAddress, byte[] data);
///
/// Executes the custom message.
///
/// The type of the response.
/// The request.
TResponse ExecuteCustomMessage(IModbusMessage request)
where TResponse : IModbusMessage, new();
}
}