Added FBID variable to PY_EVAL evaluation context. FBID does identify uniquely py_eval block instance triggering execution
authorEdouard Tisserant
Mon, 15 Oct 2012 17:05:19 +0200
changeset 851 666f5bdad301
parent 850 072188d4d812
child 852 1009f956d2ee
Added FBID variable to PY_EVAL evaluation context. FBID does identify uniquely py_eval block instance triggering execution
py_ext/plc_python.c
runtime/PLCObject.py
--- 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 */
--- 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)