--- a/mb_rtu.c Mon Jun 07 11:21:26 2021 +0200
+++ b/mb_rtu.c Wed Oct 05 19:40:55 2022 +0100
@@ -43,7 +43,8 @@
#define ERRMSG_HEAD "ModbusRTU: "
-// #define DEBUG /* uncomment to see the data sent and received */
+/* help in DEBUGing read80holdreg bug... */ +#define DEBUG /* uncomment to see the data sent and received */ @@ -1303,6 +1304,11 @@
#define SFF_HIST_NO_RESPONSE_FRAME 0x02
#define SFF_HIST_NO_FRAME (SFF_HIST_NO_RESPONSE_FRAME + SFF_HIST_NO_QUERY_FRAME)
+ /* help in DEBUGing read80holdreg bug... */ + fprintf(stderr, "mb_rtu::search_for_frame() called\n"); + fprintf(stderr, "mb_rtu::search_for_frame() frame_data_ptr=%p frame_data_length=%d\n", frame_data, frame_data_length); if ((*search_history == SFF_HIST_NO_FRAME) ||
(frame_data_length < MIN_FRAME_LENGTH) ||
(frame_data_length > MAX_RTU_FRAME_LENGTH))
@@ -1534,6 +1540,10 @@
+ /* help in DEBUGing read80holdreg bug... */ + fprintf(stderr, "mb_rtu::read_frame() called\n"); + fprintf(stderr, "mb_rtu::read_frame() data_count in recv_buf=%d\n", lb_data_count(&recv_buf->data_buf)); /*===================================*
* Delete any previously received data that has already been returned as a valid frame in *
*===================================*/
@@ -1554,6 +1564,7 @@
frame_length = search_for_frame(lb_data(&recv_buf->data_buf),
lb_data_count(&recv_buf->data_buf),
&recv_buf->frame_search_history);
+ fprintf(stderr, "mb_rtu::search_for_frame(1) returned %d\n", frame_length); /* We found a valid frame! */
return return_frame(recv_buf, frame_length, recv_data_ptr);
@@ -1613,6 +1624,7 @@
{/* display the hex code of each character received */
+ fprintf(stderr, "-%p--", lb_free(&recv_buf->data_buf)); for (i=0; i < read_stat; i++)
fprintf(stderr, "<0x%2X>", *(lb_free(&recv_buf->data_buf) + i));
@@ -1626,6 +1638,7 @@
frame_length = search_for_frame(lb_data(&recv_buf->data_buf),
lb_data_count(&recv_buf->data_buf),
&recv_buf->frame_search_history);
+ fprintf(stderr, "mb_rtu::search_for_frame(2) returned %d\n", frame_length); /* We found a valid frame! */
return return_frame(recv_buf, frame_length, recv_data_ptr);
@@ -1698,7 +1711,7 @@
/* We have found a valid frame. Let's get out of here! */
return return_frame(recv_buf, frame_length, recv_data_ptr);
/* We have detected a frame boundary, but the frame we read