21 # |
21 # |
22 # This code is made available on the understanding that it will not be |
22 # This code is made available on the understanding that it will not be |
23 # used in safety-critical situations without a full and competent review. |
23 # used in safety-critical situations without a full and competent review. |
24 |
24 |
25 |
25 |
26 from __future__ import absolute_import |
26 |
27 import os |
27 import os |
28 from six.moves import xrange |
28 from six.moves import xrange |
29 |
29 |
30 from modbus.mb_utils import * |
30 from modbus.mb_utils import * |
31 from ConfigTreeNode import ConfigTreeNode |
31 from ConfigTreeNode import ConfigTreeNode |
92 infos = ConfigTreeNode.GetParamsAttributes(self, path=path) |
92 infos = ConfigTreeNode.GetParamsAttributes(self, path=path) |
93 for element in infos: |
93 for element in infos: |
94 if element["name"] == "ModbusRequest": |
94 if element["name"] == "ModbusRequest": |
95 for child in element["children"]: |
95 for child in element["children"]: |
96 if child["name"] == "Function": |
96 if child["name"] == "Function": |
97 list = modbus_function_dict.keys() |
97 list = list(modbus_function_dict.keys()) |
98 list.sort() |
98 list.sort() |
99 child["type"] = list |
99 child["type"] = list |
100 return infos |
100 return infos |
101 |
101 |
102 def GetVariableLocationTree(self): |
102 def GetVariableLocationTree(self): |
238 infos = ConfigTreeNode.GetParamsAttributes(self, path=path) |
238 infos = ConfigTreeNode.GetParamsAttributes(self, path=path) |
239 for element in infos: |
239 for element in infos: |
240 if element["name"] == "MemoryArea": |
240 if element["name"] == "MemoryArea": |
241 for child in element["children"]: |
241 for child in element["children"]: |
242 if child["name"] == "MemoryAreaType": |
242 if child["name"] == "MemoryAreaType": |
243 list = modbus_memtype_dict.keys() |
243 list = list(modbus_memtype_dict.keys()) |
244 list.sort() |
244 list.sort() |
245 child["type"] = list |
245 child["type"] = list |
246 return infos |
246 return infos |
247 |
247 |
248 def GetVariableLocationTree(self): |
248 def GetVariableLocationTree(self): |
616 if child["name"] == "Baud_Rate": |
616 if child["name"] == "Baud_Rate": |
617 child["type"] = modbus_serial_baudrate_list |
617 child["type"] = modbus_serial_baudrate_list |
618 if child["name"] == "Stop_Bits": |
618 if child["name"] == "Stop_Bits": |
619 child["type"] = modbus_serial_stopbits_list |
619 child["type"] = modbus_serial_stopbits_list |
620 if child["name"] == "Parity": |
620 if child["name"] == "Parity": |
621 child["type"] = modbus_serial_parity_dict.keys() |
621 child["type"] = list(modbus_serial_parity_dict.keys()) |
622 return infos |
622 return infos |
623 |
623 |
624 # Return the number of (modbus library) nodes this specific RTU client will need |
624 # Return the number of (modbus library) nodes this specific RTU client will need |
625 # return type: (tcp nodes, rtu nodes, ascii nodes) |
625 # return type: (tcp nodes, rtu nodes, ascii nodes) |
626 def GetNodeCount(self): |
626 def GetNodeCount(self): |
707 if child["name"] == "Baud_Rate": |
707 if child["name"] == "Baud_Rate": |
708 child["type"] = modbus_serial_baudrate_list |
708 child["type"] = modbus_serial_baudrate_list |
709 if child["name"] == "Stop_Bits": |
709 if child["name"] == "Stop_Bits": |
710 child["type"] = modbus_serial_stopbits_list |
710 child["type"] = modbus_serial_stopbits_list |
711 if child["name"] == "Parity": |
711 if child["name"] == "Parity": |
712 child["type"] = modbus_serial_parity_dict.keys() |
712 child["type"] = list(modbus_serial_parity_dict.keys()) |
713 return infos |
713 return infos |
714 |
714 |
715 # Return the number of (modbus library) nodes this specific RTU slave will need |
715 # Return the number of (modbus library) nodes this specific RTU slave will need |
716 # return type: (tcp nodes, rtu nodes, ascii nodes) |
716 # return type: (tcp nodes, rtu nodes, ascii nodes) |
717 def GetNodeCount(self): |
717 def GetNodeCount(self): |
1024 #print "subchild" + repr(iecvar) |
1024 #print "subchild" + repr(iecvar) |
1025 absloute_address = iecvar["LOC"][3] |
1025 absloute_address = iecvar["LOC"][3] |
1026 start_address = int(GetCTVal(subchild, 2)) |
1026 start_address = int(GetCTVal(subchild, 2)) |
1027 relative_addr = absloute_address - start_address |
1027 relative_addr = absloute_address - start_address |
1028 # test if relative address in request specified range |
1028 # test if relative address in request specified range |
1029 if relative_addr in xrange(int(GetCTVal(subchild, 1))): |
1029 if relative_addr in range(int(GetCTVal(subchild, 1))): |
1030 if str(iecvar["NAME"]) not in loc_vars_list: |
1030 if str(iecvar["NAME"]) not in loc_vars_list: |
1031 loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &server_nodes[%d].mem_area.%s[%d];" % ( |
1031 loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &server_nodes[%d].mem_area.%s[%d];" % ( |
1032 server_id, memarea, absloute_address)) |
1032 server_id, memarea, absloute_address)) |
1033 loc_vars_list.append(str(iecvar["NAME"])) |
1033 loc_vars_list.append(str(iecvar["NAME"])) |
1034 server_id += 1 |
1034 server_id += 1 |
1078 # print repr(iecvar) |
1078 # print repr(iecvar) |
1079 absloute_address = iecvar["LOC"][3] |
1079 absloute_address = iecvar["LOC"][3] |
1080 start_address = int(GetCTVal(subchild, 2)) |
1080 start_address = int(GetCTVal(subchild, 2)) |
1081 relative_addr = absloute_address - start_address |
1081 relative_addr = absloute_address - start_address |
1082 # test if relative address in request specified range |
1082 # test if relative address in request specified range |
1083 if relative_addr in xrange(int(GetCTVal(subchild, 1))): |
1083 if relative_addr in range(int(GetCTVal(subchild, 1))): |
1084 if str(iecvar["NAME"]) not in loc_vars_list: |
1084 if str(iecvar["NAME"]) not in loc_vars_list: |
1085 loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &server_nodes[%d].mem_area.%s[%d];" % ( |
1085 loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &server_nodes[%d].mem_area.%s[%d];" % ( |
1086 server_id, memarea, absloute_address)) |
1086 server_id, memarea, absloute_address)) |
1087 loc_vars_list.append(str(iecvar["NAME"])) |
1087 loc_vars_list.append(str(iecvar["NAME"])) |
1088 server_id += 1 |
1088 server_id += 1 |
1114 # with 4 numbers (e.g. %QX0.1.2.55), this control flag is mapped |
1114 # with 4 numbers (e.g. %QX0.1.2.55), this control flag is mapped |
1115 # onto a location with 4 numbers (e.g. %QX0.1.2.0.0), where the last |
1115 # onto a location with 4 numbers (e.g. %QX0.1.2.0.0), where the last |
1116 # two numbers are always '0.0', and the first two identify the request. |
1116 # two numbers are always '0.0', and the first two identify the request. |
1117 # In the following if, we check for this condition by checking |
1117 # In the following if, we check for this condition by checking |
1118 # if there are at least 4 or more number in the location's address. |
1118 # if there are at least 4 or more number in the location's address. |
1119 if ( relative_addr in xrange(int(GetCTVal(subchild, 2))) # condition (a) explained above |
1119 if ( relative_addr in range(int(GetCTVal(subchild, 2))) # condition (a) explained above |
1120 and len(iecvar["LOC"]) < 5): # condition (b) explained above |
1120 and len(iecvar["LOC"]) < 5): # condition (b) explained above |
1121 if str(iecvar["NAME"]) not in loc_vars_list: |
1121 if str(iecvar["NAME"]) not in loc_vars_list: |
1122 loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].plcv_buffer[%d];" % (client_requestid, relative_addr)) |
1122 loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].plcv_buffer[%d];" % (client_requestid, relative_addr)) |
1123 loc_vars_list.append(str(iecvar["NAME"])) |
1123 loc_vars_list.append(str(iecvar["NAME"])) |
1124 # Now add the located variable in case it is a flag (condition (b) above |
1124 # Now add the located variable in case it is a flag (condition (b) above |
1175 # with 4 numbers (e.g. %QX0.1.2.55), this control flag is mapped |
1175 # with 4 numbers (e.g. %QX0.1.2.55), this control flag is mapped |
1176 # onto a location with 4 numbers (e.g. %QX0.1.2.0.0), where the last |
1176 # onto a location with 4 numbers (e.g. %QX0.1.2.0.0), where the last |
1177 # two numbers are always '0.0', and the first two identify the request. |
1177 # two numbers are always '0.0', and the first two identify the request. |
1178 # In the following if, we check for this condition by checking |
1178 # In the following if, we check for this condition by checking |
1179 # if there are at least 4 or more number in the location's address. |
1179 # if there are at least 4 or more number in the location's address. |
1180 if ( relative_addr in xrange(int(GetCTVal(subchild, 2))) # condition (a) explained above |
1180 if ( relative_addr in range(int(GetCTVal(subchild, 2))) # condition (a) explained above |
1181 and len(iecvar["LOC"]) < 5): # condition (b) explained above |
1181 and len(iecvar["LOC"]) < 5): # condition (b) explained above |
1182 if str(iecvar["NAME"]) not in loc_vars_list: |
1182 if str(iecvar["NAME"]) not in loc_vars_list: |
1183 loc_vars.append( |
1183 loc_vars.append( |
1184 "u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].plcv_buffer[%d];" % (client_requestid, relative_addr)) |
1184 "u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].plcv_buffer[%d];" % (client_requestid, relative_addr)) |
1185 loc_vars_list.append(str(iecvar["NAME"])) |
1185 loc_vars_list.append(str(iecvar["NAME"])) |