plugger.py
changeset 418 01f6bfc01251
parent 415 339fa2542481
child 420 c093ec48f2fd
equal deleted inserted replaced
416:3b3f7f5a8e40 418:01f6bfc01251
   656 if wx.Platform == '__WXMSW__':
   656 if wx.Platform == '__WXMSW__':
   657     exe_ext=".exe"
   657     exe_ext=".exe"
   658 else:
   658 else:
   659     exe_ext=""
   659     exe_ext=""
   660 
   660 
   661 iec2c_path = os.path.join(base_folder, "matiec", "iec2c"+exe_ext)
       
   662 ieclib_path = os.path.join(base_folder, "matiec", "lib")
       
   663 
       
   664 # import for project creation timestamping
   661 # import for project creation timestamping
   665 from threading import Timer, Lock, Thread, Semaphore
   662 from threading import Timer, Lock, Thread, Semaphore
   666 from time import localtime
   663 from time import localtime
   667 from datetime import datetime
   664 from datetime import datetime
   668 # import necessary stuff from PLCOpenEditor
   665 # import necessary stuff from PLCOpenEditor
   746         self.logger = logger
   743         self.logger = logger
   747         self._builder = None
   744         self._builder = None
   748         self._connector = None
   745         self._connector = None
   749         self.Deleting = False
   746         self.Deleting = False
   750         
   747         
       
   748         self.iec2c_path = os.path.join(base_folder, "matiec", "iec2c"+exe_ext)
       
   749         self.ieclib_path = os.path.join(base_folder, "matiec", "lib")
       
   750         
   751         # Setup debug information
   751         # Setup debug information
   752         self.IECdebug_datas = {}
   752         self.IECdebug_datas = {}
   753         self.IECdebug_lock = Lock()
   753         self.IECdebug_lock = Lock()
   754 
   754 
   755         self.DebugTimer=None
   755         self.DebugTimer=None
   792          return self.ChangesToSave or not self.ProjectIsSaved()
   792          return self.ChangesToSave or not self.ProjectIsSaved()
   793 
   793 
   794     def GetPlugRoot(self):
   794     def GetPlugRoot(self):
   795         return self
   795         return self
   796 
   796 
       
   797     def GetIECLibPath(self):
       
   798         return self.ieclib_path
       
   799     
       
   800     def GetIEC2cPath(self):
       
   801         return self.iec2c_path
       
   802     
   797     def GetCurrentLocation(self):
   803     def GetCurrentLocation(self):
   798         return ()
   804         return ()
   799 
   805 
   800     def GetCurrentName(self):
   806     def GetCurrentName(self):
   801         return ""
   807         return ""
  1041         # Now compile IEC code into many C files
  1047         # Now compile IEC code into many C files
  1042         # files are listed to stdout, and errors to stderr. 
  1048         # files are listed to stdout, and errors to stderr. 
  1043         status, result, err_result = ProcessLogger(
  1049         status, result, err_result = ProcessLogger(
  1044                self.logger,
  1050                self.logger,
  1045                "\"%s\" -f -I \"%s\" -T \"%s\" \"%s\""%(
  1051                "\"%s\" -f -I \"%s\" -T \"%s\" \"%s\""%(
  1046                          iec2c_path,
  1052                          self.iec2c_path,
  1047                          ieclib_path, 
  1053                          self.ieclib_path, 
  1048                          buildpath,
  1054                          buildpath,
  1049                          self._getIECcodepath()),
  1055                          self._getIECcodepath()),
  1050                no_stdout=True, no_stderr=True).spin()
  1056                no_stdout=True, no_stderr=True).spin()
  1051         if status:
  1057         if status:
  1052             # Failed !
  1058             # Failed !
  1092         # Keep track of generated located variables for later use by self._Generate_C
  1098         # Keep track of generated located variables for later use by self._Generate_C
  1093         self.PLCGeneratedLocatedVars = self.GetLocations()
  1099         self.PLCGeneratedLocatedVars = self.GetLocations()
  1094         # Keep track of generated C files for later use by self.PlugGenerate_C
  1100         # Keep track of generated C files for later use by self.PlugGenerate_C
  1095         self.PLCGeneratedCFiles = C_files
  1101         self.PLCGeneratedCFiles = C_files
  1096         # compute CFLAGS for plc
  1102         # compute CFLAGS for plc
  1097         self.plcCFLAGS = "\"-I"+ieclib_path+"\""
  1103         self.plcCFLAGS = "\"-I"+self.ieclib_path+"\""
  1098         return True
  1104         return True
  1099 
  1105 
  1100     def GetBuilder(self):
  1106     def GetBuilder(self):
  1101         """
  1107         """
  1102         Return a Builder (compile C code into machine code)
  1108         Return a Builder (compile C code into machine code)
  1259         # Generate main, based on template
  1265         # Generate main, based on template
  1260         if self.BeremizRoot.getEnable_Plugins():
  1266         if self.BeremizRoot.getEnable_Plugins():
  1261             plc_main_code = targets.code("plc_common_main") % {
  1267             plc_main_code = targets.code("plc_common_main") % {
  1262                 "calls_prototypes":"\n".join([(
  1268                 "calls_prototypes":"\n".join([(
  1263                       "int __init_%(s)s(int argc,char **argv);\n"+
  1269                       "int __init_%(s)s(int argc,char **argv);\n"+
  1264                       "void __cleanup_%(s)s();\n"+
  1270                       "void __cleanup_%(s)s(void);\n"+
  1265                       "void __retrieve_%(s)s();\n"+
  1271                       "void __retrieve_%(s)s(void);\n"+
  1266                       "void __publish_%(s)s();")%{'s':locstr} for locstr in locstrs]),
  1272                       "void __publish_%(s)s(void);")%{'s':locstr} for locstr in locstrs]),
  1267                 "retrieve_calls":"\n    ".join([
  1273                 "retrieve_calls":"\n    ".join([
  1268                       "__retrieve_%s();"%locstr for locstr in locstrs]),
  1274                       "__retrieve_%s();"%locstr for locstr in locstrs]),
  1269                 "publish_calls":"\n    ".join([ #Call publish in reverse order
  1275                 "publish_calls":"\n    ".join([ #Call publish in reverse order
  1270                       "__publish_%s();"%locstrs[i-1] for i in xrange(len(locstrs), 0, -1)]),
  1276                       "__publish_%s();"%locstrs[i-1] for i in xrange(len(locstrs), 0, -1)]),
  1271                 "init_calls":"\n    ".join([
  1277                 "init_calls":"\n    ".join([