133 if path == "BaseParams.IEC_Channel": |
133 if path == "BaseParams.IEC_Channel": |
134 return self.FindNewIEC_Channel(value,logger), True |
134 return self.FindNewIEC_Channel(value,logger), True |
135 elif path == "BaseParams.Name": |
135 elif path == "BaseParams.Name": |
136 res = self.FindNewName(value,logger) |
136 res = self.FindNewName(value,logger) |
137 self.PlugRequestSave() |
137 self.PlugRequestSave() |
138 return res, True |
138 return res, False |
139 |
139 |
140 parts = path.split(".", 1) |
140 parts = path.split(".", 1) |
141 if self.MandatoryParams and parts[0] == self.MandatoryParams[0]: |
141 if self.MandatoryParams and parts[0] == self.MandatoryParams[0]: |
142 self.MandatoryParams[1].setElementValue(parts[1], value) |
142 self.MandatoryParams[1].setElementValue(parts[1], value) |
143 elif self.PlugParams and parts[0] == self.PlugParams[0]: |
143 elif self.PlugParams and parts[0] == self.PlugParams[0]: |
299 """ |
299 """ |
300 return self.PlugParent._GetCurrentName() + self.BaseParams.getName() + "." |
300 return self.PlugParent._GetCurrentName() + self.BaseParams.getName() + "." |
301 |
301 |
302 def GetPlugRoot(self): |
302 def GetPlugRoot(self): |
303 return self.PlugParent.GetPlugRoot() |
303 return self.PlugParent.GetPlugRoot() |
|
304 |
|
305 def GetFullIEC_Channel(self): |
|
306 return ".".join([str(i) for i in self.GetCurrentLocation()]) + ".x" |
|
307 |
|
308 def GetLocations(self): |
|
309 location = self.GetCurrentLocation() |
|
310 return [loc for loc in self.PlugParent.GetLocations() if loc["LOC"][0:len(location)] == location] |
304 |
311 |
305 def GetPlugInfos(self): |
312 def GetPlugInfos(self): |
306 childs = [] |
313 childs = [] |
307 # reorder childs by IEC_channels |
314 # reorder childs by IEC_channels |
308 for child in self.IECSortedChilds(): |
315 for child in self.IECSortedChilds(): |
757 |
764 |
758 def _getIECrawcodepath(self): |
765 def _getIECrawcodepath(self): |
759 # define name for IEC raw code file |
766 # define name for IEC raw code file |
760 return os.path.join(self._getBuildPath(), "raw_plc.st") |
767 return os.path.join(self._getBuildPath(), "raw_plc.st") |
761 |
768 |
|
769 def GetLocations(self): |
|
770 locations = [] |
|
771 filepath = os.path.join(self._getBuildPath(),"LOCATED_VARIABLES.h") |
|
772 if os.path.isfile(filepath): |
|
773 # IEC2C compiler generate a list of located variables : LOCATED_VARIABLES.h |
|
774 location_file = open(os.path.join(self._getBuildPath(),"LOCATED_VARIABLES.h")) |
|
775 # each line of LOCATED_VARIABLES.h declares a located variable |
|
776 lines = [line.strip() for line in location_file.readlines()] |
|
777 # This regular expression parses the lines genereated by IEC2C |
|
778 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]*)\)") |
|
779 for line in lines: |
|
780 # If line match RE, |
|
781 result = LOCATED_MODEL.match(line) |
|
782 if result: |
|
783 # Get the resulting dict |
|
784 resdict = result.groupdict() |
|
785 # rewrite string for variadic location as a tuple of integers |
|
786 resdict['LOC'] = tuple(map(int,resdict['LOC'].split(','))) |
|
787 # set located size to 'X' if not given |
|
788 if not resdict['SIZE']: |
|
789 resdict['SIZE'] = 'X' |
|
790 # finally store into located variable list |
|
791 locations.append(resdict) |
|
792 return locations |
|
793 |
762 def _Generate_SoftPLC(self, logger): |
794 def _Generate_SoftPLC(self, logger): |
763 """ |
795 """ |
764 Generate SoftPLC ST/IL/SFC code out of PLCOpenEditor controller, and compile it with IEC2C |
796 Generate SoftPLC ST/IL/SFC code out of PLCOpenEditor controller, and compile it with IEC2C |
765 @param buildpath: path where files should be created |
797 @param buildpath: path where files should be created |
766 @param logger: the log pseudo file |
798 @param logger: the log pseudo file |
797 C_files.remove("POUS.c") |
829 C_files.remove("POUS.c") |
798 C_files.remove("LOCATED_VARIABLES.h") |
830 C_files.remove("LOCATED_VARIABLES.h") |
799 # transform those base names to full names with path |
831 # transform those base names to full names with path |
800 C_files = map(lambda filename:os.path.join(buildpath, filename), C_files) |
832 C_files = map(lambda filename:os.path.join(buildpath, filename), C_files) |
801 logger.write("Extracting Located Variables...\n") |
833 logger.write("Extracting Located Variables...\n") |
802 # IEC2C compiler generate a list of located variables : LOCATED_VARIABLES.h |
834 # Keep track of generated located variables for later use by self._Generate_C |
803 location_file = open(os.path.join(buildpath,"LOCATED_VARIABLES.h")) |
835 self.PLCGeneratedLocatedVars = self.GetLocations() |
804 locations = [] |
|
805 # each line of LOCATED_VARIABLES.h declares a located variable |
|
806 lines = [line.strip() for line in location_file.readlines()] |
|
807 # This regular expression parses the lines genereated by IEC2C |
|
808 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]*)\)") |
|
809 for line in lines: |
|
810 # If line match RE, |
|
811 result = LOCATED_MODEL.match(line) |
|
812 if result: |
|
813 # Get the resulting dict |
|
814 resdict = result.groupdict() |
|
815 # rewrite string for variadic location as a tuple of integers |
|
816 resdict['LOC'] = tuple(map(int,resdict['LOC'].split(','))) |
|
817 # set located size to 'X' if not given |
|
818 if not resdict['SIZE']: |
|
819 resdict['SIZE'] = 'X' |
|
820 # finally store into located variable list |
|
821 locations.append(resdict) |
|
822 # Keep track of generated C files for later use by self.PlugGenerate_C |
836 # Keep track of generated C files for later use by self.PlugGenerate_C |
823 self.PLCGeneratedCFiles = C_files |
837 self.PLCGeneratedCFiles = C_files |
824 # Keep track of generated located variables for later use by self._Generate_C |
|
825 self.PLCGeneratedLocatedVars = locations |
|
826 # compute CFLAGS for plc |
838 # compute CFLAGS for plc |
827 self.CFLAGS = "\"-I"+ieclib_path+"\"" |
839 self.CFLAGS = "\"-I"+ieclib_path+"\"" |
828 return True |
840 return True |
829 |
841 |
830 def _build(self, logger): |
842 def _build(self, logger): |