# HG changeset patch # User Edouard Tisserant # Date 1350584651 -7200 # Node ID dbf82971f09d39e1c00e6a295173fe338567a5ca # Parent daafaa8a28fda78b7b71b8ba7a142e944388a672 More pedagogical tests/python. Should be renamed python_ctypes_and_C_pragmas_in_ST or something diff -r daafaa8a28fd -r dbf82971f09d tests/python/beremiz.xml --- a/tests/python/beremiz.xml Thu Oct 18 17:42:29 2012 +0200 +++ b/tests/python/beremiz.xml Thu Oct 18 20:24:11 2012 +0200 @@ -1,4 +1,4 @@ - + diff -r daafaa8a28fd -r dbf82971f09d tests/python/c_code@c_ext/cfile.xml --- a/tests/python/c_code@c_ext/cfile.xml Thu Oct 18 17:42:29 2012 +0200 +++ b/tests/python/c_code@c_ext/cfile.xml Thu Oct 18 20:24:11 2012 +0200 @@ -3,14 +3,48 @@ - + + + + - + +int Python_to_C_Call(int toC, int *fromC){ + /* Code called by python should never touch to + variables modified by PLC thread directly + + AtomicCompareExchange comes from + beremiz' runtime implementation */ + + int res = 0; + if(!AtomicCompareExchange(&Lock, 0, 1)){ + PtoC=toC; + *fromC=CtoP; + AtomicCompareExchange(&Lock, 1, 0); + res=1; + } + printf("C code called by Python: toC %d fromC %d\n",toC,*fromC); + return res; +} + +int PLC_C_Call(int fromPLC, int *toPLC){ + /* PLC also have to be realy carefull not to + conflict with asynchronous python access */ + int res; + if(!AtomicCompareExchange(&Lock, 0, 1)){ + CtoP = fromPLC; + *toPLC = PtoC; + AtomicCompareExchange(&Lock, 1, 0); + return 1; + } + return 0; +}]]> diff -r daafaa8a28fd -r dbf82971f09d tests/python/plc.xml --- a/tests/python/plc.xml Thu Oct 18 17:42:29 2012 +0200 +++ b/tests/python/plc.xml Thu Oct 18 20:24:11 2012 +0200 @@ -8,7 +8,7 @@ productVersion="0.0" creationDateTime="2008-12-14T16:21:19"/> + modificationDateTime="2012-10-18T20:21:28"> @@ -63,6 +63,16 @@ + + + + + + + + + + @@ -202,7 +212,7 @@ - 'PLCBinary.Python_to_C_Call(5678)' + 'PLCBinary.Simple_C_Call(5678)' @@ -457,9 +467,79 @@ pytest_var3 + + + + + + + + + + FromC + + + + + + + 23 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +IN); + if(PLC_C_Call(fromPLC, &toPLC))__SET_VAR(data__->,OUT,toPLC); +} +(* If you do not use __GET_VAR and _SET_VAR macro, expect unexpected *) +]]> + + + diff -r daafaa8a28fd -r dbf82971f09d tests/python/python@py_ext/py_ext.xml --- a/tests/python/python@py_ext/py_ext.xml Thu Oct 18 17:42:29 2012 +0200 +++ b/tests/python/python@py_ext/py_ext.xml Thu Oct 18 20:24:11 2012 +0200 @@ -1,11 +1,19 @@ -