145 "type": LOCATION_VAR_MEMORY, |
145 "type": LOCATION_VAR_MEMORY, |
146 "size": 8, # BYTE flag |
146 "size": 8, # BYTE flag |
147 "IEC_type": "BYTE", # BYTE flag |
147 "IEC_type": "BYTE", # BYTE flag |
148 "var_name": "var_name", |
148 "var_name": "var_name", |
149 "location": "B" + ".".join([str(i) for i in current_location]) + ".0.1", |
149 "location": "B" + ".".join([str(i) for i in current_location]) + ".0.1", |
150 "description": "Modbus request status flag", |
150 "description": "Modbus request status flag (0 -> OK, 1 -> Network error, 2 -> Received invalid frame, 3 -> Timeout, 4 -> Received error frame)", |
151 "children": []}) |
151 "children": []}) |
152 entries.append({ |
152 entries.append({ |
153 "name": "Modbus Error Code", |
153 "name": "Modbus Error Code", |
154 "type": LOCATION_VAR_MEMORY, |
154 "type": LOCATION_VAR_MEMORY, |
155 "size": 8, # BYTE flag |
155 "size": 8, # BYTE flag |
889 # absloute address - start address |
890 # absloute address - start address |
890 relative_addr = iecvar["LOC"][3] - int(GetCTVal(subchild, 3)) |
891 relative_addr = iecvar["LOC"][3] - int(GetCTVal(subchild, 3)) |
891 # test if the located variable |
892 # test if the located variable |
892 # (a) has relative address in request specified range |
893 # (a) has relative address in request specified range |
893 # AND is NOT |
894 # AND is NOT |
894 # (b) is a control flag added by this modbus plugin |
895 # (b) is a flag added by this modbus plugin. |
895 # to control its execution at runtime. |
896 # We currently add 3 flags: An execution control flag |
896 # Currently, we only add the "Execution Control Flag" |
897 # and another two status flags. |
897 # to each client request (one flag per request) |
898 # We add the "Execution Control Flag" to each client request (one flag per request) |
898 # to control when to execute the request (if not executed periodically) |
899 # to allow the user program to control when to execute the request (if not executed periodically) |
899 # While all Modbus registers/coils are mapped onto a location |
900 # While all Modbus registers/coils are mapped onto a location |
900 # with 4 numbers (e.g. %QX0.1.2.55), this control flag is mapped |
901 # with 4 numbers (e.g. %QX0.1.2.55), this control flag is mapped |
901 # onto a location with 4 numbers (e.g. %QX0.1.2.0.0), where the last |
902 # onto a location with 4 numbers (e.g. %QX0.1.2.0.0), where the last |
902 # two numbers are always '0.0', and the first two identify the request. |
903 # two numbers are always '0.0', and the first two identify the request. |
903 # In the following if, we check for this condition by checking |
904 # In the following if, we check for this condition by checking |
904 # if their are at least 4 or more number in the location's address. |
905 # if there are at least 4 or more number in the location's address. |
905 if ( relative_addr in xrange(int(GetCTVal(subchild, 2))) # condition (a) explained above |
906 if ( relative_addr in xrange(int(GetCTVal(subchild, 2))) # condition (a) explained above |
906 and len(iecvar["LOC"]) < 5): # condition (b) explained above |
907 and len(iecvar["LOC"]) < 5): # condition (b) explained above |
907 if str(iecvar["NAME"]) not in loc_vars_list: |
908 if str(iecvar["NAME"]) not in loc_vars_list: |
908 loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].plcv_buffer[%d];" % (client_requestid, relative_addr)) |
909 loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].plcv_buffer[%d];" % (client_requestid, relative_addr)) |
909 loc_vars_list.append(str(iecvar["NAME"])) |
910 loc_vars_list.append(str(iecvar["NAME"])) |
913 # Add if it is a Execution Request Flag (mapped onto %QXa.b.c.0.0), so last number is a '0' |
914 # Add if it is a Execution Request Flag (mapped onto %QXa.b.c.0.0), so last number is a '0' |
914 if iecvar["LOC"][4] == 0: |
915 if iecvar["LOC"][4] == 0: |
915 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_req;" % (client_requestid)) |
916 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_req;" % (client_requestid)) |
916 loc_vars_list.append(str(iecvar["NAME"])) |
917 loc_vars_list.append(str(iecvar["NAME"])) |
917 # Add if it is a "Modbus Request Status flag" (mapped onto %QWa.b.c.0.1), so last number is a '1' |
918 # Add if it is a "Modbus Request Status flag" (mapped onto %QWa.b.c.0.1), so last number is a '1' |
|
919 # -> will store the result of the last executed MB transaction |
|
920 # 1 -> error accessing IP network, or serial interface |
|
921 # 2 -> reply received from server was an invalid frame |
|
922 # 3 -> server did not reply before timeout expired |
|
923 # 4 -> server returned a valid Modbus error frame |
|
924 # -> will be reset (set to 0) once this MB transaction has completed sucesfully |
918 if iecvar["LOC"][4] == 1: |
925 if iecvar["LOC"][4] == 1: |
919 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_tn_error_code;" % (client_requestid)) |
926 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_tn_error_code;" % (client_requestid)) |
920 loc_vars_list.append(str(iecvar["NAME"])) |
927 loc_vars_list.append(str(iecvar["NAME"])) |
921 # Add if it is a "Modbus Error code" (mapped onto %QWa.b.c.0.2), so last number is a '2' |
928 # Add if it is a "Modbus Error code" (mapped onto %QWa.b.c.0.2), so last number is a '2' |
|
929 # -> 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 |
|
930 # -> will be reset (set to 0) once this MB transaction has completed succesfully |
922 if iecvar["LOC"][4] == 2: |
931 if iecvar["LOC"][4] == 2: |
923 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_mb_error_code;" % (client_requestid)) |
932 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_mb_error_code;" % (client_requestid)) |
924 loc_vars_list.append(str(iecvar["NAME"])) |
933 loc_vars_list.append(str(iecvar["NAME"])) |
925 client_requestid += 1 |
934 client_requestid += 1 |
926 tcpclient_node_count += 1 |
935 tcpclient_node_count += 1 |
942 # absloute address - start address |
951 # absloute address - start address |
943 relative_addr = iecvar["LOC"][3] - int(GetCTVal(subchild, 3)) |
952 relative_addr = iecvar["LOC"][3] - int(GetCTVal(subchild, 3)) |
944 # test if the located variable |
953 # test if the located variable |
945 # (a) has relative address in request specified range |
954 # (a) has relative address in request specified range |
946 # AND is NOT |
955 # AND is NOT |
947 # (b) is a control flag added by this modbus plugin |
956 # (b) is a flag added by this modbus plugin. |
948 # to control its execution at runtime. |
957 # We currently add 3 flags: An execution control flag |
949 # Currently, we only add the "Execution Control Flag" |
958 # and another two status flags. |
950 # to each client request (one flag per request) |
959 # We add the "Execution Control Flag" to each client request (one flag per request) |
951 # to control when to execute the request (if not executed periodically) |
960 # to allow the user program to control when to execute the request (if not executed periodically) |
952 # While all Modbus registers/coils are mapped onto a location |
961 # While all Modbus registers/coils are mapped onto a location |
953 # with 4 numbers (e.g. %QX0.1.2.55), this control flag is mapped |
962 # with 4 numbers (e.g. %QX0.1.2.55), this control flag is mapped |
954 # onto a location with 4 numbers (e.g. %QX0.1.2.0.0), where the last |
963 # onto a location with 4 numbers (e.g. %QX0.1.2.0.0), where the last |
955 # two numbers are always '0.0', and the first two identify the request. |
964 # two numbers are always '0.0', and the first two identify the request. |
956 # In the following if, we check for this condition by checking |
965 # In the following if, we check for this condition by checking |
967 # Add if it is a Execution Request Flag (mapped onto %QXa.b.c.0.0), so last number is a '0' |
976 # Add if it is a Execution Request Flag (mapped onto %QXa.b.c.0.0), so last number is a '0' |
968 if iecvar["LOC"][4] == 0: |
977 if iecvar["LOC"][4] == 0: |
969 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_req;" % (client_requestid)) |
978 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_req;" % (client_requestid)) |
970 loc_vars_list.append(str(iecvar["NAME"])) |
979 loc_vars_list.append(str(iecvar["NAME"])) |
971 # Add if it is a "Modbus Request Status flag" (mapped onto %QWa.b.c.0.1), so last number is a '1' |
980 # Add if it is a "Modbus Request Status flag" (mapped onto %QWa.b.c.0.1), so last number is a '1' |
|
981 # -> will store the result of the last executed MB transaction |
|
982 # 1 -> error accessing IP network, or serial interface |
|
983 # 2 -> reply received from server was an invalid frame |
|
984 # 3 -> server did not reply before timeout expired |
|
985 # 4 -> server returned a valid Modbus error frame |
|
986 # -> will be reset (set to 0) once this MB transaction has completed sucesfully |
972 if iecvar["LOC"][4] == 1: |
987 if iecvar["LOC"][4] == 1: |
973 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_tn_error_code;" % (client_requestid)) |
988 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_tn_error_code;" % (client_requestid)) |
974 loc_vars_list.append(str(iecvar["NAME"])) |
989 loc_vars_list.append(str(iecvar["NAME"])) |
975 # Add if it is a "Modbus Error code" (mapped onto %QWa.b.c.0.2), so last number is a '2' |
990 # Add if it is a "Modbus Error code" (mapped onto %QWa.b.c.0.2), so last number is a '2' |
|
991 # -> 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 |
|
992 # -> will be reset (set to 0) once this MB transaction has completed succesfully |
976 if iecvar["LOC"][4] == 2: |
993 if iecvar["LOC"][4] == 2: |
977 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_mb_error_code;" % (client_requestid)) |
994 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_mb_error_code;" % (client_requestid)) |
978 loc_vars_list.append(str(iecvar["NAME"])) |
995 loc_vars_list.append(str(iecvar["NAME"])) |
979 client_requestid += 1 |
996 client_requestid += 1 |
980 rtuclient_node_count += 1 |
997 rtuclient_node_count += 1 |