1016 factorized_paths.append(paths[num]) |
1016 factorized_paths.append(paths[num]) |
1017 factorized_paths.sort() |
1017 factorized_paths.sort() |
1018 return factorized_paths |
1018 return factorized_paths |
1019 |
1019 |
1020 def GenerateBlock(self, block, block_infos, body, link, order=False, to_inout=False): |
1020 def GenerateBlock(self, block, block_infos, body, link, order=False, to_inout=False): |
|
1021 |
|
1022 def _GetBlockName(name, type): |
|
1023 """function returns name of function or function block instance""" |
|
1024 if name: |
|
1025 # function blocks |
|
1026 blockname = "{a1}({a2})".format(a1=name, a2=type) |
|
1027 else: |
|
1028 # functions |
|
1029 blockname = type |
|
1030 return blockname |
|
1031 |
|
1032 def _RaiseUnconnectedInOutError(name, type, parameter, place): |
|
1033 blockname = _GetBlockName(name, type) |
|
1034 raise ValueError( |
|
1035 _("InOut variable {a1} in block {a2} in POU {a3} must be connected."). |
|
1036 format(a1=parameter, a2=blockname, a3=place)) |
|
1037 |
1021 name = block.getinstanceName() |
1038 name = block.getinstanceName() |
1022 type = block.gettypeName() |
1039 type = block.gettypeName() |
1023 executionOrderId = block.getexecutionOrderId() |
1040 executionOrderId = block.getexecutionOrderId() |
1024 input_variables = block.inputVariables.getvariable() |
1041 input_variables = block.inputVariables.getvariable() |
1025 output_variables = block.outputVariables.getvariable() |
1042 output_variables = block.outputVariables.getvariable() |
1063 one_input_connected = True |
1080 one_input_connected = True |
1064 if parameter in inout_variables: |
1081 if parameter in inout_variables: |
1065 expression = self.ComputeExpression(body, connections, executionOrderId > 0, True) |
1082 expression = self.ComputeExpression(body, connections, executionOrderId > 0, True) |
1066 if expression is not None: |
1083 if expression is not None: |
1067 inout_variables[parameter] = expression |
1084 inout_variables[parameter] = expression |
|
1085 else: |
|
1086 _RaiseUnconnectedInOutError(name, type, parameter, self.Name) |
1068 else: |
1087 else: |
1069 expression = self.ComputeExpression(body, connections, executionOrderId > 0) |
1088 expression = self.ComputeExpression(body, connections, executionOrderId > 0) |
1070 if expression is not None: |
1089 if expression is not None: |
1071 connected_vars.append(([(parameter, input_info), (" := ", ())], |
1090 connected_vars.append(([(parameter, input_info), (" := ", ())], |
1072 self.ExtractModifier(variable, expression, input_info))) |
1091 self.ExtractModifier(variable, expression, input_info))) |
1126 if connections is not None: |
1145 if connections is not None: |
1127 expression = self.ComputeExpression(body, connections, executionOrderId > 0, parameter in inout_variables) |
1146 expression = self.ComputeExpression(body, connections, executionOrderId > 0, parameter in inout_variables) |
1128 if expression is not None: |
1147 if expression is not None: |
1129 vars.append([(parameter, input_info), |
1148 vars.append([(parameter, input_info), |
1130 (" := ", ())] + self.ExtractModifier(variable, expression, input_info)) |
1149 (" := ", ())] + self.ExtractModifier(variable, expression, input_info)) |
|
1150 elif parameter in inout_variables: |
|
1151 _RaiseUnconnectedInOutError(name, type, parameter, self.Name) |
1131 self.Program += [(self.CurrentIndent, ()), |
1152 self.Program += [(self.CurrentIndent, ()), |
1132 (name, (self.TagName, "block", block.getlocalId(), "name")), |
1153 (name, (self.TagName, "block", block.getlocalId(), "name")), |
1133 ("(", ())] |
1154 ("(", ())] |
1134 self.Program += JoinList([(", ", ())], vars) |
1155 self.Program += JoinList([(", ", ())], vars) |
1135 self.Program += [(");\n", ())] |
1156 self.Program += [(");\n", ())] |
1162 |
1183 |
1163 if output_variable is not None: |
1184 if output_variable is not None: |
1164 if block_infos["type"] == "function": |
1185 if block_infos["type"] == "function": |
1165 output_info = (self.TagName, "block", block.getlocalId(), "output", output_idx) |
1186 output_info = (self.TagName, "block", block.getlocalId(), "output", output_idx) |
1166 if output_parameter in inout_variables: |
1187 if output_parameter in inout_variables: |
1167 output_value = inout_variables[output_parameter] |
1188 for variable in input_variables: |
|
1189 if variable.getformalParameter() == output_parameter: |
|
1190 connections = variable.connectionPointIn.getconnections() |
|
1191 if connections is not None: |
|
1192 expression = self.ComputeExpression( |
|
1193 body, connections, executionOrderId > 0, True) |
|
1194 output_value = expression |
|
1195 break |
1168 else: |
1196 else: |
1169 if output_parameter == "": |
1197 if output_parameter == "": |
1170 output_name = "%s%d" % (type, block.getlocalId()) |
1198 output_name = "%s%d" % (type, block.getlocalId()) |
1171 else: |
1199 else: |
1172 output_name = "%s%d_%s" % (type, block.getlocalId(), output_parameter) |
1200 output_name = "%s%d_%s" % (type, block.getlocalId(), output_parameter) |
1173 output_value = [(output_name, output_info)] |
1201 output_value = [(output_name, output_info)] |
1174 return self.ExtractModifier(output_variable, output_value, output_info) |
1202 return self.ExtractModifier(output_variable, output_value, output_info) |
1175 |
|
1176 if block_infos["type"] == "functionBlock": |
1203 if block_infos["type"] == "functionBlock": |
1177 output_info = (self.TagName, "block", block.getlocalId(), "output", output_idx) |
1204 output_info = (self.TagName, "block", block.getlocalId(), "output", output_idx) |
1178 output_name = self.ExtractModifier(output_variable, [("%s.%s" % (name, output_parameter), output_info)], output_info) |
1205 output_name = self.ExtractModifier(output_variable, [("%s.%s" % (name, output_parameter), output_info)], output_info) |
1179 if to_inout: |
1206 if to_inout: |
1180 variable_name = "%s_%s" % (name, output_parameter) |
1207 variable_name = "%s_%s" % (name, output_parameter) |
1193 return [(variable_name, ())] |
1220 return [(variable_name, ())] |
1194 return output_name |
1221 return output_name |
1195 if link is not None: |
1222 if link is not None: |
1196 if output_parameter is None: |
1223 if output_parameter is None: |
1197 output_parameter = "" |
1224 output_parameter = "" |
1198 if name: |
1225 blockname = _GetBlockName(name, type) |
1199 blockname = "{a1}({a2})".format(a1=name, a2=type) |
|
1200 else: |
|
1201 blockname = type |
|
1202 raise ValueError( |
1226 raise ValueError( |
1203 _("No output {a1} variable found in block {a2} in POU {a3}. Connection must be broken"). |
1227 _("No output {a1} variable found in block {a2} in POU {a3}. Connection must be broken"). |
1204 format(a1=output_parameter, a2=blockname, a3=self.Name)) |
1228 format(a1=output_parameter, a2=blockname, a3=self.Name)) |
1205 |
1229 |
1206 def GeneratePaths(self, connections, body, order=False, to_inout=False): |
1230 def GeneratePaths(self, connections, body, order=False, to_inout=False): |