@@ -73,9 +73,9 @@ class Modbus {
73
73
void writeSingleRegister (const word reg, const word value);
74
74
void writeMultipleRegisters (const byte *frame, const word startreg, const word numoutputs, const byte bytecount);
75
75
void exceptionResponse (const byte fcode, const byte excode);
76
-
76
+
77
77
#ifndef USE_HOLDING_REGISTERS_ONLY
78
- void readBits (const byte fcode,const word startreg, const word numregs);
78
+ void readBits (const byte fcode, const word startreg, const word numregs);
79
79
void writeSingleCoil (const word reg, const word status);
80
80
void writeMultipleCoils (const byte *frame, const word startreg, const word numoutputs, const byte bytecount);
81
81
#endif
@@ -101,8 +101,10 @@ class Modbus {
101
101
byte *_frame;
102
102
byte _len;
103
103
byte _reply;
104
+ Print *_debug;
104
105
void receivePDU (byte *frame);
105
106
void reportServerId ();
107
+ void debugMessage (bool reply = false );
106
108
#endif
107
109
108
110
public:
@@ -180,6 +182,31 @@ class Modbus {
180
182
return hreg (offset);
181
183
}
182
184
185
+ /* *
186
+ @brief Enable debug mode
187
+ */
188
+ inline void setDebug (Print &print) {
189
+ _debug = &print;
190
+ _debug->println (" Modbus: debug enabled...." );
191
+ }
192
+
193
+ /* *
194
+ @brief Returns true if debug mode is enabled
195
+ */
196
+ inline bool isDebug () {
197
+ return _debug != nullptr;
198
+ }
199
+
200
+ /* *
201
+ @brief Print a debug message, only if debug mode is enabled
202
+ @param msg message to print
203
+ */
204
+ inline void debug (const char *msg) {
205
+ if (_debug) {
206
+ _debug->println (msg);
207
+ }
208
+ }
209
+
183
210
#ifndef USE_HOLDING_REGISTERS_ONLY
184
211
185
212
/* *
0 commit comments