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", |
|
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, |
885 # In the following if, we check for this condition by checking |
903 # 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. |
904 # if their 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 |
905 if ( relative_addr in xrange(int(GetCTVal(subchild, 2))) # condition (a) explained above |
888 and len(iecvar["LOC"]) < 5): # condition (b) explained above |
906 and len(iecvar["LOC"]) < 5): # condition (b) explained above |
889 if str(iecvar["NAME"]) not in loc_vars_list: |
907 if str(iecvar["NAME"]) not in loc_vars_list: |
890 loc_vars.append( |
908 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"])) |
909 loc_vars_list.append(str(iecvar["NAME"])) |
893 # Now add the located variable in case it is a flag (condition (b) above |
910 # Now add the located variable in case it is a flag (condition (b) above |
894 if len(iecvar["LOC"]) >= 5: # condition (b) explained above |
911 if len(iecvar["LOC"]) >= 5: # condition (b) explained above |
895 if str(iecvar["NAME"]) not in loc_vars_list: |
912 if str(iecvar["NAME"]) not in loc_vars_list: |
896 loc_vars.append( |
913 # 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)) |
914 if iecvar["LOC"][4] == 0: |
898 loc_vars_list.append(str(iecvar["NAME"])) |
915 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_req;" % (client_requestid)) |
|
916 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 if iecvar["LOC"][4] == 1: |
|
919 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_tn_error_code;" % (client_requestid)) |
|
920 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' |
|
922 if iecvar["LOC"][4] == 2: |
|
923 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_mb_error_code;" % (client_requestid)) |
|
924 loc_vars_list.append(str(iecvar["NAME"])) |
899 client_requestid += 1 |
925 client_requestid += 1 |
900 tcpclient_node_count += 1 |
926 tcpclient_node_count += 1 |
901 client_nodeid += 1 |
927 client_nodeid += 1 |
902 # |
928 # |
903 if child.PlugType == "ModbusRTUclient": |
929 if child.PlugType == "ModbusRTUclient": |
926 # While all Modbus registers/coils are mapped onto a location |
952 # 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 |
953 # 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 |
954 # 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. |
955 # 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 |
956 # 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. |
957 # 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 |
958 if ( relative_addr in xrange(int(GetCTVal(subchild, 2))) # condition (a) explained above |
933 and len(iecvar["LOC"]) < 5): # condition (b) explained above |
959 and len(iecvar["LOC"]) < 5): # condition (b) explained above |
934 if str(iecvar["NAME"]) not in loc_vars_list: |
960 if str(iecvar["NAME"]) not in loc_vars_list: |
935 loc_vars.append( |
961 loc_vars.append( |
936 "u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].plcv_buffer[%d];" % (client_requestid, relative_addr)) |
962 "u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].plcv_buffer[%d];" % (client_requestid, relative_addr)) |
937 loc_vars_list.append(str(iecvar["NAME"])) |
963 loc_vars_list.append(str(iecvar["NAME"])) |
938 # Now add the located variable in case it is a flag (condition (b) above |
964 # Now add the located variable in case it is a flag (condition (b) above |
939 if len(iecvar["LOC"]) >= 5: # condition (b) explained above |
965 if len(iecvar["LOC"]) >= 5: # condition (b) explained above |
940 if str(iecvar["NAME"]) not in loc_vars_list: |
966 if str(iecvar["NAME"]) not in loc_vars_list: |
941 loc_vars.append( |
967 # 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)) |
968 if iecvar["LOC"][4] == 0: |
943 loc_vars_list.append(str(iecvar["NAME"])) |
969 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_req;" % (client_requestid)) |
|
970 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' |
|
972 if iecvar["LOC"][4] == 1: |
|
973 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_tn_error_code;" % (client_requestid)) |
|
974 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' |
|
976 if iecvar["LOC"][4] == 2: |
|
977 loc_vars.append("u8 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_mb_error_code;" % (client_requestid)) |
|
978 loc_vars_list.append(str(iecvar["NAME"])) |
944 client_requestid += 1 |
979 client_requestid += 1 |
945 rtuclient_node_count += 1 |
980 rtuclient_node_count += 1 |
946 client_nodeid += 1 |
981 client_nodeid += 1 |
947 nodeid += 1 |
982 nodeid += 1 |
948 |
983 |