ProjectController.py
changeset 883 235a9ec83b95
parent 869 abf90a44c265
child 897 3cd39bc7dbad
equal deleted inserted replaced
882:3c6ce0a5ab2c 883:235a9ec83b95
   501                     if not resdict['SIZE']:
   501                     if not resdict['SIZE']:
   502                         resdict['SIZE'] = 'X'
   502                         resdict['SIZE'] = 'X'
   503                     # finally store into located variable list
   503                     # finally store into located variable list
   504                     locations.append(resdict)
   504                     locations.append(resdict)
   505         return locations
   505         return locations
   506         
   506     
       
   507     def GetConfNodeGlobalInstances(self):
       
   508         return self._GlobalInstances()
       
   509     
   507     def _Generate_SoftPLC(self):
   510     def _Generate_SoftPLC(self):
   508         """
   511         """
   509         Generate SoftPLC ST/IL/SFC code out of PLCOpenEditor controller, and compile it with IEC2C
   512         Generate SoftPLC ST/IL/SFC code out of PLCOpenEditor controller, and compile it with IEC2C
   510         @param buildpath: path where files should be created
   513         @param buildpath: path where files should be created
   511         """
   514         """
   695                     attrs["C_path"] = '__'.join(attrs["C_path"].split(".",2)[1:])
   698                     attrs["C_path"] = '__'.join(attrs["C_path"].split(".",2)[1:])
   696                     # Push this dictionnary into result.
   699                     # Push this dictionnary into result.
   697                     self._ProgramList.append(attrs)
   700                     self._ProgramList.append(attrs)
   698         
   701         
   699                 # second section contains all variables
   702                 # second section contains all variables
       
   703                 config_FBs = {}
   700                 for line in ListGroup[1]:
   704                 for line in ListGroup[1]:
   701                     # Split and Maps each field to dictionnary entries
   705                     # Split and Maps each field to dictionnary entries
   702                     attrs = dict(zip(VariablesListAttributeName,line.strip().split(';')))
   706                     attrs = dict(zip(VariablesListAttributeName,line.strip().split(';')))
   703                     # Truncate "C_path" to remove conf an ressources names
   707                     # Truncate "C_path" to remove conf an ressources names
   704                     parts = attrs["C_path"].split(".",2)
   708                     parts = attrs["C_path"].split(".",2)
   705                     if len(parts) > 2:
   709                     if len(parts) > 2:
   706                         attrs["C_path"] = '__'.join(parts[1:])
   710                         config_FB = config_FBs.get(tuple(parts[:2]))
       
   711                         if config_FB:
       
   712                             parts = [config_FB] + parts[2:]
       
   713                             attrs["C_path"] = '.'.join(parts)
       
   714                         else: 
       
   715                             attrs["C_path"] = '__'.join(parts[1:])
   707                     else:
   716                     else:
   708                         attrs["C_path"] = '__'.join(parts)
   717                         attrs["C_path"] = '__'.join(parts)
       
   718                         if attrs["vartype"] == "FB":
       
   719                             config_FBs[tuple(parts)] = attrs["C_path"]
   709                     # Push this dictionnary into result.
   720                     # Push this dictionnary into result.
   710                     self._VariablesList.append(attrs)
   721                     self._VariablesList.append(attrs)
   711                     # Fill in IEC<->C translation dicts
   722                     # Fill in IEC<->C translation dicts
   712                     IEC_path=attrs["IEC_path"]
   723                     IEC_path=attrs["IEC_path"]
   713                     Idx=int(attrs["num"])
   724                     Idx=int(attrs["num"])
   739            "extern_variables_declarations":"\n".join([
   750            "extern_variables_declarations":"\n".join([
   740               {"EXT":"extern __IEC_%(type)s_p %(C_path)s;",
   751               {"EXT":"extern __IEC_%(type)s_p %(C_path)s;",
   741                "IN":"extern __IEC_%(type)s_p %(C_path)s;",
   752                "IN":"extern __IEC_%(type)s_p %(C_path)s;",
   742                "MEM":"extern __IEC_%(type)s_p %(C_path)s;",
   753                "MEM":"extern __IEC_%(type)s_p %(C_path)s;",
   743                "OUT":"extern __IEC_%(type)s_p %(C_path)s;",
   754                "OUT":"extern __IEC_%(type)s_p %(C_path)s;",
   744                "VAR":"extern __IEC_%(type)s_t %(C_path)s;"}[v["vartype"]]%v 
   755                "VAR":"extern __IEC_%(type)s_t %(C_path)s;",
   745                for v in self._VariablesList if v["vartype"] != "FB" and v["C_path"].find('.')<0]),
   756                "FB":"extern %(type)s %(C_path)s;"}[v["vartype"]]%v 
       
   757                for v in self._VariablesList if v["C_path"].find('.')<0]),
   746            "for_each_variable_do_code":"\n".join([
   758            "for_each_variable_do_code":"\n".join([
   747                {"EXT":"    (*fp)((void*)&%(C_path)s,%(type)s_P_ENUM);\n",
   759                {"EXT":"    (*fp)((void*)&(%(C_path)s),%(type)s_P_ENUM);\n",
   748                 "IN":"    (*fp)((void*)&%(C_path)s,%(type)s_P_ENUM);\n",
   760                 "IN":"    (*fp)((void*)&(%(C_path)s),%(type)s_P_ENUM);\n",
   749                 "MEM":"    (*fp)((void*)&%(C_path)s,%(type)s_O_ENUM);\n",
   761                 "MEM":"    (*fp)((void*)&(%(C_path)s),%(type)s_O_ENUM);\n",
   750                 "OUT":"    (*fp)((void*)&%(C_path)s,%(type)s_O_ENUM);\n",
   762                 "OUT":"    (*fp)((void*)&(%(C_path)s),%(type)s_O_ENUM);\n",
   751                 "VAR":"    (*fp)((void*)&%(C_path)s,%(type)s_ENUM);\n"}[v["vartype"]]%v
   763                 "VAR":"    (*fp)((void*)&(%(C_path)s),%(type)s_ENUM);\n"}[v["vartype"]]%v
   752                 for v in self._VariablesList if v["vartype"] != "FB" and v["type"] in DebugTypesSize ]),
   764                 for v in self._VariablesList if v["vartype"] != "FB" and v["type"] in DebugTypesSize ]),
   753            "find_variable_case_code":"\n".join([
   765            "find_variable_case_code":"\n".join([
   754                "    case %(num)s:\n"%v+
   766                "    case %(num)s:\n"%v+
   755                "        *varp = (void*)&%(C_path)s;\n"%v+
   767                "        *varp = (void*)&(%(C_path)s);\n"%v+
   756                {"EXT":"        return %(type)s_P_ENUM;\n",
   768                {"EXT":"        return %(type)s_P_ENUM;\n",
   757                 "IN":"        return %(type)s_P_ENUM;\n",
   769                 "IN":"        return %(type)s_P_ENUM;\n",
   758                 "MEM":"        return %(type)s_O_ENUM;\n",
   770                 "MEM":"        return %(type)s_O_ENUM;\n",
   759                 "OUT":"        return %(type)s_O_ENUM;\n",
   771                 "OUT":"        return %(type)s_O_ENUM;\n",
   760                 "VAR":"        return %(type)s_ENUM;\n"}[v["vartype"]]%v
   772                 "VAR":"        return %(type)s_ENUM;\n"}[v["vartype"]]%v