@@ -73,9 +73,9 @@ class Modbus {
7373 void writeSingleRegister (const word reg, const word value);
7474 void writeMultipleRegisters (const byte *frame, const word startreg, const word numoutputs, const byte bytecount);
7575 void exceptionResponse (const byte fcode, const byte excode);
76-
76+
7777 #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);
7979 void writeSingleCoil (const word reg, const word status);
8080 void writeMultipleCoils (const byte *frame, const word startreg, const word numoutputs, const byte bytecount);
8181 #endif
@@ -101,8 +101,10 @@ class Modbus {
101101 byte *_frame;
102102 byte _len;
103103 byte _reply;
104+ Print *_debug;
104105 void receivePDU (byte *frame);
105106 void reportServerId ();
107+ void debugMessage (bool reply = false );
106108 #endif
107109
108110 public:
@@ -180,6 +182,31 @@ class Modbus {
180182 return hreg (offset);
181183 }
182184
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+
183210 #ifndef USE_HOLDING_REGISTERS_ONLY
184211
185212 /* *
0 commit comments