Dynamic Modbus Master
A dynamic wrapper for the modbus master part of esp-modbus written in C++.
 
Loading...
Searching...
No Matches
dynamic_modbus_master::slave::SlaveDeviceIfc< T > Class Template Reference

Interface class for slave devices in a Modbus network. More...

#include <SlaveDeviceIfc.h>

+ Collaboration diagram for dynamic_modbus_master::slave::SlaveDeviceIfc< T >:

Public Member Functions

virtual ~SlaveDeviceIfc ()=default
 
template<ModbusData D>
ModbusError writeHolding (uint16_t reg, const D &data) const
 Write data to a holding register.
 
template<ModbusData D>
SlaveReturn< DreadHolding (uint16_t reg) const
 Read data from a holding register.
 
template<ModbusData D>
ModbusError writeCoils (uint16_t reg, const D &data, uint16_t coilNum)
 Write data to a group of coils.
 
template<ModbusData D>
SlaveReturn< DreadCoils (uint16_t reg, uint16_t coilNum)
 Read data from a group of coils.
 
template<ModbusData D>
SlaveReturn< DreadInputs (uint16_t reg)
 Read data from input registers.
 
template<ModbusData D>
SlaveReturn< DreadDiscreteInputs (uint16_t reg)
 Reads data from discrete inputs in a Modbus slave device.
 

Detailed Description

template<class T>
class dynamic_modbus_master::slave::SlaveDeviceIfc< T >

Interface class for slave devices in a Modbus network.

This class provides an interface for slave devices in a Modbus network. It uses CRTP to allow the usage of generic templated virtual Methods.

This interface can be used when devices require a different Implementation for their communication from dynamic_modbus_master::slave::SlaveDevice which provides a generally good way to access a device.

Note
for further info on CRTP see cppreference , Wikipedia or FluentCPP
Template Parameters
TThe derived class that implements the interface

Constructor & Destructor Documentation

◆ ~SlaveDeviceIfc()

Member Function Documentation

◆ readCoils()

template<class T >
template<ModbusData D>
SlaveReturn< D > dynamic_modbus_master::slave::SlaveDeviceIfc< T >::readCoils ( uint16_t  reg,
uint16_t  coilNum 
)
inline

Read data from a group of coils.

This method reads data from a group of coils starting at the specified coil address.

Parameters
regThe coil address to start reading data from
coilNumThe number of coils to read data from
Template Parameters
DThe type as which the read Data will be returned, must fulfill the ModbusData concept.
Returns
A SlaveReturn structure containing the read data and any errors encountered during the read operation

◆ readDiscreteInputs()

template<class T >
template<ModbusData D>
SlaveReturn< D > dynamic_modbus_master::slave::SlaveDeviceIfc< T >::readDiscreteInputs ( uint16_t  reg)
inline

Reads data from discrete inputs in a Modbus slave device.

This function reads data from discrete inputs in a Modbus slave device at the specified register address. The function is templated to allow reading data of different types. The type of data to be read must fulfill the ModbusData concept. The function delegates the actual implementation to the derived class implementing the interface.

Template Parameters
DThe type of data to be read, must fulfill the ModbusData concept
Parameters
regThe register address to read the data from
Returns
A SlaveReturn structure containing the read data and any errors encountered during the read operation

◆ readHolding()

template<class T >
template<ModbusData D>
SlaveReturn< D > dynamic_modbus_master::slave::SlaveDeviceIfc< T >::readHolding ( uint16_t  reg) const
inline

Read data from a holding register.

This method reads data from a holding register at the specified register address. The data read must be of a type that can be represented in Modbus registers, i.e., it must be at least 16-bits or the size of a single Modbus register.

Parameters
regThe register address to read the data from
Template Parameters
DThe type of data to be read
Returns
A SlaveReturn structure containing the read data and any errors encountered during the read operation

◆ readInputs()

template<class T >
template<ModbusData D>
SlaveReturn< D > dynamic_modbus_master::slave::SlaveDeviceIfc< T >::readInputs ( uint16_t  reg)
inline

Read data from input registers.

This method reads data from input registers at the specified register address. Input registers are read-only and contain data from the slave device.

Parameters
regThe register address to read the data from
Template Parameters
DThe type of data to be read from input registers, must fulfill the ModbusData concept
Returns
A SlaveReturn structure containing the read data and any errors encountered during the read operation

◆ writeCoils()

template<class T >
template<ModbusData D>
ModbusError dynamic_modbus_master::slave::SlaveDeviceIfc< T >::writeCoils ( uint16_t  reg,
const D data,
uint16_t  coilNum 
)
inline

Write data to a group of coils.

This method writes the provided data to a group of coils starting at the specified coil address.

Parameters
regThe coil address to start writing data to
dataThe data to be written to the coils
coilNumThe number of coils to write data to
Template Parameters
DThe type of data to be written, must fulfill the ModbusData concept.
Returns
A ModbusError value indicating the success or failure of the write operation

◆ writeHolding()

template<class T >
template<ModbusData D>
ModbusError dynamic_modbus_master::slave::SlaveDeviceIfc< T >::writeHolding ( uint16_t  reg,
const D &  data 
) const
inline

Write data to a holding register.

This method writes the provided data to a holding register at the specified register address. The data must be of a type that can be represented in Modbus registers, i.e., it must be at least 16-bits or the size of a single Modbus register.

Parameters
regThe register address to write the data to
dataThe data to be written to the register
Template Parameters
DThe type of data to be written
Returns
A ModbusError value indicating the success or failure of the write operation

The documentation for this class was generated from the following file: