plugger.py
changeset 64 531e6a834d7e
parent 62 ddf0cdd71558
child 65 e55d6faee9d1
equal deleted inserted replaced
63:bdb196c40619 64:531e6a834d7e
   472 ###################################   ROOT    ######################################
   472 ###################################   ROOT    ######################################
   473 ####################################################################################
   473 ####################################################################################
   474 ####################################################################################
   474 ####################################################################################
   475 ####################################################################################
   475 ####################################################################################
   476 
   476 
   477 iec2cc_path = os.path.join(base_folder, "matiec", "iec2cc")
   477 iec2c_path = os.path.join(base_folder, "matiec", "iec2c")
   478 ieclib_path = os.path.join(base_folder, "matiec", "lib")
   478 ieclib_path = os.path.join(base_folder, "matiec", "lib")
   479 
   479 
   480 # import for project creation timestamping
   480 # import for project creation timestamping
   481 from time import localtime
   481 from time import localtime
   482 from datetime import datetime
   482 from datetime import datetime
   696         # define name for IEC code file
   696         # define name for IEC code file
   697         return os.path.join(self._getBuildPath(), "plc.st")
   697         return os.path.join(self._getBuildPath(), "plc.st")
   698     
   698     
   699     def _Generate_SoftPLC(self, logger):
   699     def _Generate_SoftPLC(self, logger):
   700         """
   700         """
   701         Generate SoftPLC ST/IL/SFC code out of PLCOpenEditor controller, and compile it with IEC2CC
   701         Generate SoftPLC ST/IL/SFC code out of PLCOpenEditor controller, and compile it with IEC2C
   702         @param buildpath: path where files should be created
   702         @param buildpath: path where files should be created
   703         @param logger: the log pseudo file
   703         @param logger: the log pseudo file
   704         """
   704         """
   705 
   705 
   706         # Update PLCOpenEditor Plugin Block types before generate ST code
   706         # Update PLCOpenEditor Plugin Block types before generate ST code
   717             logger.write_error("Error : ST/IL/SFC code generator returned %d\n"%result)
   717             logger.write_error("Error : ST/IL/SFC code generator returned %d\n"%result)
   718             return False
   718             return False
   719         logger.write("Compiling IEC Program in to C code...\n")
   719         logger.write("Compiling IEC Program in to C code...\n")
   720         # Now compile IEC code into many C files
   720         # Now compile IEC code into many C files
   721         # files are listed to stdout, and errors to stderr. 
   721         # files are listed to stdout, and errors to stderr. 
   722         status, result, err_result = logger.LogCommand("%s %s -I %s %s"%(iec2cc_path, plc_file, ieclib_path, buildpath), no_stdout=True)
   722         status, result, err_result = logger.LogCommand("%s %s -I %s %s"%(iec2c_path, plc_file, ieclib_path, buildpath), no_stdout=True)
   723         if status:
   723         if status:
   724             # Failed !
   724             # Failed !
   725             logger.write_error("Error : IEC to C compiler returned %d\n"%status)
   725             logger.write_error("Error : IEC to C compiler returned %d\n"%status)
   726             return False
   726             return False
   727         # Now extract C files of stdout
   727         # Now extract C files of stdout
   730         C_files.remove("POUS.c")
   730         C_files.remove("POUS.c")
   731         C_files.remove("LOCATED_VARIABLES.h")
   731         C_files.remove("LOCATED_VARIABLES.h")
   732         # transform those base names to full names with path
   732         # transform those base names to full names with path
   733         C_files = map(lambda filename:os.path.join(buildpath, filename), C_files)
   733         C_files = map(lambda filename:os.path.join(buildpath, filename), C_files)
   734         logger.write("Extracting Located Variables...\n")
   734         logger.write("Extracting Located Variables...\n")
   735         # IEC2CC compiler generate a list of located variables : LOCATED_VARIABLES.h
   735         # IEC2C compiler generate a list of located variables : LOCATED_VARIABLES.h
   736         location_file = open(os.path.join(buildpath,"LOCATED_VARIABLES.h"))
   736         location_file = open(os.path.join(buildpath,"LOCATED_VARIABLES.h"))
   737         locations = []
   737         locations = []
   738         # each line of LOCATED_VARIABLES.h declares a located variable
   738         # each line of LOCATED_VARIABLES.h declares a located variable
   739         lines = [line.strip() for line in location_file.readlines()]
   739         lines = [line.strip() for line in location_file.readlines()]
   740         # This regular expression parses the lines genereated by IEC2CC
   740         # This regular expression parses the lines genereated by IEC2C
   741         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]*)\)")
   741         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]*)\)")
   742         for line in lines:
   742         for line in lines:
   743             # If line match RE, 
   743             # If line match RE, 
   744             result = LOCATED_MODEL.match(line)
   744             result = LOCATED_MODEL.match(line)
   745             if result:
   745             if result: