# HG changeset patch
# User Edouard Tisserant
# Date 1350313519 -7200
# Node ID 666f5bdad3010b0f31ada00b3a8b8aa69183bb0d
# Parent  072188d4d81237335c16d3744d423a6bf12b5255
Added FBID variable to PY_EVAL evaluation context. FBID does identify uniquely py_eval block instance triggering execution

diff -r 072188d4d812 -r 666f5bdad301 py_ext/plc_python.c
--- a/py_ext/plc_python.c	Sat Oct 06 00:23:51 2012 +0200
+++ b/py_ext/plc_python.c	Mon Oct 15 17:05:19 2012 +0200
@@ -152,7 +152,7 @@
 	}
 }
 
-char* PythonIterator(char* result)
+char* PythonIterator(char* result, void** id)
 {
 	char* next_command;
 	PYTHON_EVAL* data__;
@@ -163,6 +163,7 @@
 	LockPython();
 	/* Get current FB */
 	data__ = EvalFBs[Current_Python_EvalFB];
+	*id=data__;
 	if(data__ && /* may be null at first run */
 	    __GET_VAR(data__->STATE) == PYTHON_FB_PROCESSING){ /* some answer awaited*/
 	   	/* If result not None */
diff -r 072188d4d812 -r 666f5bdad301 runtime/PLCObject.py
--- a/runtime/PLCObject.py	Sat Oct 06 00:23:51 2012 +0200
+++ b/runtime/PLCObject.py	Mon Oct 15 17:05:19 2012 +0200
@@ -105,7 +105,7 @@
             self._PythonIterator = getattr(self.PLClibraryHandle, "PythonIterator", None)
             if self._PythonIterator is not None:
                 self._PythonIterator.restype = ctypes.c_char_p
-                self._PythonIterator.argtypes = [ctypes.c_char_p]
+                self._PythonIterator.argtypes = [ctypes.c_char_p, ctypes.POINTER(ctypes.c_void_p)]
                 
                 self._stopPLC = self._stopPLC_real
             else:
@@ -221,14 +221,15 @@
         self.StatusChange()
         self.StartSem.release()
         self.evaluator(self.PrepareRuntimePy)
-        res,cmd = "None","None"
+        res,cmd,blkid = "None","None",ctypes.c_void_p()
         while True:
-            #print "_PythonIterator(", res, ")",
-            cmd = self._PythonIterator(res)
-            #print " -> ", cmd
+            # print "_PythonIterator(", res, ")",
+            cmd = self._PythonIterator(res,blkid)
+            # print " -> ", cmd, blkid
             if cmd is None:
                 break
             try :
+                self.python_threads_vars["FBID"]=blkid.value
                 res = str(self.evaluator(eval,cmd,self.python_threads_vars))
             except Exception,e:
                 res = "#EXCEPTION : "+str(e)