--- a/modbus/mb_runtime.c Mon Dec 21 21:15:47 2020 +0000
+++ b/modbus/mb_runtime.c Mon Dec 21 22:26:36 2020 +0000
@@ -400,11 +400,12 @@
- /* Set the flag_exec_status that is mapped onto a located WORD variable, so the user program
+ /* Set the flag_tn_error_code and flag_mb_error_code that are mapped onto + * located BYTE variables, so the user program * knows how the communication is going.
- * This flag is an ammalgamation of the data in mb_error_code and tn_error_code
- client_requests[req].flag_exec_status = client_requests[req].tn_error_code * 256 + client_requests[req].mb_error_code;
+ client_requests[req].flag_mb_error_code = client_requests[req].mb_error_code; + client_requests[req].flag_tn_error_code = client_requests[req].tn_error_code; /* We have just finished excuting a client transcation request.
* If the current cycle was activated by user request we reset the flag used to ask to run it
--- a/modbus/mb_runtime.h Mon Dec 21 21:15:47 2020 +0000
+++ b/modbus/mb_runtime.h Mon Dec 21 22:26:36 2020 +0000
@@ -171,20 +171,30 @@
* -> will be reset once the MB transaction has completed
- /* flag that will be mapped onto a (WORD) located variable
- * (u16 because the flag is a word! )
- * -> MSByte will store the result of the last executed MB transaction
+ /* flag that will be mapped onto a (BYTE) located variable + * (u8 because the flag is a BYTE! ) + * -> 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
- * -> if the MSByte is 4, the LSByte will store the MB error code returned by the server
* -> will be reset (set to 0) once this MB transaction has completed sucesfully
- * In other words, this variable will be set from the current status of the
- * mb_error_code and tn_error_code flags after each request.
+ * In other words, this variable is a copy of tn_error_code, reset after each request attempt completes. + * We map this copy (instead of tn_error_code) onto a located variable in case the user program decides + * to overwrite its value and mess up the plugin logic.
+ /* flag that will be mapped onto a (BYTE) located variable + * (u8 because the flag is a BYTE! ) + * -> if flag_tn_error_code 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 + * In other words, this variable is a copy of mb_error_code, reset after each request attempt completes. + * We map this copy (instead of mb_error_code) onto a located variable in case the user program decides + * to overwrite its value and mess up the plugin logic. --- a/modbus/modbus.py Mon Dec 21 21:15:47 2020 +0000
+++ b/modbus/modbus.py Mon Dec 21 22:26:36 2020 +0000
@@ -141,14 +141,23 @@
"description": "Modbus request execution control flag",
- "name": "Request Status flag",
+ "name": "Modbus Request Status flag", "type": LOCATION_VAR_MEMORY,
- "size": 16, # WORD flag
- "IEC_type": "WORD", # WORD flag
+ "IEC_type": "BYTE", # BYTE flag - "location": "W" + ".".join([str(i) for i in current_location]) + ".0.1",
+ "location": "B" + ".".join([str(i) for i in current_location]) + ".0.1", "description": "Modbus request status flag",
+ "name": "Modbus Error Code", + "type": LOCATION_VAR_MEMORY, + "IEC_type": "BYTE", # BYTE flag + "var_name": "var_name", + "location": "B" + ".".join([str(i) for i in current_location]) + ".0.2", + "description": "Modbus Error Code received in Modbus error frame", for offset in range(address, address + count):
"name": dataname + " " + str(offset),
@@ -905,9 +914,13 @@
if iecvar["LOC"][4] == 0:
loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_req;" % (client_requestid))
loc_vars_list.append(str(iecvar["NAME"]))
- # Add if it is a Communication Status Flag (mapped onto %QWa.b.c.0.1), so last number is a '1'
+ # Add if it is a "Modbus Request Status flag" (mapped onto %QWa.b.c.0.1), so last number is a '1' if iecvar["LOC"][4] == 1:
- loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_status;" % (client_requestid))
+ 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 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"]))
tcpclient_node_count += 1
@@ -955,9 +968,13 @@
if iecvar["LOC"][4] == 0:
loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_req;" % (client_requestid))
loc_vars_list.append(str(iecvar["NAME"]))
- # Add if it is a Communication Status Flag (mapped onto %QWa.b.c.0.1), so last number is a '1'
+ # Add if it is a "Modbus Request Status flag" (mapped onto %QWa.b.c.0.1), so last number is a '1' if iecvar["LOC"][4] == 1:
- loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_status;" % (client_requestid))
+ 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 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"]))
rtuclient_node_count += 1