py_ext/py_ext.py
changeset 1784 64beb9e9c749
parent 1746 45d6f5fba016
child 1853 47a3f39bead0
equal deleted inserted replaced
1729:31e63e25b4cc 1784:64beb9e9c749
    26 import os
    26 import os
    27 from POULibrary import POULibrary
    27 from POULibrary import POULibrary
    28 from PythonFileCTNMixin import PythonFileCTNMixin
    28 from PythonFileCTNMixin import PythonFileCTNMixin
    29 import util.paths as paths
    29 import util.paths as paths
    30 
    30 
       
    31 
    31 class PythonLibrary(POULibrary):
    32 class PythonLibrary(POULibrary):
    32     def GetLibraryPath(self):
    33     def GetLibraryPath(self):
    33         return paths.AbsNeighbourFile(__file__, "pous.xml") 
    34         return paths.AbsNeighbourFile(__file__, "pous.xml")
    34 
    35 
    35     def Generate_C(self, buildpath, varlist, IECCFLAGS):
    36     def Generate_C(self, buildpath, varlist, IECCFLAGS):
    36         
    37 
    37         plc_python_filepath = paths.AbsNeighbourFile(__file__, "plc_python.c")
    38         plc_python_filepath = paths.AbsNeighbourFile(__file__, "plc_python.c")
    38         plc_python_file = open(plc_python_filepath, 'r')
    39         plc_python_file = open(plc_python_filepath, 'r')
    39         plc_python_code = plc_python_file.read()
    40         plc_python_code = plc_python_file.read()
    40         plc_python_file.close()
    41         plc_python_file.close()
    41         python_eval_fb_list = []
    42         python_eval_fb_list = []
    42         for v in varlist:
    43         for v in varlist:
    43             if v["vartype"] == "FB" and v["type"] in ["PYTHON_EVAL",
    44             if v["vartype"] == "FB" and v["type"] in ["PYTHON_EVAL",
    44                                                       "PYTHON_POLL"]:
    45                                                       "PYTHON_POLL"]:
    45                 python_eval_fb_list.append(v)
    46                 python_eval_fb_list.append(v)
    46         python_eval_fb_count = max(1, len(python_eval_fb_list))
    47         python_eval_fb_count = max(1, len(python_eval_fb_list))
    47         
    48 
    48         # prepare python code
    49         # prepare python code
    49         plc_python_code = plc_python_code % {
    50         plc_python_code = plc_python_code % {
    50             "python_eval_fb_count": python_eval_fb_count }
    51             "python_eval_fb_count": python_eval_fb_count}
    51         
    52 
    52         Gen_Pythonfile_path = os.path.join(buildpath, "py_ext.c")
    53         Gen_Pythonfile_path = os.path.join(buildpath, "py_ext.c")
    53         pythonfile = open(Gen_Pythonfile_path,'w')
    54         pythonfile = open(Gen_Pythonfile_path, 'w')
    54         pythonfile.write(plc_python_code)
    55         pythonfile.write(plc_python_code)
    55         pythonfile.close()
    56         pythonfile.close()
    56         
    57 
    57         return (["py_ext"], [(Gen_Pythonfile_path, IECCFLAGS)], True), ""
    58         return (["py_ext"], [(Gen_Pythonfile_path, IECCFLAGS)], True), ""
    58 
    59 
       
    60 
    59 class PythonFile(PythonFileCTNMixin):
    61 class PythonFile(PythonFileCTNMixin):
    60     
    62 
    61     def GetIconName(self):
    63     def GetIconName(self):
    62         return "Pyfile"
    64         return "Pyfile"
    63     
       
    64