--- a/Beremiz.py Fri Aug 31 15:11:30 2007 +0200
+++ b/Beremiz.py Mon Sep 03 17:12:43 2007 +0200
@@ -866,61 +866,6 @@
return (err, outdata, errdata)
- LOCATED_MODEL = re.compile("__LOCATED_VAR\(([A-Z]*),([_A-Za-z0-9]*)\)")
- self.TargetDir = os.path.join(self.CurrentProjectPath, "build")
- if not os.path.exists(self.TargetDir):
- os.mkdir(self.TargetDir)
- self.Log.write("Generating IEC-61131 code...\n")
- plc_file = os.path.join(self.TargetDir, "plc.st")
- result = self.PLCManager.GenerateProgram(plc_file)
- raise Exception, "Error : ST/IL/SFC code generator returned %d"%result
- self.Log.write("Compiling ST Program in to C Program...\n")
- status, result, err_result = self.LogCommand("%s %s -I %s %s"%(iec2cc_path, plc_file, ieclib_path, self.TargetDir))
- new_dialog = wx.Frame(None)
- ST_viewer = TextViewer(new_dialog, None, None)
- #ST_viewer.Enable(False)
- ST_viewer.SetKeywords(IEC_KEYWORDS)
- ST_viewer.SetText(file(plc_file).read())
- raise Exception, "Error : IEC to C compiler returned %d"%status
- C_files = result.splitlines()
- C_files.remove("POUS.c")
- C_files = map(lambda filename:os.path.join(self.TargetDir, filename), C_files)
- self.Log.write("Extracting Located Variables...\n")
- location_file = open(os.path.join(self.TargetDir,"LOCATED_VARIABLES.h"))
- lines = [line.strip() for line in location_file.readlines()]
- result = LOCATED_MODEL.match(line)
- locations.append(result.groups())
- self.Log.write("Generating Network Configurations...\n")
- for bus_id, bus_infos in self.BusManagers.items():
- if bus_infos["Manager"]:
- c_filename = "%s.c"%os.path.join(self.TargetDir, gen_cfile.FormatName(bus_infos["Name"]))
- result = bus_infos["Manager"].GenerateBus(c_filename, locations)
- C_files.append(c_filename)
- self.Log.write("Generating Makefiles...\n")
- self.Log.write(str(C_files))
- self.Log.write("Compiling Project...\n")
- self.Log.write("\nBuild Project completed\n")
- except Exception, message:
- self.Log.write_error("\nBuild Failed\n")
- self.Log.write(str(message))
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
--- a/plugger.py Fri Aug 31 15:11:30 2007 +0200
+++ b/plugger.py Mon Sep 03 17:12:43 2007 +0200
@@ -117,22 +117,24 @@
shutil.copytree(src_PlugPath, self.PlugPath)
- def PlugGenerate_C(self, buildpath, current_location, locations):
+ def PlugGenerate_C(self, buildpath, current_location, locations, logger): @param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5)
@param locations: List of complete variables locations \
[(IEC_loc, IEC_Direction, IEC_Type, Name)]\
ex: [((0,0,4,5),'I','STRING','__IX_0_0_4_5'),...]
+ @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND + logger.write_warning(".".join(map(lambda x:str(x), current_location)) + " -> Nothing yo do") - def _Generate_C(self, buildpath, current_location, locations):
+ def _Generate_C(self, buildpath, current_location, locations, logger): # Generate plugins [(Cfiles, CFLAGS)], LDFLAGS
- PlugCFilesAndCFLAGS, PlugLDFLAGS = self.PlugGenerate_C(buildpath, current_location, locations)
+ PlugCFilesAndCFLAGS, PlugLDFLAGS = self.PlugGenerate_C(buildpath, current_location, locations, logger) # recurse through all childs, and stack their results
for PlugChild in self.IterChilds():
- # Compute chile IEC location
+ # Compute child's IEC location new_location = current_location + (self.BaseParams.getIEC_Channel())
# Get childs [(Cfiles, CFLAGS)], LDFLAGS
CFilesAndCFLAGS, LDFLAGS = \
@@ -142,7 +144,9 @@
# but update location (add curent IEC channel at the end)
# filter locations that start with current IEC location
- [ (l,d,t,n) for l,d,t,n in locations if l[0:len(new_location)] == new_location ])
+ [ (l,d,t,n) for l,d,t,n in locations if l[0:len(new_location)] == new_location ], PlugCFilesAndCFLAGS += CFilesAndCFLAGS
@@ -519,3 +523,89 @@
def PluginXmlFilePath(self, PlugName=None):
return os.path.join(self.PlugPath(PlugName), "beremiz.xml")
+ def PlugGenerate_C(self, buildpath, current_location, locations, logger): + @param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5) + @param locations: List of complete variables locations \ + [(IEC_loc, IEC_Direction, IEC_Type, Name)]\ + ex: [((0,0,4,5),'I','STRING','__IX_0_0_4_5'),...] + @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND + return [(C_file_name, "") for C_file_name in self.PLCGeneratedCFiles ] , "" + def _Generate_SoftPLC(self, buildpath, logger): + LOCATED_MODEL = re.compile("__LOCATED_VAR\((?P<IEC_TYPE>[A-Z]*),(?P<NAME>[_A-Za-z0-9]*),(?P<DIR>[QMI])(?:,(?P<SIZE>[XBWD]))?,(?P<LOC>[,0-9]*)\)") + logger.write("Generating SoftPLC IEC-61131 ST/IL/SFC code...\n") + plc_file = os.path.join(self.TargetDir, "plc.st") + result = self.PLCManager.GenerateProgram(plc_file) + logger.write_error("Error : ST/IL/SFC code generator returned %d"%result) + logger.write("Compiling ST Program in to C Program...\n") + status, result, err_result = self.LogCommand("%s %s -I %s %s"%(iec2cc_path, plc_file, ieclib_path, self.TargetDir)) + new_dialog = wx.Frame(None) + ST_viewer = TextViewer(new_dialog, None, None) + #ST_viewer.Enable(False) + ST_viewer.SetKeywords(IEC_KEYWORDS) + ST_viewer.SetText(file(plc_file).read()) + raise Exception, "Error : IEC to C compiler returned %d"%status + C_files = result.splitlines() + C_files.remove("POUS.c") + C_files = map(lambda filename:os.path.join(self.TargetDir, filename), C_files) + logger.write("Extracting Located Variables...\n") + location_file = open(os.path.join(self.TargetDir,"LOCATED_VARIABLES.h")) + lines = [line.strip() for line in location_file.readlines()] + result = LOCATED_MODEL.match(line) + resdict = result.groupdict() + # rewrite location as a tuple of integers + resdict['LOC'] = tuple(map(int,resdict['LOC'].split(','))) + if not resdict['SIZE']: + locations.append(resdict) + self.PLCGeneratedCFiles = C_files + self.PLCGeneratedLocatedVars = locations + def _build(self, logger): + buildpath = os.path.join(self.ProjectPath, "build") + if not os.path.exists(buildpath): + logger.write("Start build in %s" % buildpath) + if not self._Generate_SoftPLC(buildpath, logger): + logger.write("SoftPLC code generation failed !") + logger.write("SoftPLC code generation successfull") + CFilesAndCFLAGS, LDFLAGS = self._Generate_C( + self.PLCGeneratedLocatedVars, + logger.write_error("Plugins code generation Failed !") + logger.write_error(str(msg)) + logger.write_error("Plugins code generation successfull") + for CFile, CFLAG in CFilesAndCFLAGS: + PluginMethods = [("Build",_build), ("Clean",None), ("Run",None), ("EditPLC",None), ("Simulate",None)] --- a/plugins/canfestival/canfestival.py Fri Aug 31 15:11:30 2007 +0200
+++ b/plugins/canfestival/canfestival.py Mon Sep 03 17:12:43 2007 +0200
@@ -28,7 +28,7 @@
self.LoadProject(self.PlugPath())
+ def _OpenView(self, logger): @@ -48,7 +48,7 @@
- def PlugGenerate_C(self, buildpath, current_location, locations):
+ def PlugGenerate_C(self, buildpath, current_location, locations, logger): @param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5)