864 self.Log.write_error("Output size reached limit -- killed\n") |
864 self.Log.write_error("Output size reached limit -- killed\n") |
865 break |
865 break |
866 err = child.wait() |
866 err = child.wait() |
867 return (err, outdata, errdata) |
867 return (err, outdata, errdata) |
868 |
868 |
869 def BuildAutom(self): |
|
870 LOCATED_MODEL = re.compile("__LOCATED_VAR\(([A-Z]*),([_A-Za-z0-9]*)\)") |
|
871 |
|
872 if self.PLCManager: |
|
873 self.TargetDir = os.path.join(self.CurrentProjectPath, "build") |
|
874 if not os.path.exists(self.TargetDir): |
|
875 os.mkdir(self.TargetDir) |
|
876 self.Log.flush() |
|
877 try: |
|
878 self.Log.write("Generating IEC-61131 code...\n") |
|
879 plc_file = os.path.join(self.TargetDir, "plc.st") |
|
880 result = self.PLCManager.GenerateProgram(plc_file) |
|
881 if not result: |
|
882 raise Exception, "Error : ST/IL/SFC code generator returned %d"%result |
|
883 self.Log.write("Compiling ST Program in to C Program...\n") |
|
884 status, result, err_result = self.LogCommand("%s %s -I %s %s"%(iec2cc_path, plc_file, ieclib_path, self.TargetDir)) |
|
885 if status: |
|
886 new_dialog = wx.Frame(None) |
|
887 ST_viewer = TextViewer(new_dialog, None, None) |
|
888 #ST_viewer.Enable(False) |
|
889 ST_viewer.SetKeywords(IEC_KEYWORDS) |
|
890 ST_viewer.SetText(file(plc_file).read()) |
|
891 new_dialog.Show() |
|
892 raise Exception, "Error : IEC to C compiler returned %d"%status |
|
893 C_files = result.splitlines() |
|
894 C_files.remove("POUS.c") |
|
895 C_files = map(lambda filename:os.path.join(self.TargetDir, filename), C_files) |
|
896 self.Log.write("Extracting Located Variables...\n") |
|
897 location_file = open(os.path.join(self.TargetDir,"LOCATED_VARIABLES.h")) |
|
898 locations = [] |
|
899 lines = [line.strip() for line in location_file.readlines()] |
|
900 for line in lines: |
|
901 result = LOCATED_MODEL.match(line) |
|
902 if result: |
|
903 locations.append(result.groups()) |
|
904 self.Log.write("Generating Network Configurations...\n") |
|
905 for bus_id, bus_infos in self.BusManagers.items(): |
|
906 if bus_infos["Manager"]: |
|
907 c_filename = "%s.c"%os.path.join(self.TargetDir, gen_cfile.FormatName(bus_infos["Name"])) |
|
908 result = bus_infos["Manager"].GenerateBus(c_filename, locations) |
|
909 if result: |
|
910 raise Exception |
|
911 else: |
|
912 C_files.append(c_filename) |
|
913 self.Log.write("Generating Makefiles...\n") |
|
914 self.Log.write(str(C_files)) |
|
915 |
|
916 self.Log.write("Compiling Project...\n") |
|
917 |
|
918 self.Log.write("\nBuild Project completed\n") |
|
919 except Exception, message: |
|
920 self.Log.write_error("\nBuild Failed\n") |
|
921 self.Log.write(str(message)) |
|
922 pass |
|
923 |
|
924 #------------------------------------------------------------------------------- |
869 #------------------------------------------------------------------------------- |
925 # Add Bus Dialog |
870 # Add Bus Dialog |
926 #------------------------------------------------------------------------------- |
871 #------------------------------------------------------------------------------- |
927 |
872 |
928 [ID_ADDBUSDIALOG, ID_ADDBUSDIALOGBUSID, |
873 [ID_ADDBUSDIALOG, ID_ADDBUSDIALOGBUSID, |