# HG changeset patch # User Edouard Tisserant # Date 1368609680 -32400 # Node ID 203f4eff331388dc6f54808aaac002ed5afd9d28 # Parent 21475ee0e688cac3dbcb4305d6e57daecc612d1b Fixed PLC global var access from python. Added test in tests/python diff -r 21475ee0e688 -r 203f4eff3313 py_ext/PythonFileCTNMixin.py --- 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){ %(IECtype)s res; while(AtomicCompareExchange(&__%(name)s_rlock, 0, 1)); - res = __%(name)s_rbuffer; + *pvalue = __%(name)s_rbuffer; AtomicCompareExchange((long*)&__%(name)s_rlock, 1, 0); - return res; } __SafeSetPLCGlob_%(name)s(%(IECtype)s *value){ while(AtomicCompareExchange(&__%(name)s_wlock, 0, 1)); @@ -207,6 +206,6 @@ return ([(Gen_PyCfile_path, matiec_flags)], "", - False, + True, ("runtime_%s.py"%location_str, file(runtimefile_path,"rb"))) diff -r 21475ee0e688 -r 203f4eff3313 runtime/PLCObject.py --- 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 class PLCSafeGlobals: - 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() try: for filename in os.listdir(self.workingdir): diff -r 21475ee0e688 -r 203f4eff3313 tests/python/plc.xml --- 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 @@ productVersion="0.0" creationDateTime="2008-12-14T16:21:19"/> + modificationDateTime="2013-05-15T18:19:52"> @@ -191,6 +191,16 @@ + + + + + + + + + + @@ -857,15 +867,15 @@ 'True' - + - + - + @@ -879,13 +889,6 @@ - - - - - - BYTE#145 - @@ -1089,6 +1092,31 @@ TUTU + + + + + + Second_Python_Var + + + + + + + + + + + Test_Python_Var + + + + + + + 23 + diff -r 21475ee0e688 -r 203f4eff3313 tests/python/python@py_ext/pyfile.xml --- 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 @@ - + +