py_ext/py_ext.py
changeset 1730 64d8f52bc8c8
parent 1680 6db967480b7d
child 1736 7e61baa047f0
equal deleted inserted replaced
1726:d51af006fa6b 1730:64d8f52bc8c8
    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 class PythonLibrary(POULibrary):
    31 class PythonLibrary(POULibrary):
    32     def GetLibraryPath(self):
    32     def GetLibraryPath(self):
    33         return paths.AbsNeighbourFile(__file__, "pous.xml") 
    33         return paths.AbsNeighbourFile(__file__, "pous.xml")
    34 
    34 
    35     def Generate_C(self, buildpath, varlist, IECCFLAGS):
    35     def Generate_C(self, buildpath, varlist, IECCFLAGS):
    36         
    36 
    37         plc_python_filepath = paths.AbsNeighbourFile(__file__, "plc_python.c")
    37         plc_python_filepath = paths.AbsNeighbourFile(__file__, "plc_python.c")
    38         plc_python_file = open(plc_python_filepath, 'r')
    38         plc_python_file = open(plc_python_filepath, 'r')
    39         plc_python_code = plc_python_file.read()
    39         plc_python_code = plc_python_file.read()
    40         plc_python_file.close()
    40         plc_python_file.close()
    41         python_eval_fb_list = []
    41         python_eval_fb_list = []
    42         for v in varlist:
    42         for v in varlist:
    43             if v["vartype"] == "FB" and v["type"] in ["PYTHON_EVAL",
    43             if v["vartype"] == "FB" and v["type"] in ["PYTHON_EVAL",
    44                                                       "PYTHON_POLL"]:
    44                                                       "PYTHON_POLL"]:
    45                 python_eval_fb_list.append(v)
    45                 python_eval_fb_list.append(v)
    46         python_eval_fb_count = max(1, len(python_eval_fb_list))
    46         python_eval_fb_count = max(1, len(python_eval_fb_list))
    47         
    47 
    48         # prepare python code
    48         # prepare python code
    49         plc_python_code = plc_python_code % {
    49         plc_python_code = plc_python_code % {
    50             "python_eval_fb_count": python_eval_fb_count }
    50             "python_eval_fb_count": python_eval_fb_count }
    51         
    51 
    52         Gen_Pythonfile_path = os.path.join(buildpath, "py_ext.c")
    52         Gen_Pythonfile_path = os.path.join(buildpath, "py_ext.c")
    53         pythonfile = open(Gen_Pythonfile_path,'w')
    53         pythonfile = open(Gen_Pythonfile_path,'w')
    54         pythonfile.write(plc_python_code)
    54         pythonfile.write(plc_python_code)
    55         pythonfile.close()
    55         pythonfile.close()
    56         
    56 
    57         return (["py_ext"], [(Gen_Pythonfile_path, IECCFLAGS)], True), ""
    57         return (["py_ext"], [(Gen_Pythonfile_path, IECCFLAGS)], True), ""
    58 
    58 
    59 class PythonFile(PythonFileCTNMixin):
    59 class PythonFile(PythonFileCTNMixin):
    60     
    60 
    61     def GetIconName(self):
    61     def GetIconName(self):
    62         return "Pyfile"
    62         return "Pyfile"
    63     
       
    64