6 def GetLibraryPath(self): |
6 def GetLibraryPath(self): |
7 return os.path.join(os.path.split(__file__)[0], "pous.xml") |
7 return os.path.join(os.path.split(__file__)[0], "pous.xml") |
8 |
8 |
9 def Generate_C(self, buildpath, varlist, IECCFLAGS): |
9 def Generate_C(self, buildpath, varlist, IECCFLAGS): |
10 |
10 |
11 plc_python_filepath = os.path.join(os.path.split(__file__)[0], "plc_python.c") |
11 plc_python_filepath = os.path.join( |
|
12 os.path.split(__file__)[0], "plc_python.c") |
12 plc_python_file = open(plc_python_filepath, 'r') |
13 plc_python_file = open(plc_python_filepath, 'r') |
13 plc_python_code = plc_python_file.read() |
14 plc_python_code = plc_python_file.read() |
14 plc_python_file.close() |
15 plc_python_file.close() |
15 python_eval_fb_list = [] |
16 python_eval_fb_list = [] |
16 for v in varlist: |
17 for v in varlist: |
17 if v["vartype"] == "FB" and v["type"] in ["PYTHON_EVAL","PYTHON_POLL"]: |
18 if v["vartype"] == "FB" and v["type"] in ["PYTHON_EVAL", |
|
19 "PYTHON_POLL"]: |
18 python_eval_fb_list.append(v) |
20 python_eval_fb_list.append(v) |
19 python_eval_fb_count = max(1, len(python_eval_fb_list)) |
21 python_eval_fb_count = max(1, len(python_eval_fb_list)) |
20 |
22 |
21 # prepare python code |
23 # prepare python code |
22 plc_python_code = plc_python_code % { "python_eval_fb_count": python_eval_fb_count } |
24 plc_python_code = plc_python_code % { |
|
25 "python_eval_fb_count": python_eval_fb_count } |
23 |
26 |
24 Gen_Pythonfile_path = os.path.join(buildpath, "py_ext.c") |
27 Gen_Pythonfile_path = os.path.join(buildpath, "py_ext.c") |
25 pythonfile = open(Gen_Pythonfile_path,'w') |
28 pythonfile = open(Gen_Pythonfile_path,'w') |
26 pythonfile.write(plc_python_code) |
29 pythonfile.write(plc_python_code) |
27 pythonfile.close() |
30 pythonfile.close() |
31 class PythonFile(PythonFileCTNMixin): |
34 class PythonFile(PythonFileCTNMixin): |
32 |
35 |
33 def GetIconName(self): |
36 def GetIconName(self): |
34 return "Pyfile" |
37 return "Pyfile" |
35 |
38 |
36 def CTNGenerate_C(self, buildpath, locations): |
|
37 current_location = self.GetCurrentLocation() |
|
38 # define a unique name for the generated C file |
|
39 location_str = "_".join(map(lambda x:str(x), current_location)) |
|
40 |
|
41 runtimefile_path = os.path.join(buildpath, "runtime_%s.py"%location_str) |
|
42 runtimefile = open(runtimefile_path, 'w') |
|
43 runtimefile.write(self.GetPythonCode()) |
|
44 runtimefile.close() |
|
45 |
|
46 return [], "", False, ("runtime_%s.py"%location_str, file(runtimefile_path,"rb")) |
|
47 |
39 |