def CTNGenerate_C(self, buildpath, locations): """ Return C code generated by iec2c compiler when _generate_softPLC have been called @param locations: ignored @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND """ current_location = self.GetCurrentLocation() # define a unique name for the generated C file location_str = "_".join(map(lambda x:str(x), current_location)) res = ([], "", False) svgfile=self._getSVGpath() if os.path.exists(svgfile): res += (("gui.svg", file(svgfile,"rb")),) svguiserverfile = open(self._getSVGUIserverpath(), 'r') svguiservercode = svguiserverfile.read() svguiserverfile.close() svguilibpath = os.path.join(self._getBuildPath(), "svguilib.js") svguilibfile = open(svguilibpath, 'w') fpath=paths.AbsDir(__file__) svguilibfile.write(translate(os.path.join(fpath, "pyjs", "lib", "sys.py"), "sys")) svguilibfile.write(open(os.path.join(fpath, "pyjs", "lib", "_pyjs.js"), 'r').read()) svguilibfile.write(translate(os.path.join(fpath, "pyjs", "lib", "pyjslib.py"), "pyjslib")) svguilibfile.write(translate(os.path.join(fpath, "svguilib.py"), "svguilib")) svguilibfile.write("pyjslib();\nsvguilib();\n") svguilibfile.write(open(os.path.join(fpath, "pyjs", "lib", "json.js"), 'r').read()) svguilibfile.write(open(os.path.join(fpath, "livesvg.js"), 'r').read()) svguilibfile.close() jsmodules = {"LiveSVGPage": "svguilib.js"} res += (("svguilib.js", file(svguilibpath,"rb")),) runtimefile_path = os.path.join(buildpath, "runtime_%s.py"%location_str) runtimefile = open(runtimefile_path, 'w') runtimefile.write(svguiservercode % {"svgfile" : "gui.svg"}) runtimefile.write(""" def _runtime_%(location)s_start(): website.LoadHMI(%(svgui_class)s, %(jsmodules)s) def _runtime_%(location)s_stop(): website.UnLoadHMI() """ % {"location": location_str, "svgui_class": "SVGUI_HMI", "jsmodules" : str(jsmodules), }) runtimefile.close() res += (("runtime_%s.py"%location_str, file(runtimefile_path,"rb")),) return res
def CTNGenerate_C(self, buildpath, locations): """ Return C code generated by iec2c compiler when _generate_softPLC have been called @param locations: ignored @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND """ current_location = self.GetCurrentLocation() # define a unique name for the generated C file location_str = "_".join(map(lambda x:str(x), current_location)) res = ([], "", False) svgfile=self._getSVGpath() if os.path.exists(svgfile): res += (("gui.svg", file(svgfile,"rb")),) svguiserverfile = open(self._getSVGUIserverpath(), 'r') svguiservercode = svguiserverfile.read() svguiserverfile.close() svguilibpath = os.path.join(self._getBuildPath(), "svguilib.js") svguilibfile = open(svguilibpath, 'w') svguilibfile.write(translate(os.path.join(os.path.dirname(__file__), "pyjs", "lib", "sys.py"), "sys")) svguilibfile.write(open(os.path.join(os.path.dirname(__file__), "pyjs", "lib", "_pyjs.js"), 'r').read()) svguilibfile.write(translate(os.path.join(os.path.dirname(__file__), "pyjs", "lib", "pyjslib.py"), "pyjslib")) svguilibfile.write(translate(os.path.join(os.path.dirname(__file__), "svguilib.py"), "svguilib")) svguilibfile.write("pyjslib();\nsvguilib();\n") svguilibfile.write(open(os.path.join(os.path.dirname(__file__), "pyjs", "lib", "json.js"), 'r').read()) svguilibfile.write(open(os.path.join(os.path.dirname(__file__), "livesvg.js"), 'r').read()) svguilibfile.close() jsmodules = {"LiveSVGPage": "svguilib.js"} res += (("svguilib.js", file(svguilibpath,"rb")),) runtimefile_path = os.path.join(buildpath, "runtime_%s.py"%location_str) runtimefile = open(runtimefile_path, 'w') runtimefile.write(svguiservercode % {"svgfile" : "gui.svg"}) runtimefile.write(""" def _runtime_%(location)s_start(): website.LoadHMI(%(svgui_class)s, %(jsmodules)s) def _runtime_%(location)s_stop(): website.UnLoadHMI() """ % {"location": location_str, "svgui_class": "SVGUI_HMI", "jsmodules" : str(jsmodules), }) runtimefile.close() res += (("runtime_%s.py"%location_str, file(runtimefile_path,"rb")),) return res
def pyjs_tester(filename, module): output = pyjs.translate(filename + ".py", module)