py_ext/plc_python.c
changeset 728 e0424e96e3fd
parent 721 ecf4d203c4d4
child 851 666f5bdad301
equal deleted inserted replaced
727:3edd2f19bce2 728:e0424e96e3fd
    41 void UnBlockPythonCommands(void);
    41 void UnBlockPythonCommands(void);
    42 int TryLockPython(void);
    42 int TryLockPython(void);
    43 void UnLockPython(void);
    43 void UnLockPython(void);
    44 void LockPython(void);
    44 void LockPython(void);
    45 
    45 
    46 int __init_%(location)s()
    46 int __init_py_ext()
    47 {
    47 {
    48 	int i;
    48 	int i;
    49 	/* Initialize cursors */
    49 	/* Initialize cursors */
    50 	Current_Python_EvalFB = 0;
    50 	Current_Python_EvalFB = 0;
    51 	Current_PLC_EvalFB = 0;
    51 	Current_PLC_EvalFB = 0;
    53 	for(i = 0; i < %(python_eval_fb_count)d; i++)
    53 	for(i = 0; i < %(python_eval_fb_count)d; i++)
    54 		EvalFBs[i] = NULL;
    54 		EvalFBs[i] = NULL;
    55   return 0;
    55   return 0;
    56 }
    56 }
    57 
    57 
    58 void __cleanup_%(location)s()
    58 void __cleanup_py_ext()
    59 {
    59 {
    60 	PythonState = PYTHON_FINISHED;
    60 	PythonState = PYTHON_FINISHED;
    61 	UnBlockPythonCommands();
    61 	UnBlockPythonCommands();
    62 }
    62 }
    63 
    63 
    64 void __retrieve_%(location)s()
    64 void __retrieve_py_ext()
    65 {
    65 {
    66 	/* Check Python thread is not being
    66 	/* Check Python thread is not being
    67 	 * modifying internal python_eval data */
    67 	 * modifying internal python_eval data */
    68 	PythonState = TryLockPython() ?
    68 	PythonState = TryLockPython() ?
    69 	                PYTHON_LOCKED_BY_PLC :
    69 	                PYTHON_LOCKED_BY_PLC :
    70 	                PYTHON_LOCKED_BY_PYTHON;
    70 	                PYTHON_LOCKED_BY_PYTHON;
    71 	/* If python thread _is_ in, then PythonState remains PYTHON_LOCKED_BY_PYTHON
    71 	/* If python thread _is_ in, then PythonState remains PYTHON_LOCKED_BY_PYTHON
    72 	 * and python_eval will no do anything */
    72 	 * and python_eval will no do anything */
    73 }
    73 }
    74 
    74 
    75 void __publish_%(location)s()
    75 void __publish_py_ext()
    76 {
    76 {
    77 	if(PythonState & PYTHON_LOCKED_BY_PLC){
    77 	if(PythonState & PYTHON_LOCKED_BY_PLC){
    78 		/* If runnig PLC did push something in the fifo*/
    78 		/* If runnig PLC did push something in the fifo*/
    79 		if(PythonState & PYTHON_MUSTWAKEUP){
    79 		if(PythonState & PYTHON_MUSTWAKEUP){
    80 			/* WakeUp python thread */
    80 			/* WakeUp python thread */