Dynamic Modbus Master
A dynamic wrapper for the modbus master part of esp-modbus written in C++.
 
Loading...
Searching...
No Matches
SlaveDeviceIfc.h
Go to the documentation of this file.
1//Copyright (c) 2024 Dominik M. Glogowski
2//
3//Permission is hereby granted, free of charge, to any person obtaining a copy
4//of this software and associated documentation files (the "Software"), to deal
5//in the Software without restriction, including without limitation the rights
6//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7//copies of the Software, and to permit persons to whom the Software is
8//furnished to do so, subject to the following conditions:
9//
10//The above copyright notice and this permission notice shall be included in all
11//copies or substantial portions of the Software.
12//
13//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19//SOFTWARE.
20
21#ifndef DYNAMIC_MODBUS_MASTER_SLAVEDEVICEIFC_H
22#define DYNAMIC_MODBUS_MASTER_SLAVEDEVICEIFC_H
23
24#include "dmm_common.h"
25#include "ModbusData.hpp"
26#include "ModbusError.h"
27
29
46template<class T>
48public:
49 virtual ~SlaveDeviceIfc() = default;
50
63 template<ModbusData D>
64 ModbusError writeHolding(uint16_t reg, const D& data) const {
65 return static_cast<T const*>(this)->template writeHolding<D>(reg, data);
66 }
67
79 template<ModbusData D>
81 return static_cast<T const*>(this)->template readHolding<D>(reg);
82 }
83
95 template<ModbusData D>
97 return static_cast<T const*>(this)->template writeCoils<D>(reg, data, coilNum);
98 }
99
110 template<ModbusData D>
112 return static_cast<T const *>(this)->template readCoils<D>(reg, coilNum);
113 }
114
125 template<ModbusData D>
127 return static_cast<T const *>(this)->template readInputs<D>(reg);
128 }
129
141 template<ModbusData D>
143 return static_cast<T const *>(this)->template readDiscreteInputs<D>(reg);
144 }
145};
146}
147
148#endif //DYNAMIC_MODBUS_MASTER_SLAVEDEVICEIFC_H
Interface class for slave devices in a Modbus network.
Definition SlaveDeviceIfc.h:47
ModbusError writeCoils(uint16_t reg, const D &data, uint16_t coilNum)
Write data to a group of coils.
Definition SlaveDeviceIfc.h:96
SlaveReturn< D > readDiscreteInputs(uint16_t reg)
Reads data from discrete inputs in a Modbus slave device.
Definition SlaveDeviceIfc.h:142
SlaveReturn< D > readHolding(uint16_t reg) const
Read data from a holding register.
Definition SlaveDeviceIfc.h:80
ModbusError writeHolding(uint16_t reg, const D &data) const
Write data to a holding register.
Definition SlaveDeviceIfc.h:64
SlaveReturn< D > readCoils(uint16_t reg, uint16_t coilNum)
Read data from a group of coils.
Definition SlaveDeviceIfc.h:111
SlaveReturn< D > readInputs(uint16_t reg)
Read data from input registers.
Definition SlaveDeviceIfc.h:126
Definition ModbusData.hpp:45
ModbusError
Modbus Error Type Enum.
Definition ModbusError.h:30
Represents the return value from a Modbus slave device.
Definition ModbusData.hpp:58