targets/plc_python.c
changeset 286 a2a8a52b0d4f
parent 281 3f0fc8de99b0
child 300 7f7912ae5ee8
equal deleted inserted replaced
285:e5782a52dcea 286:a2a8a52b0d4f
    27 /* A global IEC-Python gateway state, for use inside python_eval FBs*/
    27 /* A global IEC-Python gateway state, for use inside python_eval FBs*/
    28 static int PythonState;
    28 static int PythonState;
    29 #define PYTHON_LOCKED_BY_PYTHON 0
    29 #define PYTHON_LOCKED_BY_PYTHON 0
    30 #define PYTHON_LOCKED_BY_PLC 1
    30 #define PYTHON_LOCKED_BY_PLC 1
    31 #define PYTHON_MUSTWAKEUP 2
    31 #define PYTHON_MUSTWAKEUP 2
       
    32 #define PYTHON_FINISHED 4
    32  
    33  
    33 /* Each python_eval FunctionBlock have it own state */
    34 /* Each python_eval FunctionBlock have it own state */
    34 #define PYTHON_FB_FREE 0
    35 #define PYTHON_FB_FREE 0
    35 #define PYTHON_FB_REQUESTED 1
    36 #define PYTHON_FB_REQUESTED 1
    36 #define PYTHON_FB_PROCESSING 2
    37 #define PYTHON_FB_PROCESSING 2
    53 		EvalFBs[i] = NULL;
    54 		EvalFBs[i] = NULL;
    54 }
    55 }
    55 
    56 
    56 void __cleanup_python()
    57 void __cleanup_python()
    57 {
    58 {
       
    59 	PythonState = PYTHON_FINISHED;
       
    60 	UnBlockPythonCommands();
    58 }
    61 }
    59 
    62 
    60 void __retrieve_python()
    63 void __retrieve_python()
    61 {
    64 {
    62 	/* Check Python thread is not being 
    65 	/* Check Python thread is not being 
   171 	 	  /* or doesn't contain command */ 
   174 	 	  /* or doesn't contain command */ 
   172 	      data__->STATE != PYTHON_FB_REQUESTED)
   175 	      data__->STATE != PYTHON_FB_REQUESTED)
   173 	{
   176 	{
   174 		UnLockPython();
   177 		UnLockPython();
   175 		/* wait next FB to eval */
   178 		/* wait next FB to eval */
       
   179 		//printf("PythonIterator wait\n");
   176 		WaitPythonCommands();
   180 		WaitPythonCommands();
       
   181 		/*emergency exit*/
       
   182 		if(PythonState & PYTHON_FINISHED) return NULL;
   177 		LockPython();
   183 		LockPython();
   178 	}
   184 	}
   179 	/* Mark block as processing */
   185 	/* Mark block as processing */
   180 	data__->STATE = PYTHON_FB_PROCESSING;
   186 	data__->STATE = PYTHON_FB_PROCESSING;
   181 	//printf("PythonIterator\n");
   187 	//printf("PythonIterator\n");