Open LukeSkaff opened 6 months ago
Thanks for the feedback Luke.
There was no way to disbale the debug messages. You had to manually search & replace all debug messages line as comments.
But I just added a global switch for enabling and disabling the debug messges with the following code.
// Enable/Disable debug messages here. 0 = Disabled, 1 = Enabled
#define DEBUG_ENABLED 1
// You can change the serial port for debug messages here
#define MODBUS_DEBUG_SERIAL Serial
// Define macros for printing debug messages
#if DEBUG_ENABLED
#define DEBUG_PRINT(x) MODBUS_DEBUG_SERIAL.print(x)
#define DEBUG_PRINTLN(x) MODBUS_DEBUG_SERIAL.println(x)
#else
#define DEBUG_PRINT(x)
#define DEBUG_PRINTLN(x)
#endif
Now you can enable/disbale the debug messages by setting the DEBUG_ENABLED
macro. Please test this and let me know if it is working or not, because I have not tested it yet.
You can clone the repository to your local libraries
folder to get the latest code.
Great, thank you. Any interest in making this something you pass in? That way I can use the standard library from the library manager and as it updates I don't have to make a separate copy and edit it each time.
Definitely. I will push this to a new release.
Sorry, to be more clear. An argument that can be passed in so the source files do not need to be edited. I don't think you can pass in a define.
Ah that way! Yes, I will add that.
Hi Luke. I implemented the dyniamic enable/disable for the debug messages on the fly. There is a new hlelper class called CSE_ModbusRTU_Debug
and its functions enableDebugMessages()
and disableDebugMessages()
to enable and disable the messages. You can use it in your main code as,
CSE_ModbusRTU_Debug:: enableDebugMessages();
CSE_ModbusRTU_Debug:: disableDebugMessages();
Awesome, do you have an example of how to use this? It does not appear to take a reference or pointer of the CSE_ModbusRTU class object.
You don't have to use an object. Simply call the function exactly as shown in the previous reply. You can place it anywhere in your main code.
If you want an example, check out the server test example in the test
folder.
Is there a way to turn off the debug data that is dumped to the USB serial port on every request?
Also wanted to let you know this project is absolutely awesome along with the documentation over at circuitstate. I was pulling my hair out trying to get the ArduinoModbus working on ESP boards (M5Stack) and this works. The latest fix for the holding register size got me fully up and running.