py_ext/PythonFileCTNMixin.py
changeset 1768 691083b5682a
parent 1766 c1e5b9f19483
child 1777 c46ec818bdd7
equal deleted inserted replaced
1767:c74815729afd 1768:691083b5682a
   113                     "uppername": variable.getname().upper(),
   113                     "uppername": variable.getname().upper(),
   114                     "IECtype": variable.gettype(),
   114                     "IECtype": variable.gettype(),
   115                     "pyextname": pyextname},
   115                     "pyextname": pyextname},
   116                     self.CodeFile.variables.variable)
   116                     self.CodeFile.variables.variable)
   117         # python side PLC global variables access stub
   117         # python side PLC global variables access stub
   118         globalstubs = "\n".join(["""\
   118         globalstubs = "\n".join([
       
   119             """\
   119 _%(name)s_ctype, _%(name)s_unpack, _%(name)s_pack = \\
   120 _%(name)s_ctype, _%(name)s_unpack, _%(name)s_pack = \\
   120     TypeTranslator["%(IECtype)s"]
   121     TypeTranslator["%(IECtype)s"]
   121 _PySafeGetPLCGlob_%(name)s = PLCBinary.__SafeGetPLCGlob_%(name)s
   122 _PySafeGetPLCGlob_%(name)s = PLCBinary.__SafeGetPLCGlob_%(name)s
   122 _PySafeGetPLCGlob_%(name)s.restype = None
   123 _PySafeGetPLCGlob_%(name)s.restype = None
   123 _PySafeGetPLCGlob_%(name)s.argtypes = [ctypes.POINTER(_%(name)s_ctype)]
   124 _PySafeGetPLCGlob_%(name)s.argtypes = [ctypes.POINTER(_%(name)s_ctype)]
   128     "%(name)s",
   129     "%(name)s",
   129     "%(IECtype)s",
   130     "%(IECtype)s",
   130     %(desc)s,
   131     %(desc)s,
   131     %(onchange)s,
   132     %(onchange)s,
   132     %(opts)s))
   133     %(opts)s))
   133 """ % varinfo
   134 """ % varinfo for varinfo in varinfos])
   134       for varinfo in varinfos])
       
   135 
   135 
   136         # Runtime calls (start, stop, init, and cleanup)
   136         # Runtime calls (start, stop, init, and cleanup)
   137         rtcalls = ""
   137         rtcalls = ""
   138         for section in self.SECTIONS_NAMES:
   138         for section in self.SECTIONS_NAMES:
   139             if section != "globals":
   139             if section != "globals":
   171 
   171 
   172 """ % locals()
   172 """ % locals()
   173 
   173 
   174         # write generated content to python file
   174         # write generated content to python file
   175         runtimefile_path = os.path.join(buildpath,
   175         runtimefile_path = os.path.join(buildpath,
   176             "runtime_%s.py" % location_str)
   176                                         "runtime_%s.py" % location_str)
   177         runtimefile = open(runtimefile_path, 'w')
   177         runtimefile = open(runtimefile_path, 'w')
   178         runtimefile.write(PyFileContent.encode('utf-8'))
   178         runtimefile.write(PyFileContent.encode('utf-8'))
   179         runtimefile.close()
   179         runtimefile.close()
   180 
   180 
   181         # C code for safe global variables access
   181         # C code for safe global variables access