IF NOTxInitGraphSortingPlantExecuteTHEN

// graph execute

oper(in_name:='Conveyor1TransportWPToRamp1',in_operation:='Conveyor1TransportWPToRamp1',in_preConditions:=preConditionArray,in_postConditions:=postConditionArray,in_inverseOperation:='Conveyor1TransportWPBackToStart',in_isRecoveryState:=TRUE);

nextGraphElem.addObject('End');

previousGraphElem.addObject('Start');

graphElem(in_name:='Conveyor1TransportWPToRamp1',in_dataType:=tGRAPH,in_nextElements:=nextGraphElem,in_previousElements:=previousGraphElem);

graphElem.operation:=oper;

graphElemArray.addObject(graphElem);

preConditionArray.removeAllObjects();

postConditionArray.removeAllObjects();

nextGraphElem.removeAllObjects();

previousGraphElem.removeAllObjects();

graphSortingPlantExecute(in_allGraphElements:=graphElemArray,in_name:='SortingPlantExecute');

xInitGraphSortingPlantExecute := TRUE;

END_IF

execute := tOPERATING;

isStopped := FALSE;

currentGraphElementArray := graphSortingPlantExecute.getCurrentNodes();

allGraphElementArray := graphSortingPlantExecute.getAllGraphElements();

graphSortingPlantExecute.updateCurrentNodes();

FOR i:=1 TOcurrentGraphElementArray.numberOfObjects() BY 1 DO

graphElement := currentGraphElementArray.objectAtIndex(i);

operation := graphElement.operation;

IFoperation.getOperation() = 'Conveyor1TransportWPToRamp1' THEN

operationState := conveyor1.execute();

END_IF

IFoperationState = tOPERATING THEN

graphElement.timeUpdated := FALSE;

graphElement.updateTimer();

ELSIFoperationState = tFINISHEDTHEN

IF NOTgraphElement.timeUpdatedTHEN

timeOperation := operation.timeOperation;

timeOperation.updateTime(graphElement.returnTime());

operation.timeOperation := timeOperation;

graphElement.timeUpdated := TRUE;

graphElement.operation := operation;

graphElement.resetTimer();

allGraphElementArray.replaceObject(graphElement);

graphSortingPlantExecute.setAllGraphElements(allGraphElementArray);

END_IF

ELSIFoperationState = tERRORTHEN

errorDetected := TRUE;

END_IF

currentTimeOperation := graphElement.returnTime();

timeOperation := operation.timeOperation;

averageTimeOperation := timeOperation.getAverage();

IFaverageTimeOperation> 1 THEN

IFcurrentTimeOperation> (averageTimeOperation + 500) THEN

errorDetected := TRUE;

ELSE

errorDetected := errorDetected OR FALSE;

END_IF

END_IF

graphSortingPlantExecute.updateCurrentGraphElement(graphElement);

END_FOR

IFerrorDetectedTHEN

execute := tERROR;

ELSIFgraphSortingPlantExecute.isFinished() THEN

execute := tFINISHED;

END_IF