--- a/py_ext/PythonFileCTNMixin.py Wed May 15 17:13:49 2013 +0900
+++ b/py_ext/PythonFileCTNMixin.py Wed May 15 18:21:20 2013 +0900
@@ -66,8 +66,8 @@
_%(name)s_ctype, _%(name)s_unpack, _%(name)s_pack = \\
TypeTranslator["%(IECtype)s"]
_PySafeGetPLCGlob_%(name)s = PLCBinary.__SafeGetPLCGlob_%(name)s
-_PySafeGetPLCGlob_%(name)s.restype = _%(name)s_ctype
-_PySafeGetPLCGlob_%(name)s.argtypes = []
+_PySafeGetPLCGlob_%(name)s.restype = None +_PySafeGetPLCGlob_%(name)s.argtypes = [ctypes.POINTER(_%(name)s_ctype)] _PySafeSetPLCGlob_%(name)s = PLCBinary.__SafeSetPLCGlob_%(name)s
_PySafeSetPLCGlob_%(name)s.restype = None
_PySafeSetPLCGlob_%(name)s.argtypes = [ctypes.POINTER(_%(name)s_ctype)]
@@ -127,12 +127,11 @@
long __%(name)s_rlock = 0;
long __%(name)s_wlock = 0;
int __%(name)s_wbuffer_written = 0;
-%(IECtype)s __SafeGetPLCGlob_%(name)s(){
+void __SafeGetPLCGlob_%(name)s(%(IECtype)s *pvalue){ while(AtomicCompareExchange(&__%(name)s_rlock, 0, 1));
- res = __%(name)s_rbuffer;
+ *pvalue = __%(name)s_rbuffer; AtomicCompareExchange((long*)&__%(name)s_rlock, 1, 0);
__SafeSetPLCGlob_%(name)s(%(IECtype)s *value){
while(AtomicCompareExchange(&__%(name)s_wlock, 0, 1));
@@ -207,6 +206,6 @@
return ([(Gen_PyCfile_path, matiec_flags)],
("runtime_%s.py"%location_str, file(runtimefile_path,"rb")))
--- a/runtime/PLCObject.py Wed May 15 17:13:49 2013 +0900
+++ b/runtime/PLCObject.py Wed May 15 18:21:20 2013 +0900
@@ -265,12 +265,14 @@
self.python_runtime_vars["PLCObject"] = self
self.python_runtime_vars["PLCBinary"] = self.PLClibraryHandle
- def __getattr__(self, name):
- r = globals()["_PySafeGetPLCGlob_"+name]()
- return globals()["_"+name+"_unpack"](r)
- def __setattr__(self, name, value):
- v = globals()["_"+name+"_pack"](c_type,value)
- globals()["_PySafeSetPLCGlob_"+name](ctypes.byref(v))
+ def __getattr__(_self, name): + v = self.python_runtime_vars["_"+name+"_ctype"]() + r = self.python_runtime_vars["_PySafeGetPLCGlob_"+name](ctypes.byref(v)) + return self.python_runtime_vars["_"+name+"_unpack"](v) + def __setattr__(_self, name, value): + t = self.python_runtime_vars["_"+name+"_ctype"] + v = self.python_runtime_vars["_"+name+"_pack"](t,value) + self.python_runtime_vars["_PySafeSetPLCGlob_"+name](ctypes.byref(v)) self.python_runtime_vars["PLCGlobals"] = PLCSafeGlobals()
for filename in os.listdir(self.workingdir):
--- a/tests/python/plc.xml Wed May 15 17:13:49 2013 +0900
+++ b/tests/python/plc.xml Wed May 15 18:21:20 2013 +0900
@@ -8,7 +8,7 @@
creationDateTime="2008-12-14T16:21:19"/>
<contentHeader name="Beremiz Python Support Tests"
- modificationDateTime="2013-05-08T22:43:14">
+ modificationDateTime="2013-05-15T18:19:52"> <pageSize x="1024" y="1024"/>
@@ -191,6 +191,16 @@
+ <variable name="Test_Python_Var"> + <variable name="Second_Python_Var"> @@ -857,15 +867,15 @@
<expression>'True'</expression>
- <block localId="46" width="130" height="45" typeName="BYTE_TO_STRING">
+ <block localId="46" width="130" height="45" typeName="INT_TO_STRING"> <position x="900" y="970"/>
<variable formalParameter="IN">
<relPosition x="0" y="30"/>
- <connection refLocalId="47">
+ <connection refLocalId="58"> <position x="900" y="1000"/>
- <position x="850" y="1000"/>
+ <position x="840" y="1000"/> @@ -879,13 +889,6 @@
- <inVariable localId="47" height="30" width="80">
- <position x="770" y="985"/>
- <relPosition x="80" y="15"/>
- <expression>BYTE#145</expression>
<inVariable localId="50" height="30" width="105">
<position x="200" y="1085"/>
@@ -1089,6 +1092,31 @@
<expression>TUTU</expression>
+ <inVariable localId="58" height="30" width="145"> + <position x="715" y="985"/> + <relPosition x="145" y="15"/> + <expression>Second_Python_Var</expression> + <outVariable localId="47" height="30" width="125"> + <position x="400" y="975"/> + <relPosition x="0" y="15"/> + <connection refLocalId="59"> + <position x="400" y="990"/> + <position x="330" y="990"/> + <expression>Test_Python_Var</expression> + <inVariable localId="59" height="30" width="30"> + <position x="300" y="975"/> + <relPosition x="30" y="15"/> + <expression>23</expression> --- a/tests/python/python@py_ext/pyfile.xml Wed May 15 17:13:49 2013 +0900
+++ b/tests/python/python@py_ext/pyfile.xml Wed May 15 18:21:20 2013 +0900
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
- <variable name="Test_Python_Var" type="INT" initial="0"/>
+ <variable name="Test_Python_Var" type="INT" initial="4"/> + <variable name="Second_Python_Var" type="INT" initial="5"/> @@ -18,6 +19,8 @@
print "Failed Python_to_C_Call failed"
+ print "Python read PLC global :",PLCGlobals.Test_Python_Var + PLCGlobals.Second_Python_Var = 789