29 |
29 |
30 import os, re, platform, sys, time, traceback, getopt, commands |
30 import os, re, platform, sys, time, traceback, getopt, commands |
31 base_folder = os.path.split(sys.path[0])[0] |
31 base_folder = os.path.split(sys.path[0])[0] |
32 sys.path.append(os.path.join(base_folder, "plcopeneditor")) |
32 sys.path.append(os.path.join(base_folder, "plcopeneditor")) |
33 sys.path.append(os.path.join(base_folder, "CanFestival-3", "objdictgen")) |
33 sys.path.append(os.path.join(base_folder, "CanFestival-3", "objdictgen")) |
|
34 sys.path.append(os.path.join(base_folder, "wxsvg", "svgui", "defeditor")) |
34 |
35 |
35 iec2cc_path = os.path.join(base_folder, "matiec", "iec2cc") |
36 iec2cc_path = os.path.join(base_folder, "matiec", "iec2cc") |
36 ieclib_path = os.path.join(base_folder, "matiec", "lib") |
37 ieclib_path = os.path.join(base_folder, "matiec", "lib") |
37 |
38 |
38 from PLCOpenEditor import PLCOpenEditor, ProjectDialog |
39 from PLCOpenEditor import PLCOpenEditor, ProjectDialog |
39 from TextViewer import TextViewer |
40 from TextViewer import TextViewer |
40 from plcopen.structures import IEC_KEYWORDS, AddPlugin |
41 from plcopen.structures import IEC_KEYWORDS#, AddPlugin |
41 from PLCControler import PLCControler |
42 from PLCControler import PLCControler |
42 |
43 |
43 import plugins |
44 import plugins |
44 |
45 |
45 __version__ = "$Revision$" |
46 __version__ = "$Revision$" |
331 def __init__(self, parent): |
332 def __init__(self, parent): |
332 self._init_ctrls(parent) |
333 self._init_ctrls(parent) |
333 |
334 |
334 for name in plugins.__all__: |
335 for name in plugins.__all__: |
335 module = getattr(plugins, name) |
336 module = getattr(plugins, name) |
336 if len(module.BlockList) > 0: |
337 |
337 function = module.GetBlockGenerationFunction(self) |
338 #AddPlugin(module.GetBlockGenerationFunction(self)) |
338 blocklist = module.BlockList |
|
339 for blocktype in blocklist["list"]: |
|
340 blocktype["generate"] = function |
|
341 AddPlugin(module.BlockList) |
|
342 |
339 |
343 self.CurrentProjectPath = "" |
340 self.CurrentProjectPath = "" |
344 |
341 |
345 self.PLCManager = None |
342 self.PLCManager = None |
346 self.PLCEditor = None |
343 self.PLCEditor = None |
662 outlen = errlen = 0 |
659 outlen = errlen = 0 |
663 while 1: |
660 while 1: |
664 ready = select.select([outfd,errfd],[],[]) # wait for input |
661 ready = select.select([outfd,errfd],[],[]) # wait for input |
665 if outfd in ready[0]: |
662 if outfd in ready[0]: |
666 outchunk = outfile.readline() |
663 outchunk = outfile.readline() |
667 if outchunk == '': outeof = 1 |
664 if outchunk == '': outeof = 1 |
|
665 else : outlen += 1 |
668 outdata += outchunk |
666 outdata += outchunk |
669 outlen += 1 |
|
670 self.Log.write(outchunk) |
667 self.Log.write(outchunk) |
671 if errfd in ready[0]: |
668 if errfd in ready[0]: |
672 errchunk = errfile.readline() |
669 errchunk = errfile.readline() |
673 if errchunk == '': erreof = 1 |
670 if errchunk == '': erreof = 1 |
|
671 else : errlen += 1 |
674 errdata += errchunk |
672 errdata += errchunk |
675 errlen += 1 |
|
676 self.Log.write_warning(errchunk) |
673 self.Log.write_warning(errchunk) |
677 if outeof and erreof : break |
674 if outeof and erreof : break |
678 if errlen > sz_limit or outlen > sz_limit : |
675 if errlen > sz_limit or outlen > sz_limit : |
679 os.kill(child.pid, signal.SIGTERM) |
676 os.kill(child.pid, signal.SIGTERM) |
680 self.Log.write_error("Output size reached limit -- killed\n") |
677 self.Log.write_error("Output size reached limit -- killed\n") |
703 #ST_viewer.Enable(False) |
700 #ST_viewer.Enable(False) |
704 ST_viewer.SetKeywords(IEC_KEYWORDS) |
701 ST_viewer.SetKeywords(IEC_KEYWORDS) |
705 ST_viewer.SetText(file(plc_file).read()) |
702 ST_viewer.SetText(file(plc_file).read()) |
706 new_dialog.Show() |
703 new_dialog.Show() |
707 raise Exception, "Error : IEC to C compiler returned %d"%status |
704 raise Exception, "Error : IEC to C compiler returned %d"%status |
|
705 C_files = result.splitlines() |
|
706 C_files.remove("POUS.c") |
|
707 C_files = map(lambda filename:os.path.join(self.TargetDir, filename), C_files) |
708 self.Log.write("Extracting Located Variables...\n") |
708 self.Log.write("Extracting Located Variables...\n") |
709 location_file = open(os.path.join(self.TargetDir,"LOCATED_VARIABLES.h")) |
709 location_file = open(os.path.join(self.TargetDir,"LOCATED_VARIABLES.h")) |
710 locations = [] |
710 locations = [] |
711 lines = [line.strip() for line in location_file.readlines()] |
711 lines = [line.strip() for line in location_file.readlines()] |
712 for line in lines: |
712 for line in lines: |
713 result = LOCATED_MODEL.match(line) |
713 result = LOCATED_MODEL.match(line) |
714 if result: |
714 if result: |
715 locations.append(result.groups()) |
715 locations.append(result.groups()) |
716 self.Log.write("Generating Network Configurations...\n") |
716 self.Log.write("Generating Network Configurations...\n") |
717 for bus_id, bus_infos in self.BusManagers.items(): |
717 for bus_id, bus_infos in self.BusManagers.items(): |
718 if bus_infos["Manager"]: |
718 if bus_infos["Manager"]: |
719 filepath = "%s.c"%os.path.join(self.TargetDir, gen_cfile.FormatName(bus_infos["Name"])) |
719 c_filename = "%s.c"%os.path.join(self.TargetDir, gen_cfile.FormatName(bus_infos["Name"])) |
720 result = bus_infos["Manager"].GenerateBus(filepath, bus_id, locations) |
720 result = bus_infos["Manager"].GenerateBus(c_filename, locations) |
721 if result: |
721 if result: |
722 raise Exception, "Bus with id \"0x%2.2X\" can't be generated!"%bus_id |
722 raise Exception |
|
723 else: |
|
724 C_files.append(c_filename) |
723 self.Log.write("Generating Makefiles...\n") |
725 self.Log.write("Generating Makefiles...\n") |
|
726 self.Log.write(str(C_files)) |
724 |
727 |
725 self.Log.write("Compiling Project...\n") |
728 self.Log.write("Compiling Project...\n") |
726 |
729 |
727 self.Log.write("\nBuild Project completed\n") |
730 self.Log.write("\nBuild Project completed\n") |
728 except Exception, message: |
731 except Exception, message: |