merge
authorMario de Sousa <msousa@fe.up.pt>
Fri, 25 Dec 2020 17:12:02 +0000
changeset 2718 76e8ec46828a
parent 2716 ebb2595504f0 (current diff)
parent 2717 b3b6991f1cb6 (diff)
child 2719 745b64e7c695
child 2723 cde2e410b874
merge
modbus/modbus.py
--- a/modbus/modbus.py	Mon Dec 21 22:35:07 2020 +0000
+++ b/modbus/modbus.py	Fri Dec 25 17:12:02 2020 +0000
@@ -147,7 +147,7 @@
             "IEC_type": "BYTE",  # BYTE flag
             "var_name": "var_name",
             "location": "B" + ".".join([str(i) for i in current_location]) + ".0.1",
-            "description": "Modbus request status flag",
+            "description": "Modbus request status flag (0 -> OK, 1 -> Network error, 2 -> Received invalid frame, 3 -> Timeout, 4 -> Received error frame)",
             "children": []})        
         entries.append({
             "name": "Modbus Error Code",
@@ -189,6 +189,7 @@
         return [], "", False
 
 
+
 #
 #
 #
@@ -891,17 +892,17 @@
                         # test if the located variable 
                         #    (a) has relative address in request specified range
                         #  AND is NOT
-                        #    (b) is a control flag added by this modbus plugin
-                        #        to control its execution at runtime.
-                        #        Currently, we only add the "Execution Control Flag"
-                        #        to each client request (one flag per request)
-                        #        to control when to execute the request (if not executed periodically)
+                        #    (b) is a flag added by this modbus plugin.
+                        #        We currently add 3 flags: An execution control flag
+                        #        and another two status flags.
+                        #        We add the "Execution Control Flag" to each client request (one flag per request)
+                        #        to allow the user program to control when to execute the request (if not executed periodically)
                         #        While all Modbus registers/coils are mapped onto a location
                         #        with 4 numbers (e.g. %QX0.1.2.55), this control flag is mapped
                         #        onto a location with 4 numbers (e.g. %QX0.1.2.0.0), where the last
                         #        two numbers are always '0.0', and the first two identify the request.
                         #        In the following if, we check for this condition by checking
-                        #        if their are at least 4 or more number in the location's address.
+                        #        if there are at least 4 or more number in the location's address.
                         if (        relative_addr in xrange(int(GetCTVal(subchild, 2)))  # condition (a) explained above
                             and len(iecvar["LOC"]) < 5):                                  # condition (b) explained above
                             if str(iecvar["NAME"]) not in loc_vars_list:
@@ -915,10 +916,18 @@
                                     loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_req;" % (client_requestid))
                                     loc_vars_list.append(str(iecvar["NAME"]))
                                 # Add if it is a "Modbus Request Status flag" (mapped onto %QWa.b.c.0.1), so last number is a '1'
+                                #    -> will store the result of the last executed MB transaction
+                                #         1 -> error accessing IP network, or serial interface
+                                #         2 -> reply received from server was an invalid frame
+                                #         3 -> server did not reply before timeout expired
+                                #         4 -> server returned a valid Modbus error frame
+                                #    -> will be reset (set to 0) once this MB transaction has completed sucesfully 
                                 if iecvar["LOC"][4] == 1:
                                     loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_tn_error_code;" % (client_requestid))
                                     loc_vars_list.append(str(iecvar["NAME"]))
                                 # Add if it is a "Modbus Error code" (mapped onto %QWa.b.c.0.2), so last number is a '2'
+                                #    -> if "Modbus Request Status flag" is 4, this flag will store the MB error code returned by the MB server in a MB error frame
+                                #    -> will be reset (set to 0) once this MB transaction has completed succesfully                                
                                 if iecvar["LOC"][4] == 2:
                                     loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_mb_error_code;" % (client_requestid))
                                     loc_vars_list.append(str(iecvar["NAME"]))
@@ -944,11 +953,11 @@
                         # test if the located variable 
                         #    (a) has relative address in request specified range
                         #  AND is NOT
-                        #    (b) is a control flag added by this modbus plugin
-                        #        to control its execution at runtime.
-                        #        Currently, we only add the "Execution Control Flag"
-                        #        to each client request (one flag per request)
-                        #        to control when to execute the request (if not executed periodically)
+                        #    (b) is a flag added by this modbus plugin.
+                        #        We currently add 3 flags: An execution control flag
+                        #        and another two status flags.
+                        #        We add the "Execution Control Flag" to each client request (one flag per request)
+                        #        to allow the user program to control when to execute the request (if not executed periodically)
                         #        While all Modbus registers/coils are mapped onto a location
                         #        with 4 numbers (e.g. %QX0.1.2.55), this control flag is mapped
                         #        onto a location with 4 numbers (e.g. %QX0.1.2.0.0), where the last
@@ -969,10 +978,18 @@
                                     loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_req;" % (client_requestid))
                                     loc_vars_list.append(str(iecvar["NAME"]))
                                 # Add if it is a "Modbus Request Status flag" (mapped onto %QWa.b.c.0.1), so last number is a '1'
+                                #    -> will store the result of the last executed MB transaction
+                                #         1 -> error accessing IP network, or serial interface
+                                #         2 -> reply received from server was an invalid frame
+                                #         3 -> server did not reply before timeout expired
+                                #         4 -> server returned a valid Modbus error frame
+                                #    -> will be reset (set to 0) once this MB transaction has completed sucesfully 
                                 if iecvar["LOC"][4] == 1:
                                     loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_tn_error_code;" % (client_requestid))
                                     loc_vars_list.append(str(iecvar["NAME"]))
                                 # Add if it is a "Modbus Error code" (mapped onto %QWa.b.c.0.2), so last number is a '2'
+                                #    -> if "Modbus Request Status flag" is 4, this flag will store the MB error code returned by the MB server in a MB error frame
+                                #    -> will be reset (set to 0) once this MB transaction has completed succesfully                                
                                 if iecvar["LOC"][4] == 2:
                                     loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_mb_error_code;" % (client_requestid))
                                     loc_vars_list.append(str(iecvar["NAME"]))