16 MB_FC_READ_COILS = 0x01,
17 MB_FC_READ_INPUT_STAT = 0x02,
18 MB_FC_READ_REGS = 0x03,
19 MB_FC_READ_INPUT_REGS = 0x04,
20 MB_FC_WRITE_COIL = 0x05,
21 MB_FC_WRITE_REG = 0x06,
22 MB_FC_WRITE_COILS = 0x0F,
23 MB_FC_WRITE_REGS = 0x10,
24 MB_FC_REPORT_SERVER_ID = 0x11,
29 MB_EX_ILLEGAL_FUNCTION = 0x01,
30 MB_EX_ILLEGAL_ADDRESS = 0x02,
31 MB_EX_ILLEGAL_VALUE = 0x03,
32 MB_EX_SLAVE_FAILURE = 0x04,
39 MB_REPLY_NORMAL = 0x03,
70 char *_additional_data;
72 void readRegisters (
const byte fcode,
const word startreg,
const word numregs);
73 void writeSingleRegister (
const word reg,
const word value);
74 void writeMultipleRegisters (
const byte *frame,
const word startreg,
const word numoutputs,
const byte bytecount);
75 void exceptionResponse (
const byte fcode,
const byte excode);
77 #ifndef USE_HOLDING_REGISTERS_ONLY
78 void readBits (
const byte fcode,
const word startreg,
const word numregs);
79 void writeSingleCoil (
const word reg,
const word status);
80 void writeMultipleCoils (
const byte *frame,
const word startreg,
const word numoutputs,
const byte bytecount);
85 void addReg (word address, word value = 0);
86 bool setReg (word address, word value);
87 word reg (word address);
88 bool setRegBounds (word address, word min, word max);
89 bool regOutOfBounds (word address, word value);
92 inline bool Reg (word address, word value) {
93 return setReg (address, value);
96 inline word Reg (word address) {
105 void receivePDU (
byte *frame);
106 void reportServerId();
107 void debugMessage (
bool reply =
false);
121 inline void addHreg (word offset, word value = 0) {
122 this->addReg (offset + TRegister::HregOffset, value);
131 inline bool setHreg (word offset, word value) {
132 return setReg (offset + TRegister::HregOffset, value);
139 inline word
hreg (word offset) {
140 return reg (offset + TRegister::HregOffset);
151 return setRegBounds (offset + TRegister::HregOffset, min, max);
161 return regOutOfBounds (offset + TRegister::HregOffset, value);
172 inline bool Hreg (word offset, word value) {
173 return setHreg (offset, value);
181 inline word
Hreg (word offset) {
182 return hreg (offset);
190 _debug->println (
"Modbus: debug enabled....");
197 return _debug !=
nullptr;
204 inline void debug (
const char *msg) {
206 _debug->println (msg);
210 #ifndef USE_HOLDING_REGISTERS_ONLY
217 void addCoil (word offset,
bool value =
false) {
218 this->addReg (offset + TRegister::CoilOffset, value ? 0xFF00 : 0x0000);
225 inline void addIsts (word offset,
bool value =
false) {
226 this->addReg (offset + TRegister::IstsOffset, value ? 0xFF00 : 0x0000);
233 inline void addIreg (word offset, word value = 0) {
234 this->addReg (offset + TRegister::IregOffset, value);
243 inline bool setCoil (word offset,
bool value) {
244 return setReg (offset + TRegister::CoilOffset, value ? 0xFF00 : 0x0000);
253 inline bool setIsts (word offset,
bool value) {
254 return setReg (offset + TRegister::IstsOffset, value ? 0xFF00 : 0x0000);
263 inline bool setIreg (word offset, word value) {
264 return setReg (offset + TRegister::IregOffset, value);
271 inline bool coil (word offset) {
272 return (reg (offset + TRegister::CoilOffset) == 0xFF00);
279 inline bool ists (word offset) {
280 return (reg (offset + TRegister::IstsOffset) == 0xFF00);
287 inline word
ireg (word offset) {
288 return reg (offset + TRegister::IregOffset);
298 inline bool Coil (word offset,
bool value) {
299 return setCoil (offset, value);
309 inline bool Ists (word offset,
bool value) {
310 return setIsts (offset, value);
320 inline bool Ireg (word offset, word value) {
321 return setIreg (offset, value);
329 inline bool Coil (word offset) {
330 return coil (offset);
338 inline bool Ists (word offset) {
339 return ists (offset);
347 inline word
Ireg (word offset) {
348 return ireg (offset);
Modbus()
Default constructor.
void debug(const char *msg)
Print a debug message, only if debug mode is enabled.
bool Coil(word offset)
Return the value of a coil.
word ireg(word offset)
Return the value of an input register.
bool hregOutOfBounds(word offset, word value)
Checks if the value is outside the bounds of a holging register.
bool Ists(word offset, bool value)
Change the value of a discrete input This value will be returned when bus read,.
bool coil(word offset)
Return the value of a coil.
bool Coil(word offset, bool value)
Change the value of a coil This value will be returned when bus read, the master can also modify it.
void addHreg(word offset, word value=0)
Add a holding register to the list.
bool Ists(word offset)
Return the value of a discrete input.
word Hreg(word offset)
Return the value of a holding register.
void addIreg(word offset, word value=0)
Add a input register.
bool setIreg(word offset, word value)
Change the value of an input register This value will be returned when bus read.
int setAdditionalServerData(const char data[])
Sets additional Data for Report Server ID function.
void addIsts(word offset, bool value=false)
Add a discrete input.
word Ireg(word offset)
Return the value of an input register.
bool setCoil(word offset, bool value)
Change the value of a coil This value will be returned when bus read, the master can also modify it.
bool setHreg(word offset, word value)
Change the value of a holding register This value will be returned when bus read, the master can also...
bool Ireg(word offset, word value)
Change the value of an input register This value will be returned when bus read.
bool isDebug()
Returns true if debug mode is enabled.
word hreg(word offset)
Return the value of a holding register.
bool setIsts(word offset, bool value)
Change the value of a discrete input This value will be returned when bus read,.
void addCoil(word offset, bool value=false)
Add a coil.
bool Hreg(word offset, word value)
Change the value of a holding register This value will be returned when bus read, the master can also...
bool setHregBounds(word offset, word min, word max)
Sets the bounds of a holding register.
bool ists(word offset)
Return the value of a discrete input.
void setDebug(Print &print)
Enable debug mode.