132 self.ieclib_path] |
132 self.ieclib_path] |
133 path = self.findObject(paths, lambda p:os.path.isfile(os.path.join(p, "iec_types.h"))) |
133 path = self.findObject(paths, lambda p:os.path.isfile(os.path.join(p, "iec_types.h"))) |
134 return path |
134 return path |
135 |
135 |
136 def findSupportedOptions(self): |
136 def findSupportedOptions(self): |
137 buildcmd = "\"%s\" -h"%(self.getCmd()) |
137 buildcmd = "\"%s\" -h" % (self.getCmd()) |
138 options =["-f", "-l", "-p"] |
138 options =["-f", "-l", "-p"] |
139 |
139 |
140 buildopt = "" |
140 buildopt = "" |
141 try: |
141 try: |
142 # Invoke compiler. Output files are listed to stdout, errors to stderr |
142 # Invoke compiler. Output files are listed to stdout, errors to stderr |
564 |
564 |
565 def GetLibrariesCCode(self, buildpath): |
565 def GetLibrariesCCode(self, buildpath): |
566 if len(self.Libraries)==0: |
566 if len(self.Libraries)==0: |
567 return [],[],() |
567 return [],[],() |
568 self.GetIECProgramsAndVariables() |
568 self.GetIECProgramsAndVariables() |
569 LibIECCflags = '"-I%s" -Wno-unused-function'%os.path.abspath(self.GetIECLibPath()) |
569 LibIECCflags = '"-I%s" -Wno-unused-function' % os.path.abspath(self.GetIECLibPath()) |
570 LocatedCCodeAndFlags=[] |
570 LocatedCCodeAndFlags=[] |
571 Extras=[] |
571 Extras=[] |
572 for lib in self.Libraries: |
572 for lib in self.Libraries: |
573 res=lib.Generate_C(buildpath,self._VariablesList,LibIECCflags) |
573 res=lib.Generate_C(buildpath,self._VariablesList,LibIECCflags) |
574 LocatedCCodeAndFlags.append(res[:2]) |
574 LocatedCCodeAndFlags.append(res[:2]) |
707 # ask PLCOpenEditor controller to write ST/IL/SFC code file |
707 # ask PLCOpenEditor controller to write ST/IL/SFC code file |
708 program, errors, warnings = self.GenerateProgram(self._getIECgeneratedcodepath()) |
708 program, errors, warnings = self.GenerateProgram(self._getIECgeneratedcodepath()) |
709 if len(warnings) > 0: |
709 if len(warnings) > 0: |
710 self.logger.write_warning(_("Warnings in ST/IL/SFC code generator :\n")) |
710 self.logger.write_warning(_("Warnings in ST/IL/SFC code generator :\n")) |
711 for warning in warnings: |
711 for warning in warnings: |
712 self.logger.write_warning("%s\n"%warning) |
712 self.logger.write_warning("%s\n" % warning) |
713 if len(errors) > 0: |
713 if len(errors) > 0: |
714 # Failed ! |
714 # Failed ! |
715 self.logger.write_error(_("Error in ST/IL/SFC code generator :\n%s\n")%errors[0]) |
715 self.logger.write_error(_("Error in ST/IL/SFC code generator :\n%s\n") % errors[0]) |
716 return False |
716 return False |
717 plc_file = open(self._getIECcodepath(), "w") |
717 plc_file = open(self._getIECcodepath(), "w") |
718 # Add ST Library from confnodes |
718 # Add ST Library from confnodes |
719 plc_file.write(self.GetLibrariesSTCode()) |
719 plc_file.write(self.GetLibrariesSTCode()) |
720 if os.path.isfile(self._getIECrawcodepath()): |
720 if os.path.isfile(self._getIECrawcodepath()): |
734 |
734 |
735 |
735 |
736 def _Compile_ST_to_SoftPLC(self): |
736 def _Compile_ST_to_SoftPLC(self): |
737 self.logger.write(_("Compiling IEC Program into C code...\n")) |
737 self.logger.write(_("Compiling IEC Program into C code...\n")) |
738 buildpath = self._getBuildPath() |
738 buildpath = self._getBuildPath() |
739 buildcmd = "\"%s\" %s -I \"%s\" -T \"%s\" \"%s\""%( |
739 buildcmd = "\"%s\" %s -I \"%s\" -T \"%s\" \"%s\"" % ( |
740 iec2c_cfg.getCmd(), |
740 iec2c_cfg.getCmd(), |
741 iec2c_cfg.getOptions(), |
741 iec2c_cfg.getOptions(), |
742 iec2c_cfg.getLibPath(), |
742 iec2c_cfg.getLibPath(), |
743 buildpath, |
743 buildpath, |
744 self._getIECcodepath()) |
744 self._getIECcodepath()) |
779 last_section = None # only write section once |
779 last_section = None # only write section once |
780 self.logger.write_warning("%04d: %s" % (i, line)) |
780 self.logger.write_warning("%04d: %s" % (i, line)) |
781 |
781 |
782 f.close() |
782 f.close() |
783 |
783 |
784 self.logger.write_error(_("Error : IEC to C compiler returned %d\n")%status) |
784 self.logger.write_error(_("Error : IEC to C compiler returned %d\n") % status) |
785 return False |
785 return False |
786 |
786 |
787 # Now extract C files of stdout |
787 # Now extract C files of stdout |
788 C_files = [ fname for fname in result.splitlines() if fname[-2:]==".c" or fname[-2:]==".C" ] |
788 C_files = [ fname for fname in result.splitlines() if fname[-2:]==".c" or fname[-2:]==".C" ] |
789 # remove those that are not to be compiled because included by others |
789 # remove those that are not to be compiled because included by others |
806 # Keep track of generated located variables for later use by self._Generate_C |
806 # Keep track of generated located variables for later use by self._Generate_C |
807 self.PLCGeneratedLocatedVars = self.GetLocations() |
807 self.PLCGeneratedLocatedVars = self.GetLocations() |
808 # Keep track of generated C files for later use by self.CTNGenerate_C |
808 # Keep track of generated C files for later use by self.CTNGenerate_C |
809 self.PLCGeneratedCFiles = C_files |
809 self.PLCGeneratedCFiles = C_files |
810 # compute CFLAGS for plc |
810 # compute CFLAGS for plc |
811 self.plcCFLAGS = '"-I%s" -Wno-unused-function'%iec2c_cfg.getLibCPath() |
811 self.plcCFLAGS = '"-I%s" -Wno-unused-function' % iec2c_cfg.getLibCPath() |
812 return True |
812 return True |
813 |
813 |
814 def GetBuilder(self): |
814 def GetBuilder(self): |
815 """ |
815 """ |
816 Return a Builder (compile C code into machine code) |
816 Return a Builder (compile C code into machine code) |
960 variable_decl_array = [] |
960 variable_decl_array = [] |
961 bofs = 0 |
961 bofs = 0 |
962 for v in self._DbgVariablesList : |
962 for v in self._DbgVariablesList : |
963 sz = DebugTypesSize.get(v["type"], 0) |
963 sz = DebugTypesSize.get(v["type"], 0) |
964 variable_decl_array += [ |
964 variable_decl_array += [ |
965 "{&(%(C_path)s), "%v+ |
965 "{&(%(C_path)s), " % v+ |
966 {"EXT":"%(type)s_P_ENUM", |
966 {"EXT":"%(type)s_P_ENUM", |
967 "IN":"%(type)s_P_ENUM", |
967 "IN":"%(type)s_P_ENUM", |
968 "MEM":"%(type)s_O_ENUM", |
968 "MEM":"%(type)s_O_ENUM", |
969 "OUT":"%(type)s_O_ENUM", |
969 "OUT":"%(type)s_O_ENUM", |
970 "VAR":"%(type)s_ENUM"}[v["vartype"]]%v + |
970 "VAR":"%(type)s_ENUM"}[v["vartype"]] % v + |
971 "}"] |
971 "}"] |
972 bofs += sz |
972 bofs += sz |
973 debug_code = targets.GetCode("plc_debug.c") % { |
973 debug_code = targets.GetCode("plc_debug.c") % { |
974 "buffer_size":bofs, |
974 "buffer_size":bofs, |
975 "programs_declarations": |
975 "programs_declarations": |
976 "\n".join(["extern %(type)s %(C_path)s;"%p for p in self._ProgramList]), |
976 "\n".join(["extern %(type)s %(C_path)s;" % p for p in self._ProgramList]), |
977 "extern_variables_declarations":"\n".join([ |
977 "extern_variables_declarations":"\n".join([ |
978 {"EXT":"extern __IEC_%(type)s_p %(C_path)s;", |
978 {"EXT":"extern __IEC_%(type)s_p %(C_path)s;", |
979 "IN":"extern __IEC_%(type)s_p %(C_path)s;", |
979 "IN":"extern __IEC_%(type)s_p %(C_path)s;", |
980 "MEM":"extern __IEC_%(type)s_p %(C_path)s;", |
980 "MEM":"extern __IEC_%(type)s_p %(C_path)s;", |
981 "OUT":"extern __IEC_%(type)s_p %(C_path)s;", |
981 "OUT":"extern __IEC_%(type)s_p %(C_path)s;", |
982 "VAR":"extern __IEC_%(type)s_t %(C_path)s;", |
982 "VAR":"extern __IEC_%(type)s_t %(C_path)s;", |
983 "FB":"extern %(type)s %(C_path)s;"}[v["vartype"]]%v |
983 "FB":"extern %(type)s %(C_path)s;"}[v["vartype"]] % v |
984 for v in self._VariablesList if v["C_path"].find('.')<0]), |
984 for v in self._VariablesList if v["C_path"].find('.')<0]), |
985 "variable_decl_array": ",\n".join(variable_decl_array) |
985 "variable_decl_array": ",\n".join(variable_decl_array) |
986 } |
986 } |
987 |
987 |
988 return debug_code |
988 return debug_code |
1002 plc_main_code = targets.GetCode("plc_main_head.c") % { |
1002 plc_main_code = targets.GetCode("plc_main_head.c") % { |
1003 "calls_prototypes":"\n".join([( |
1003 "calls_prototypes":"\n".join([( |
1004 "int __init_%(s)s(int argc,char **argv);\n"+ |
1004 "int __init_%(s)s(int argc,char **argv);\n"+ |
1005 "void __cleanup_%(s)s(void);\n"+ |
1005 "void __cleanup_%(s)s(void);\n"+ |
1006 "void __retrieve_%(s)s(void);\n"+ |
1006 "void __retrieve_%(s)s(void);\n"+ |
1007 "void __publish_%(s)s(void);")%{'s':locstr} for locstr in locstrs]), |
1007 "void __publish_%(s)s(void);") % {'s':locstr} for locstr in locstrs]), |
1008 "retrieve_calls":"\n ".join([ |
1008 "retrieve_calls":"\n ".join([ |
1009 "__retrieve_%s();"%locstr for locstr in locstrs]), |
1009 "__retrieve_%s();" % locstr for locstr in locstrs]), |
1010 "publish_calls":"\n ".join([ #Call publish in reverse order |
1010 "publish_calls":"\n ".join([ #Call publish in reverse order |
1011 "__publish_%s();"%locstrs[i-1] for i in xrange(len(locstrs), 0, -1)]), |
1011 "__publish_%s();" % locstrs[i-1] for i in xrange(len(locstrs), 0, -1)]), |
1012 "init_calls":"\n ".join([ |
1012 "init_calls":"\n ".join([ |
1013 "init_level=%d; "%(i+1)+ |
1013 "init_level=%d; " % (i+1)+ |
1014 "if((res = __init_%s(argc,argv))){"%locstr + |
1014 "if((res = __init_%s(argc,argv))){" % locstr + |
1015 #"printf(\"%s\"); "%locstr + #for debug |
1015 #"printf(\"%s\"); "%locstr + #for debug |
1016 "return res;}" for i,locstr in enumerate(locstrs)]), |
1016 "return res;}" for i,locstr in enumerate(locstrs)]), |
1017 "cleanup_calls":"\n ".join([ |
1017 "cleanup_calls":"\n ".join([ |
1018 "if(init_level >= %d) "%i+ |
1018 "if(init_level >= %d) " % i+ |
1019 "__cleanup_%s();"%locstrs[i-1] for i in xrange(len(locstrs), 0, -1)]) |
1019 "__cleanup_%s();" % locstrs[i-1] for i in xrange(len(locstrs), 0, -1)]) |
1020 } |
1020 } |
1021 else: |
1021 else: |
1022 plc_main_code = targets.GetCode("plc_main_head.c") % { |
1022 plc_main_code = targets.GetCode("plc_main_head.c") % { |
1023 "calls_prototypes":"\n", |
1023 "calls_prototypes":"\n", |
1024 "retrieve_calls":"\n", |
1024 "retrieve_calls":"\n", |
1408 Idx, IEC_Type = self._IECPathToIdx.get(IECPath,(None,None)) |
1408 Idx, IEC_Type = self._IECPathToIdx.get(IECPath,(None,None)) |
1409 if Idx is not None: |
1409 if Idx is not None: |
1410 if IEC_Type in DebugTypesSize: |
1410 if IEC_Type in DebugTypesSize: |
1411 Idxs.append((Idx, IEC_Type, fvalue, IECPath)) |
1411 Idxs.append((Idx, IEC_Type, fvalue, IECPath)) |
1412 else: |
1412 else: |
1413 self.logger.write_warning(_("Debug: Unsupported type to debug '%s'\n")%IEC_Type) |
1413 self.logger.write_warning(_("Debug: Unsupported type to debug '%s'\n") % IEC_Type) |
1414 else: |
1414 else: |
1415 self.logger.write_warning(_("Debug: Unknown variable '%s'\n")%IECPath) |
1415 self.logger.write_warning(_("Debug: Unknown variable '%s'\n") % IECPath) |
1416 for IECPathToPop in IECPathsToPop: |
1416 for IECPathToPop in IECPathsToPop: |
1417 self.IECdebug_datas.pop(IECPathToPop) |
1417 self.IECdebug_datas.pop(IECPathToPop) |
1418 |
1418 |
1419 if Idxs: |
1419 if Idxs: |
1420 Idxs.sort() |
1420 Idxs.sort() |
1726 |
1726 |
1727 # Get connector from uri |
1727 # Get connector from uri |
1728 try: |
1728 try: |
1729 self._SetConnector(connectors.ConnectorFactory(uri, self)) |
1729 self._SetConnector(connectors.ConnectorFactory(uri, self)) |
1730 except Exception, msg: |
1730 except Exception, msg: |
1731 self.logger.write_error(_("Exception while connecting %s!\n")%uri) |
1731 self.logger.write_error(_("Exception while connecting %s!\n") % uri) |
1732 self.logger.write_error(traceback.format_exc()) |
1732 self.logger.write_error(traceback.format_exc()) |
1733 |
1733 |
1734 # Did connection success ? |
1734 # Did connection success ? |
1735 if self._connector is None: |
1735 if self._connector is None: |
1736 # Oups. |
1736 # Oups. |
1737 self.logger.write_error(_("Connection failed to %s!\n")%uri) |
1737 self.logger.write_error(_("Connection failed to %s!\n") % uri) |
1738 else: |
1738 else: |
1739 self.ShowMethod("_Connect", False) |
1739 self.ShowMethod("_Connect", False) |
1740 self.ShowMethod("_Disconnect", True) |
1740 self.ShowMethod("_Disconnect", True) |
1741 self.ShowMethod("_Transfer", True) |
1741 self.ShowMethod("_Transfer", True) |
1742 |
1742 |