modbus/mb_runtime.h
changeset 2723 cde2e410b874
parent 2716 ebb2595504f0
parent 2722 5d72a52b8f9c
child 3733 d1acf20e8e7c
--- a/modbus/mb_runtime.h	Fri Dec 25 17:12:02 2020 +0000
+++ b/modbus/mb_runtime.h	Thu Jan 28 14:51:16 2021 +0000
@@ -41,6 +41,25 @@
 	    u16		rw_bits [MEM_AREA_SIZE];
 	    u16		ro_words[MEM_AREA_SIZE];
 	    u16		rw_words[MEM_AREA_SIZE];
+            /* Two flags to count the number of Modbus requests (read and write) we have 
+             * successfully received from any remote Modbus master.
+             * Two boolean flags that are set whenever we successfully process a
+             * Modbus request sent from a remote client.
+             * These flags will be mapped onto located variables
+             * so the user's IEC 61131-3 code can check whether we are being
+             * polled by a Modbus master.
+             * The counters will roll over to 0 upon reaching maximum value.
+             * The user will probably periodically reset the boolean flags to false,
+             * and use this as a communication timeout 
+             * (when it remains false in two consecutive periods)
+             * 
+             * u8  for BOOL  variable/flag
+             * u32 for UDINT variable/counter
+             */
+        u8   flag_write_req_flag;
+        u8   flag_read_req_flag;
+        u32  flag_write_req_counter;
+        u32  flag_read_req_counter;
 	} server_mem_t;
 
 
@@ -89,6 +108,8 @@
 	    node_addr_t	node_address;
 	    int		mb_nd;      // modbus library node used for this server 
 	    int		init_state; // store how far along the server's initialization has progressed
+            /* entries from this point forward are not statically initialized when the variable is declared */
+            /* they will be initialized by the  code itself in the init() function */
 	    pthread_t	thread_id;  // thread handling this server
 	    server_mem_t	mem_area;
 	} server_node_t;