655 import targets |
655 import targets |
656 import connectors |
656 import connectors |
657 from discovery import DiscoveryDialog |
657 from discovery import DiscoveryDialog |
658 from weakref import WeakKeyDictionary |
658 from weakref import WeakKeyDictionary |
659 |
659 |
|
660 MATIEC_ERROR_MODEL = re.compile(".*\.st:(\d+)-(\d+)\.\.(\d+)-(\d+): error : (.*)$") |
|
661 |
660 class PluginsRoot(PlugTemplate, PLCControler): |
662 class PluginsRoot(PlugTemplate, PLCControler): |
661 """ |
663 """ |
662 This class define Root object of the plugin tree. |
664 This class define Root object of the plugin tree. |
663 It is responsible of : |
665 It is responsible of : |
664 - Managing project directory |
666 - Managing project directory |
947 plc_file.write(child.STLibraryFactory()) |
949 plc_file.write(child.STLibraryFactory()) |
948 plc_file.write("\n") |
950 plc_file.write("\n") |
949 if os.path.isfile(self._getIECrawcodepath()): |
951 if os.path.isfile(self._getIECrawcodepath()): |
950 plc_file.write(open(self._getIECrawcodepath(), "r").read()) |
952 plc_file.write(open(self._getIECrawcodepath(), "r").read()) |
951 plc_file.write("\n") |
953 plc_file.write("\n") |
|
954 plc_file.close() |
|
955 plc_file = open(self._getIECcodepath(), "r") |
|
956 self.ProgramOffset = 0 |
|
957 for line in plc_file.xreadlines(): |
|
958 self.ProgramOffset += 1 |
|
959 plc_file.close() |
|
960 plc_file = open(self._getIECcodepath(), "a") |
952 plc_file.write(open(self._getIECgeneratedcodepath(), "r").read()) |
961 plc_file.write(open(self._getIECgeneratedcodepath(), "r").read()) |
953 plc_file.close() |
962 plc_file.close() |
954 self.logger.write("Compiling IEC Program in to C code...\n") |
963 self.logger.write("Compiling IEC Program in to C code...\n") |
955 # Now compile IEC code into many C files |
964 # Now compile IEC code into many C files |
956 # files are listed to stdout, and errors to stderr. |
965 # files are listed to stdout, and errors to stderr. |
959 "\"%s\" -f -I \"%s\" -T \"%s\" \"%s\""%( |
968 "\"%s\" -f -I \"%s\" -T \"%s\" \"%s\""%( |
960 iec2c_path, |
969 iec2c_path, |
961 ieclib_path, |
970 ieclib_path, |
962 buildpath, |
971 buildpath, |
963 self._getIECcodepath()), |
972 self._getIECcodepath()), |
964 no_stdout=True).spin() |
973 no_stdout=True, no_stderr=True).spin() |
965 if status: |
974 if status: |
966 # Failed ! |
975 # Failed ! |
|
976 |
|
977 # parse iec2c's error message. if it contains a line number, |
|
978 # then print those lines from the generated IEC file. |
|
979 for err_line in err_result.split('\n'): |
|
980 self.logger.write_warning(err_line + "\n") |
|
981 |
|
982 m_result = MATIEC_ERROR_MODEL.match(err_line) |
|
983 if m_result is not None: |
|
984 first_line, first_column, last_line, last_column, error = m_result.groups() |
|
985 first_line, last_line = int(first_line), int(last_line) |
|
986 |
|
987 last_section = None |
|
988 f = open(self._getIECcodepath()) |
|
989 |
|
990 for i, line in enumerate(f.readlines()): |
|
991 if line[0] not in '\t \r\n': |
|
992 last_section = line |
|
993 |
|
994 if first_line <= i <= last_line: |
|
995 if last_section is not None: |
|
996 self.logger.write_warning("In section: " + last_section) |
|
997 last_section = None # only write section once |
|
998 self.logger.write_warning("%04d: %s" % (i, line)) |
|
999 |
|
1000 f.close() |
|
1001 |
967 self.logger.write_error("Error : IEC to C compiler returned %d\n"%status) |
1002 self.logger.write_error("Error : IEC to C compiler returned %d\n"%status) |
968 return False |
1003 return False |
|
1004 |
969 # Now extract C files of stdout |
1005 # Now extract C files of stdout |
970 C_files = [ fname for fname in result.splitlines() if fname[-2:]==".c" or fname[-2:]==".C" ] |
1006 C_files = [ fname for fname in result.splitlines() if fname[-2:]==".c" or fname[-2:]==".C" ] |
971 # remove those that are not to be compiled because included by others |
1007 # remove those that are not to be compiled because included by others |
972 C_files.remove("POUS.c") |
1008 C_files.remove("POUS.c") |
973 if not C_files: |
1009 if not C_files: |