PLCControler.py
changeset 681 c141dad94ff4
parent 661 7891872e6fd7
child 684 f10449b18dbe
equal deleted inserted replaced
680:b693147fb2c3 681:c141dad94ff4
    73                    "Input" :    (plcopen.interface_inputVars,    ITEM_VAR_INPUT),
    73                    "Input" :    (plcopen.interface_inputVars,    ITEM_VAR_INPUT),
    74                    "Output" :   (plcopen.interface_outputVars,   ITEM_VAR_OUTPUT),
    74                    "Output" :   (plcopen.interface_outputVars,   ITEM_VAR_OUTPUT),
    75                    "InOut" :    (plcopen.interface_inOutVars,    ITEM_VAR_INOUT)
    75                    "InOut" :    (plcopen.interface_inOutVars,    ITEM_VAR_INOUT)
    76                   }
    76                   }
    77 
    77 
    78 LOCATIONS_ITEMS = [LOCATION_PLUGIN,
    78 LOCATIONS_ITEMS = [LOCATION_CONFNODE,
    79                    LOCATION_MODULE,
    79                    LOCATION_MODULE,
    80                    LOCATION_GROUP,
    80                    LOCATION_GROUP,
    81                    LOCATION_VAR_INPUT,
    81                    LOCATION_VAR_INPUT,
    82                    LOCATION_VAR_OUTPUT,
    82                    LOCATION_VAR_OUTPUT,
    83                    LOCATION_VAR_MEMORY] = range(6)
    83                    LOCATION_VAR_MEMORY] = range(6)
   202         self.FileName = ""
   202         self.FileName = ""
   203         self.ProgramChunks = []
   203         self.ProgramChunks = []
   204         self.ProgramOffset = 0
   204         self.ProgramOffset = 0
   205         self.NextCompiledProject = None
   205         self.NextCompiledProject = None
   206         self.CurrentCompiledProject = None
   206         self.CurrentCompiledProject = None
   207         self.PluginTypes = []
   207         self.ConfNodeTypes = []
   208         self.ProgramFilePath = ""
   208         self.ProgramFilePath = ""
   209         
   209         
   210     def GetQualifierTypes(self):
   210     def GetQualifierTypes(self):
   211         return plcopen.QualifierList
   211         return plcopen.QualifierList
   212 
   212 
  1127                 if not en:
  1127                 if not en:
  1128                     tree.insert(0, ("EN", "BOOL", ([], [])))
  1128                     tree.insert(0, ("EN", "BOOL", ([], [])))
  1129                 return tree, []
  1129                 return tree, []
  1130             datatype = project.getdataType(typename)
  1130             datatype = project.getdataType(typename)
  1131             if datatype is None:
  1131             if datatype is None:
  1132                 datatype = self.GetPluginDataType(typename)
  1132                 datatype = self.GetConfNodeDataType(typename)
  1133             if datatype is not None:
  1133             if datatype is not None:
  1134                 tree = []
  1134                 tree = []
  1135                 basetype_content = datatype.baseType.getcontent()
  1135                 basetype_content = datatype.baseType.getcontent()
  1136                 if basetype_content["name"] == "derived":
  1136                 if basetype_content["name"] == "derived":
  1137                     return self.GenerateVarTree(basetype_content["value"].getname())
  1137                     return self.GenerateVarTree(basetype_content["value"].getname())
  1249                     return returntype_content["name"].upper()
  1249                     return returntype_content["name"].upper()
  1250                 else:
  1250                 else:
  1251                     return returntype_content["name"]
  1251                     return returntype_content["name"]
  1252         return None
  1252         return None
  1253 
  1253 
  1254     # Function that add a new plugin to the plugin list
  1254     # Function that add a new confnode to the confnode list
  1255     def AddPluginTypesList(self, typeslist):
  1255     def AddConfNodeTypesList(self, typeslist):
  1256         self.PluginTypes.extend(typeslist)
  1256         self.ConfNodeTypes.extend(typeslist)
  1257         
  1257         
  1258     # Function that clear the plugin list
  1258     # Function that clear the confnode list
  1259     def ClearPluginTypes(self):
  1259     def ClearConfNodeTypes(self):
  1260         for i in xrange(len(self.PluginTypes)):
  1260         for i in xrange(len(self.ConfNodeTypes)):
  1261             self.PluginTypes.pop(0)
  1261             self.ConfNodeTypes.pop(0)
  1262 
  1262 
  1263     def GetPluginBlockTypes(self):
  1263     def GetConfNodeBlockTypes(self):
  1264         return [{"name": _("%s POUs") % plugintypes["name"],
  1264         return [{"name": _("%s POUs") % confnodetypes["name"],
  1265                  "list": plugintypes["types"].GetCustomBlockTypes()}
  1265                  "list": confnodetypes["types"].GetCustomBlockTypes()}
  1266                 for plugintypes in self.PluginTypes]
  1266                 for confnodetypes in self.ConfNodeTypes]
  1267         
  1267         
  1268     def GetPluginDataTypes(self, exclude = ""):
  1268     def GetConfNodeDataTypes(self, exclude = ""):
  1269         return [{"name": _("%s Data Types") % plugintypes["name"],
  1269         return [{"name": _("%s Data Types") % confnodetypes["name"],
  1270                  "list": [datatype["name"] for datatype in plugintypes["types"].GetCustomDataTypes(exclude)]}
  1270                  "list": [datatype["name"] for datatype in confnodetypes["types"].GetCustomDataTypes(exclude)]}
  1271                 for plugintypes in self.PluginTypes]
  1271                 for confnodetypes in self.ConfNodeTypes]
  1272     
  1272     
  1273     def GetPluginDataType(self, type):
  1273     def GetConfNodeDataType(self, type):
  1274         for plugintype in self.PluginTypes:
  1274         for confnodetype in self.ConfNodeTypes:
  1275             datatype = plugintype["types"].getdataType(type)
  1275             datatype = confnodetype["types"].getdataType(type)
  1276             if datatype is not None:
  1276             if datatype is not None:
  1277                 return datatype
  1277                 return datatype
  1278         return None
  1278         return None
  1279     
  1279     
  1280     def GetVariableLocationTree(self):
  1280     def GetVariableLocationTree(self):
  1281         return []
  1281         return []
  1282 
  1282 
  1283     # Function that returns the block definition associated to the block type given
  1283     # Function that returns the block definition associated to the block type given
  1284     def GetBlockType(self, type, inputs = None, debug = False):
  1284     def GetBlockType(self, type, inputs = None, debug = False):
  1285         result_blocktype = None
  1285         result_blocktype = None
  1286         for category in BlockTypes + self.GetPluginBlockTypes():
  1286         for category in BlockTypes + self.GetConfNodeBlockTypes():
  1287             for blocktype in category["list"]:
  1287             for blocktype in category["list"]:
  1288                 if blocktype["name"] == type:
  1288                 if blocktype["name"] == type:
  1289                     if inputs is not None and inputs != "undefined":
  1289                     if inputs is not None and inputs != "undefined":
  1290                         block_inputs = tuple([var_type for name, var_type, modifier in blocktype["inputs"]])
  1290                         block_inputs = tuple([var_type for name, var_type, modifier in blocktype["inputs"]])
  1291                         if reduce(lambda x, y: x and y, map(lambda x: x[0] == "ANY" or self.IsOfType(*x), zip(inputs, block_inputs)), True):
  1291                         if reduce(lambda x, y: x and y, map(lambda x: x[0] == "ANY" or self.IsOfType(*x), zip(inputs, block_inputs)), True):
  1315             if words[0] in ["P","T","A"]:
  1315             if words[0] in ["P","T","A"]:
  1316                 name = words[1]
  1316                 name = words[1]
  1317                 type = self.GetPouType(name, debug)
  1317                 type = self.GetPouType(name, debug)
  1318         if type == "function" or words[0] == "T":
  1318         if type == "function" or words[0] == "T":
  1319             blocktypes = []
  1319             blocktypes = []
  1320             for category in BlockTypes + self.GetPluginBlockTypes():
  1320             for category in BlockTypes + self.GetConfNodeBlockTypes():
  1321                 cat = {"name" : category["name"], "list" : []}
  1321                 cat = {"name" : category["name"], "list" : []}
  1322                 for block in category["list"]:
  1322                 for block in category["list"]:
  1323                     if block["type"] == "function":
  1323                     if block["type"] == "function":
  1324                         cat["list"].append(block)
  1324                         cat["list"].append(block)
  1325                 if len(cat["list"]) > 0:
  1325                 if len(cat["list"]) > 0:
  1326                     blocktypes.append(cat)
  1326                     blocktypes.append(cat)
  1327         else:
  1327         else:
  1328             blocktypes = [category for category in BlockTypes + self.GetPluginBlockTypes()]
  1328             blocktypes = [category for category in BlockTypes + self.GetConfNodeBlockTypes()]
  1329         project = self.GetProject(debug)
  1329         project = self.GetProject(debug)
  1330         if project is not None:
  1330         if project is not None:
  1331             blocktypes.append({"name" : USER_DEFINED_POUS, "list": project.GetCustomBlockTypes(name, type == "function" or words[0] == "T")})
  1331             blocktypes.append({"name" : USER_DEFINED_POUS, "list": project.GetCustomBlockTypes(name, type == "function" or words[0] == "T")})
  1332         return blocktypes
  1332         return blocktypes
  1333 
  1333 
  1334     # Return Function Block types checking for recursion
  1334     # Return Function Block types checking for recursion
  1335     def GetFunctionBlockTypes(self, tagname = "", debug = False):
  1335     def GetFunctionBlockTypes(self, tagname = "", debug = False):
  1336         blocktypes = []
  1336         blocktypes = []
  1337         for category in BlockTypes + self.GetPluginBlockTypes():
  1337         for category in BlockTypes + self.GetConfNodeBlockTypes():
  1338             for block in category["list"]:
  1338             for block in category["list"]:
  1339                 if block["type"] == "functionBlock":
  1339                 if block["type"] == "functionBlock":
  1340                     blocktypes.append(block["name"])
  1340                     blocktypes.append(block["name"])
  1341         project = self.GetProject(debug)
  1341         project = self.GetProject(debug)
  1342         if project is not None:
  1342         if project is not None:
  1379         project = self.GetProject(debug)
  1379         project = self.GetProject(debug)
  1380         if project is not None:
  1380         if project is not None:
  1381             result = project.GetBaseType(type)
  1381             result = project.GetBaseType(type)
  1382             if result is not None:
  1382             if result is not None:
  1383                 return result
  1383                 return result
  1384         for plugintype in self.PluginTypes:
  1384         for confnodetype in self.ConfNodeTypes:
  1385             result = plugintype["types"].GetBaseType(type)
  1385             result = confnodetype["types"].GetBaseType(type)
  1386             if result is not None:
  1386             if result is not None:
  1387                 return result
  1387                 return result
  1388         return None
  1388         return None
  1389 
  1389 
  1390     def GetBaseTypes(self):
  1390     def GetBaseTypes(self):
  1404             return self.IsOfType(TypeHierarchy[type], reference)
  1404             return self.IsOfType(TypeHierarchy[type], reference)
  1405         else:
  1405         else:
  1406             project = self.GetProject(debug)
  1406             project = self.GetProject(debug)
  1407             if project is not None and project.IsOfType(type, reference):
  1407             if project is not None and project.IsOfType(type, reference):
  1408                 return True
  1408                 return True
  1409             for plugintype in self.PluginTypes:
  1409             for confnodetype in self.ConfNodeTypes:
  1410                 if plugintype["types"].IsOfType(type, reference):
  1410                 if confnodetype["types"].IsOfType(type, reference):
  1411                     return True
  1411                     return True
  1412         return False
  1412         return False
  1413     
  1413     
  1414     def IsEndType(self, type):
  1414     def IsEndType(self, type):
  1415         if type is not None:
  1415         if type is not None:
  1421             return False 
  1421             return False 
  1422         project = self.GetProject(debug)
  1422         project = self.GetProject(debug)
  1423         if project is not None:
  1423         if project is not None:
  1424             datatype = project.getdataType(type)
  1424             datatype = project.getdataType(type)
  1425             if datatype is None:
  1425             if datatype is None:
  1426                 datatype = self.GetPluginDataType(type)
  1426                 datatype = self.GetConfNodeDataType(type)
  1427             if datatype is not None:
  1427             if datatype is not None:
  1428                 return project.IsLocatableType(datatype)
  1428                 return project.IsLocatableType(datatype)
  1429         return True
  1429         return True
  1430     
  1430     
  1431     def IsEnumeratedType(self, type, debug = False):
  1431     def IsEnumeratedType(self, type, debug = False):
  1432         project = self.GetProject(debug)
  1432         project = self.GetProject(debug)
  1433         if project is not None:
  1433         if project is not None:
  1434             datatype = project.getdataType(type)
  1434             datatype = project.getdataType(type)
  1435             if datatype is None:
  1435             if datatype is None:
  1436                 datatype = self.GetPluginDataType(type)
  1436                 datatype = self.GetConfNodeDataType(type)
  1437             if datatype is not None:
  1437             if datatype is not None:
  1438                 basetype_content = datatype.baseType.getcontent()
  1438                 basetype_content = datatype.baseType.getcontent()
  1439                 return basetype_content["name"] == "enum"
  1439                 return basetype_content["name"] == "enum"
  1440         return False
  1440         return False
  1441 
  1441 
  1446             project = self.GetProject(debug)
  1446             project = self.GetProject(debug)
  1447             if project is not None:
  1447             if project is not None:
  1448                 result = project.GetDataTypeRange(type)
  1448                 result = project.GetDataTypeRange(type)
  1449                 if result is not None:
  1449                 if result is not None:
  1450                     return result
  1450                     return result
  1451             for plugintype in self.PluginTypes:
  1451             for confnodetype in self.ConfNodeTypes:
  1452                 result = plugintype["types"].GetDataTypeRange(type)
  1452                 result = confnodetype["types"].GetDataTypeRange(type)
  1453                 if result is not None:
  1453                 if result is not None:
  1454                     return result
  1454                     return result
  1455         return None
  1455         return None
  1456     
  1456     
  1457     # Return Subrange types
  1457     # Return Subrange types
  1458     def GetSubrangeBaseTypes(self, exclude, debug = False):
  1458     def GetSubrangeBaseTypes(self, exclude, debug = False):
  1459         subrange_basetypes = []
  1459         subrange_basetypes = []
  1460         project = self.GetProject(debug)
  1460         project = self.GetProject(debug)
  1461         if project is not None:
  1461         if project is not None:
  1462             subrange_basetypes.extend(project.GetSubrangeBaseTypes(exclude))
  1462             subrange_basetypes.extend(project.GetSubrangeBaseTypes(exclude))
  1463         for plugintype in self.PluginTypes:
  1463         for confnodetype in self.ConfNodeTypes:
  1464             subrange_basetypes.extend(plugintype["types"].GetSubrangeBaseTypes(exclude))
  1464             subrange_basetypes.extend(confnodetype["types"].GetSubrangeBaseTypes(exclude))
  1465         return DataTypeRange.keys() + subrange_basetypes
  1465         return DataTypeRange.keys() + subrange_basetypes
  1466     
  1466     
  1467     # Return Enumerated Values
  1467     # Return Enumerated Values
  1468     def GetEnumeratedDataValues(self, type = None, debug = False):
  1468     def GetEnumeratedDataValues(self, type = None, debug = False):
  1469         values = []
  1469         values = []
  1470         project = self.GetProject(debug)
  1470         project = self.GetProject(debug)
  1471         if project is not None:
  1471         if project is not None:
  1472             values.extend(project.GetEnumeratedDataTypeValues(type))
  1472             values.extend(project.GetEnumeratedDataTypeValues(type))
  1473             if type is None and len(values) > 0:
  1473             if type is None and len(values) > 0:
  1474                 return values
  1474                 return values
  1475         for plugintype in self.PluginTypes:
  1475         for confnodetype in self.ConfNodeTypes:
  1476             values.extend(plugintype["types"].GetEnumeratedDataTypeValues(type))
  1476             values.extend(confnodetype["types"].GetEnumeratedDataTypeValues(type))
  1477             if type is None and len(values) > 0:
  1477             if type is None and len(values) > 0:
  1478                 return values
  1478                 return values
  1479         return values
  1479         return values
  1480 
  1480 
  1481 #-------------------------------------------------------------------------------
  1481 #-------------------------------------------------------------------------------