py_ext/PythonFileCTNMixin.py
changeset 1447 d6b878525ceb
parent 1436 e15ca67197b9
child 1448 20ff66dcc31d
equal deleted inserted replaced
1446:4963e3816641 1447:d6b878525ceb
    70         # location string for that CTN
    70         # location string for that CTN
    71         location_str = "_".join(map(lambda x:str(x),
    71         location_str = "_".join(map(lambda x:str(x),
    72                                 self.GetCurrentLocation()))
    72                                 self.GetCurrentLocation()))
    73         configname = self.GetCTRoot().GetProjectConfigNames()[0]
    73         configname = self.GetCTRoot().GetProjectConfigNames()[0]
    74 
    74 
       
    75         pyextname = self.CTNName()
    75 
    76 
    76         # python side PLC global variables access stub
    77         # python side PLC global variables access stub
    77         globalstubs = "\n".join(["""\
    78         globalstubs = "\n".join(["""\
    78 _%(name)s_ctype, _%(name)s_unpack, _%(name)s_pack = \\
    79 _%(name)s_ctype, _%(name)s_unpack, _%(name)s_pack = \\
    79     TypeTranslator["%(IECtype)s"]
    80     TypeTranslator["%(IECtype)s"]
    81 _PySafeGetPLCGlob_%(name)s.restype = None
    82 _PySafeGetPLCGlob_%(name)s.restype = None
    82 _PySafeGetPLCGlob_%(name)s.argtypes = [ctypes.POINTER(_%(name)s_ctype)]
    83 _PySafeGetPLCGlob_%(name)s.argtypes = [ctypes.POINTER(_%(name)s_ctype)]
    83 _PySafeSetPLCGlob_%(name)s = PLCBinary.__SafeSetPLCGlob_%(name)s
    84 _PySafeSetPLCGlob_%(name)s = PLCBinary.__SafeSetPLCGlob_%(name)s
    84 _PySafeSetPLCGlob_%(name)s.restype = None
    85 _PySafeSetPLCGlob_%(name)s.restype = None
    85 _PySafeSetPLCGlob_%(name)s.argtypes = [ctypes.POINTER(_%(name)s_ctype)]
    86 _PySafeSetPLCGlob_%(name)s.argtypes = [ctypes.POINTER(_%(name)s_ctype)]
    86 _PySafePLCGlobals.append(("%(name)s","%(IECtype)s"))
    87 _%(pyextname)sGlobalsDesc.append(("%(name)s","%(IECtype)s"))
    87 """ % { "name": variable.getname(),
    88 """ % { "name": variable.getname(),
    88         "configname": configname.upper(),
    89         "configname": configname.upper(),
    89         "uppername": variable.getname().upper(),
    90         "uppername": variable.getname().upper(),
    90         "IECtype": variable.gettype()}
    91         "IECtype": variable.gettype(),
       
    92         "pyextname":pyextname}
    91             for variable in self.CodeFile.variables.variable])
    93             for variable in self.CodeFile.variables.variable])
    92 
    94 
    93         # Runtime calls (start, stop, init, and cleanup)
    95         # Runtime calls (start, stop, init, and cleanup)
    94         rtcalls = ""
    96         rtcalls = ""
    95         for section in self.SECTIONS_NAMES:
    97         for section in self.SECTIONS_NAMES:
   102                 else:
   104                 else:
   103                     rtcalls += "    pass\n\n"
   105                     rtcalls += "    pass\n\n"
   104 
   106 
   105         globalsection = self.GetSection("globals")
   107         globalsection = self.GetSection("globals")
   106 
   108 
   107         pyextname = self.CTNName()
       
   108 
       
   109         PyFileContent = """\
   109         PyFileContent = """\
   110 #!/usr/bin/env python
   110 #!/usr/bin/env python
   111 # -*- coding: utf-8 -*-
   111 # -*- coding: utf-8 -*-
   112 ## Code generated by Beremiz python mixin confnode
   112 ## Code generated by Beremiz python mixin confnode
   113 ##
   113 ##
   114 
   114 
   115 ## Code for PLC global variable access
   115 ## Code for PLC global variable access
   116 from targets.typemapping import TypeTranslator
   116 from targets.typemapping import TypeTranslator
   117 import ctypes
   117 import ctypes
   118 _PyExtName = "%(pyextname)s"
   118 _%(pyextname)sGlobalsDesc = []
   119 _PySafePLCGlobals = []
   119 PLCGlobalsDesc.append(( "_%(pyextname)s" , _%(pyextname)sGlobalsDesc ))
   120 %(globalstubs)s
   120 %(globalstubs)s
   121 
   121 
   122 ## User code in "global" scope
   122 ## User code in "global" scope
   123 %(globalsection)s
   123 %(globalsection)s
   124 
   124