File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -249,6 +249,16 @@ The *modbus_strerror()* function is provided to translate libmodbus-specific
249249error codes into error message strings; for details refer to
250250[ modbus_strerror] ( modbus_strerror.md ) .
251251
252+ ## Extended debug
253+
254+ By default, the debug output created by enabling [ modbus_set_debug] ( modbus_set_debug.md )
255+ is written to stdout/stderr. With the following functions those can be redirected
256+ to files or a callback.
257+
258+ - [ modbus_set_out_user_data] ( modbus_set_out_user_data.md )
259+ - [ modbus_set_error_user_data] ( modbus_set_error_user_data.md )
260+ - [ modbus_set_trace_handler] ( modbus_set_trace_handler.md )
261+
252262## Miscellaneous
253263
254264To deviate from the Modbus standard, you can enable or disable quirks with:
Original file line number Diff line number Diff line change 1+ # modbus_set_error_user_data
2+
3+ ## Name
4+
5+ modbus_set_error_user_data - set file stream to write log output
6+
7+ ## Synopsis
8+
9+ ``` c
10+ void modbus_set_error_user_data (modbus_t * ctx, void* out_user_data);
11+ ```
12+
13+ ## Description
14+
15+ The *modbus_set_error_user_data()* changes where log output is written
16+ to when enabled with [modbus_set_debug](modbus_set_debug.md). Defaults
17+ to stderr when not set.
18+
19+
20+ ## Example
21+
22+ ```c
23+ FILE *fp;
24+ fp = fopen("error.txt", "w");
25+ modbus_set_error_user_data(ctx, fp);
26+ modbus_set_debug(ctx, 1)
27+ ```
28+
29+ ## See also
30+
31+ - [ modbus_set_out_user_data] ( modbus_set_out_user_data.md )
32+ - [ modbus_set_trace_handler] ( modbus_set_trace_handler.md )
Original file line number Diff line number Diff line change 1+ # modbus_set_out_user_data
2+
3+ ## Name
4+
5+ modbus_set_out_user_data - set file stream to write log output
6+
7+ ## Synopsis
8+
9+ ``` c
10+ void modbus_set_out_user_data (modbus_t * ctx, void* out_user_data);
11+ ```
12+
13+ ## Description
14+
15+ The *modbus_set_out_user_data()* changes where log output is written
16+ to when enabled with [modbus_set_debug](modbus_set_debug.md). Defaults
17+ to stdout when not set.
18+
19+
20+ ## Example
21+
22+ ```c
23+ FILE *fp;
24+ fp = fopen("output.txt", "w");
25+ modbus_set_out_user_data(ctx, fp);
26+ modbus_set_debug(ctx, 1)
27+ ```
28+
29+ ## See also
30+
31+ - [ modbus_set_error_user_data] ( modbus_set_error_user_data.md )
32+ - [ modbus_set_trace_handler] ( modbus_set_trace_handler.md )
Original file line number Diff line number Diff line change 1+ # modbus_set_trace_handler
2+
3+ ## Name
4+
5+ modbus_set_trace_handler - call method when log data is written
6+
7+ ## Synopsis
8+
9+ ``` c
10+ typedef int (* modbus_stream_handler_t)(void * user, const char * format, va_list ap);
11+ void modbus_set_trace_handler(modbus_t * ctx, modbus_stream_handler_t handler);
12+ ```
13+
14+ ## Description
15+
16+ The *modbus_set_trace_handler()* sets a callback. When log data is written, the
17+ callback is called. A log message is finalized with a '\n' as last character.
18+ Defaults to vfprintf when not set.
19+
20+
21+ ## Example
22+
23+ ```c++
24+ class Test {
25+ public:
26+ static int log_callback(void *user, const char *format, va_list ap)
27+ {
28+ auto *inst = reinterpret_cast<Test*>(user);
29+ //call methods
30+ }
31+ void setup()
32+ {
33+ modbus_set_out_user_data(reinterpret_cast<void*>(this));
34+ modbus_set_error_user_data(reinterpret_cast<void*>(this));
35+ modbus_set_trace_handler(log_callback);
36+ modbus_set_debug(true);
37+ }
38+ }
39+ ```
40+
41+ ## See also
42+
43+ - [ modbus_set_out_user_data] ( modbus_set_out_user_data.md )
44+ - [ modbus_set_error_user_data] ( modbus_set_error_user_data.md )
You can’t perform that action at this time.
0 commit comments