130 # %QX1.2.3.2 |
130 # %QX1.2.3.2 |
131 # .. |
131 # .. |
132 # %QX1.2.3.n |
132 # %QX1.2.3.n |
133 entries = [] |
133 entries = [] |
134 entries.append({ |
134 entries.append({ |
135 "name": "Exec. request flag", |
135 "name": "Execute request flag", |
136 "type": LOCATION_VAR_MEMORY, |
136 "type": LOCATION_VAR_MEMORY, |
137 "size": 1, # BOOL flag |
137 "size": 1, # BOOL flag |
138 "IEC_type": "BOOL", # BOOL flag |
138 "IEC_type": "BOOL", # BOOL flag |
139 "var_name": "var_name", |
139 "var_name": "var_name", |
140 "location": "X" + ".".join([str(i) for i in current_location]) + ".0.0", |
140 "location": "X" + ".".join([str(i) for i in current_location]) + ".0.0", |
141 "description": "MB request execution control flag", |
141 "description": "Modbus request execution control flag", |
|
142 "children": []}) |
|
143 entries.append({ |
|
144 "name": "Modbus Request Status flag", |
|
145 "type": LOCATION_VAR_MEMORY, |
|
146 "size": 8, # BYTE flag |
|
147 "IEC_type": "BYTE", # BYTE flag |
|
148 "var_name": "var_name", |
|
149 "location": "B" + ".".join([str(i) for i in current_location]) + ".0.1", |
|
150 "description": "Modbus request status flag (0 -> OK, 1 -> Network error, 2 -> Received invalid frame, 3 -> Timeout, 4 -> Received error frame)", |
|
151 "children": []}) |
|
152 entries.append({ |
|
153 "name": "Modbus Error Code", |
|
154 "type": LOCATION_VAR_MEMORY, |
|
155 "size": 8, # BYTE flag |
|
156 "IEC_type": "BYTE", # BYTE flag |
|
157 "var_name": "var_name", |
|
158 "location": "B" + ".".join([str(i) for i in current_location]) + ".0.2", |
|
159 "description": "Modbus Error Code received in Modbus error frame", |
142 "children": []}) |
160 "children": []}) |
143 for offset in range(address, address + count): |
161 for offset in range(address, address + count): |
144 entries.append({ |
162 entries.append({ |
145 "name": dataname + " " + str(offset), |
163 "name": dataname + " " + str(offset), |
146 "type": LOCATION_VAR_MEMORY, |
164 "type": LOCATION_VAR_MEMORY, |
871 # absloute address - start address |
890 # absloute address - start address |
872 relative_addr = iecvar["LOC"][3] - int(GetCTVal(subchild, 3)) |
891 relative_addr = iecvar["LOC"][3] - int(GetCTVal(subchild, 3)) |
873 # test if the located variable |
892 # test if the located variable |
874 # (a) has relative address in request specified range |
893 # (a) has relative address in request specified range |
875 # AND is NOT |
894 # AND is NOT |
876 # (b) is a control flag added by this modbus plugin |
895 # (b) is a flag added by this modbus plugin. |
877 # to control its execution at runtime. |
896 # We currently add 3 flags: An execution control flag |
878 # Currently, we only add the "Execution Control Flag" |
897 # and another two status flags. |
879 # to each client request (one flag per request) |
898 # We add the "Execution Control Flag" to each client request (one flag per request) |
880 # 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) |
881 # While all Modbus registers/coils are mapped onto a location |
900 # While all Modbus registers/coils are mapped onto a location |
882 # 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 |
883 # 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 |
884 # 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. |
885 # In the following if, we check for this condition by checking |
904 # In the following if, we check for this condition by checking |
886 # 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. |
887 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 |
888 and len(iecvar["LOC"]) < 5): # condition (b) explained above |
907 and len(iecvar["LOC"]) < 5): # condition (b) explained above |
889 if str(iecvar["NAME"]) not in loc_vars_list: |
908 if str(iecvar["NAME"]) not in loc_vars_list: |
890 loc_vars.append( |
909 loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].plcv_buffer[%d];" % (client_requestid, relative_addr)) |
891 "u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].plcv_buffer[%d];" % (client_requestid, relative_addr)) |
|
892 loc_vars_list.append(str(iecvar["NAME"])) |
910 loc_vars_list.append(str(iecvar["NAME"])) |
893 # Now add the located variable in case it is a flag (condition (b) above |
911 # Now add the located variable in case it is a flag (condition (b) above |
894 if len(iecvar["LOC"]) >= 5: # condition (b) explained above |
912 if len(iecvar["LOC"]) >= 5: # condition (b) explained above |
895 if str(iecvar["NAME"]) not in loc_vars_list: |
913 if str(iecvar["NAME"]) not in loc_vars_list: |
896 loc_vars.append( |
914 # Add if it is a Execution Request Flag (mapped onto %QXa.b.c.0.0), so last number is a '0' |
897 "u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_req;" % (client_requestid)) |
915 if iecvar["LOC"][4] == 0: |
898 loc_vars_list.append(str(iecvar["NAME"])) |
916 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_req;" % (client_requestid)) |
|
917 loc_vars_list.append(str(iecvar["NAME"])) |
|
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 |
|
925 if iecvar["LOC"][4] == 1: |
|
926 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_tn_error_code;" % (client_requestid)) |
|
927 loc_vars_list.append(str(iecvar["NAME"])) |
|
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 |
|
931 if iecvar["LOC"][4] == 2: |
|
932 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_mb_error_code;" % (client_requestid)) |
|
933 loc_vars_list.append(str(iecvar["NAME"])) |
899 client_requestid += 1 |
934 client_requestid += 1 |
900 tcpclient_node_count += 1 |
935 tcpclient_node_count += 1 |
901 client_nodeid += 1 |
936 client_nodeid += 1 |
902 # |
937 # |
903 if child.PlugType == "ModbusRTUclient": |
938 if child.PlugType == "ModbusRTUclient": |
916 # absloute address - start address |
951 # absloute address - start address |
917 relative_addr = iecvar["LOC"][3] - int(GetCTVal(subchild, 3)) |
952 relative_addr = iecvar["LOC"][3] - int(GetCTVal(subchild, 3)) |
918 # test if the located variable |
953 # test if the located variable |
919 # (a) has relative address in request specified range |
954 # (a) has relative address in request specified range |
920 # AND is NOT |
955 # AND is NOT |
921 # (b) is a control flag added by this modbus plugin |
956 # (b) is a flag added by this modbus plugin. |
922 # to control its execution at runtime. |
957 # We currently add 3 flags: An execution control flag |
923 # Currently, we only add the "Execution Control Flag" |
958 # and another two status flags. |
924 # to each client request (one flag per request) |
959 # We add the "Execution Control Flag" to each client request (one flag per request) |
925 # 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) |
926 # While all Modbus registers/coils are mapped onto a location |
961 # While all Modbus registers/coils are mapped onto a location |
927 # 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 |
928 # 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 |
929 # 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. |
930 # In the following if, we check for this condition by checking |
965 # In the following if, we check for this condition by checking |
931 # if their are at least 4 or more number in the location's address. |
966 # if there are at least 4 or more number in the location's address. |
932 if ( relative_addr in xrange(int(GetCTVal(subchild, 2))) # condition (a) explained above |
967 if ( relative_addr in xrange(int(GetCTVal(subchild, 2))) # condition (a) explained above |
933 and len(iecvar["LOC"]) < 5): # condition (b) explained above |
968 and len(iecvar["LOC"]) < 5): # condition (b) explained above |
934 if str(iecvar["NAME"]) not in loc_vars_list: |
969 if str(iecvar["NAME"]) not in loc_vars_list: |
935 loc_vars.append( |
970 loc_vars.append( |
936 "u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].plcv_buffer[%d];" % (client_requestid, relative_addr)) |
971 "u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].plcv_buffer[%d];" % (client_requestid, relative_addr)) |
937 loc_vars_list.append(str(iecvar["NAME"])) |
972 loc_vars_list.append(str(iecvar["NAME"])) |
938 # Now add the located variable in case it is a flag (condition (b) above |
973 # Now add the located variable in case it is a flag (condition (b) above |
939 if len(iecvar["LOC"]) >= 5: # condition (b) explained above |
974 if len(iecvar["LOC"]) >= 5: # condition (b) explained above |
940 if str(iecvar["NAME"]) not in loc_vars_list: |
975 if str(iecvar["NAME"]) not in loc_vars_list: |
941 loc_vars.append( |
976 # Add if it is a Execution Request Flag (mapped onto %QXa.b.c.0.0), so last number is a '0' |
942 "u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_req;" % (client_requestid)) |
977 if iecvar["LOC"][4] == 0: |
943 loc_vars_list.append(str(iecvar["NAME"])) |
978 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_req;" % (client_requestid)) |
|
979 loc_vars_list.append(str(iecvar["NAME"])) |
|
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 |
|
987 if iecvar["LOC"][4] == 1: |
|
988 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_tn_error_code;" % (client_requestid)) |
|
989 loc_vars_list.append(str(iecvar["NAME"])) |
|
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 |
|
993 if iecvar["LOC"][4] == 2: |
|
994 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_mb_error_code;" % (client_requestid)) |
|
995 loc_vars_list.append(str(iecvar["NAME"])) |
944 client_requestid += 1 |
996 client_requestid += 1 |
945 rtuclient_node_count += 1 |
997 rtuclient_node_count += 1 |
946 client_nodeid += 1 |
998 client_nodeid += 1 |
947 nodeid += 1 |
999 nodeid += 1 |
948 |
1000 |