Added __ext_name__ variable accessible from user python code, reflecting extension name. Fixed contend of OnChange field in PLCGlobalsDesc
authorEdouard Tisserant
Sat, 21 Feb 2015 10:20:24 +0100
changeset 1449 5f09fa31d7b0
parent 1448 20ff66dcc31d
child 1450 44bf0ba866e9
Added __ext_name__ variable accessible from user python code, reflecting extension name. Fixed contend of OnChange field in PLCGlobalsDesc
py_ext/PythonFileCTNMixin.py
--- a/py_ext/PythonFileCTNMixin.py	Thu Feb 19 00:40:53 2015 +0100
+++ b/py_ext/PythonFileCTNMixin.py	Sat Feb 21 10:20:24 2015 +0100
@@ -75,8 +75,11 @@
         varinfos = map(lambda variable : {
                     "name": variable.getname(),
                     "desc" : repr(variable.getdesc()),   
-                    "onchange" : '"'+variable.getonchange()+"('"+variable.getname()+"')\"" \
-                                 if variable.getonchange() else "",
+                    "onchangecode" : '"'+variable.getonchange()+\
+                                         "('"+variable.getname()+"')\"" \
+                                     if variable.getonchange() else '""',
+                    "onchange" : repr(variable.getonchange()) \
+                                 if variable.getonchange() else None,
                     "opts" : repr(variable.getopts()),
                     "configname" : configname.upper(),
                     "uppername" : variable.getname().upper(),
@@ -97,8 +100,10 @@
     "%(name)s",
     "%(IECtype)s",
     %(desc)s,
+    %(onchange)s,
     %(opts)s))
-""" % varinfo for varinfo in varinfos])
+""" % varinfo 
+      for varinfo in varinfos])
 
         # Runtime calls (start, stop, init, and cleanup)
         rtcalls = ""
@@ -124,6 +129,7 @@
 from targets.typemapping import TypeTranslator
 import ctypes
 _%(pyextname)sGlobalsDesc = []
+__ext_name__ = "%(pyextname)s"
 PLCGlobalsDesc.append(( "_%(pyextname)s" , _%(pyextname)sGlobalsDesc ))
 %(globalstubs)s
 
@@ -133,6 +139,8 @@
 ## Beremiz python runtime calls
 %(rtcalls)s
 
+del __ext_name__
+
 """ % locals()
 
         # write generated content to python file
@@ -198,7 +206,7 @@
         varinitonchangefmt = """\
     __%(name)s_notifier = __GET_GLOBAL_ON%(uppername)sCHANGE();
     __SET_VAR(__%(name)s_notifier->,TRIG,,__BOOL_LITERAL(TRUE));
-    __SET_VAR(__%(name)s_notifier->,CODE,,__STRING_LITERAL(%(onchangelen)d,%(onchange)s));
+    __SET_VAR(__%(name)s_notifier->,CODE,,__STRING_LITERAL(%(onchangelen)d,%(onchangecode)s));
 """
         vardec = "\n".join([(vardecfmt + vardeconchangefmt 
                              if varinfo["onchange"] else vardecfmt)% varinfo 
@@ -208,7 +216,7 @@
                              varpubfmt) % varinfo
                             for varinfo in varinfos])
         varinit = "\n".join([varinitonchangefmt % dict(
-                                onchangelen = len(varinfo["onchange"]),**varinfo)
+                                onchangelen = len(varinfo["onchangecode"]),**varinfo)
                             for varinfo in varinfos if varinfo["onchange"]])
 
         PyCFileContent = """\