<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.0.20">
  <POU Name="PRG_StopAllAxes" Id="{596673af-c193-4877-bab8-9005903d7bc6}">
    <Declaration><![CDATA[PROGRAM PRG_StopAllAxes
VAR_INPUT
	bExecute: BOOL;
END_VAR

VAR_OUTPUT
	BDone: BOOL;
END_VAR

VAR
	i: 									INT;
	fbMC_Stop: 							ARRAY [1..nMaxNumberOfAxis] OF MC_Stop;
	arAxisInGroup: 					ARRAY [1..nMaxNumberOfAxis] OF BOOL; // := nMaxNumberOfAxis(FALSE);
	nState : 							UINT;
	fbR_TRIG: 							R_TRIG;
	fbCfgReadExt3DAxisIds: 			ARRAY [1..nMaxNumberOfNciChannels] OF CfgReadExt3DAxisIds;
	stGroup:								ARRAY [1..nMaxNumberOfNciChannels] OF NCI_EXT3DGROUP;
	localDone: BOOL;
	l: UINT;
END_VAR
]]></Declaration>
    <Implementation>
      <ST><![CDATA[(* ========================================================== *)
(*   PRG: PRG_StopAllAxis			        		          *)
(* ---------------------------------------------------------- *)
(*   Desc: Stop all axis in PTP Channel with the help of MC_STOP *)
(*   Auth: MiB                                               *)
(*   Date: 12.06.2006                                        *)
(*   Last: 02.04.2013                                        *)
(*   Rev.: 1.1                                               *)
(* ==========================================================*)


fbR_TRIG(CLK:= bExecute);


IF fbR_TRIG.Q THEN
	nState := 1;
	bDone := FALSE;
	(* Init fbCfgReadExt3DAxisIds *)
	FOR i := 1 TO nMaxNumberOfNciChannels DO
		fbCfgReadExt3DAxisIds[i]( bExecute := FALSE , stExt3dGroup:= stGroup[i]);
	END_FOR
	(* Init fbMC_Stop *)
	FOR i:=1 TO nMaxNumberOfAxis DO
		fbMC_Stop[i](Execute := FALSE, Axis:= arrAxis_Ref[i]);
		arAxisInGroup[i] := FALSE;
	END_FOR
END_IF


CASE nState OF

1:	(* read the Axis ID for all axis that belong to an NCI Channel *)
	localDone := TRUE;
	FOR i := 1 TO nMaxNumberOfNciChannels DO
		fbCfgReadExt3DAxisIds[i](
			bExecute:= TRUE ,
			nGroupId:= nGroup[i],
			tTimeOut:= t#2s,
			stExt3dGroup:= stGroup[i]);
      localDone := localDone AND NOT fbCfgReadExt3DAxisIds[i].bBusy;
	END_FOR;
	IF localDone THEN
		nState := nState + 1;
	END_IF

2: (* Fill array with information, which axis belongs to another NCI channel *)
	FOR l := 1 TO nMaxNumberOfAxis DO
		FOR i := 1 TO nMaxNumberOfNciChannels DO
			IF stGroup[i].nXAxisId = arrAxis_Ref[l].NcToPlc.AxisId THEN //TVoss kontrollieren
				arAxisInGroup[l]:= TRUE;
			END_IF
			IF stGroup[i].nYAxisId = arrAxis_Ref[l].NcToPlc.AxisId THEN
				arAxisInGroup[l]:= TRUE;
			END_IF
			IF stGroup[i].nZAxisId = arrAxis_Ref[l].NcToPlc.AxisId THEN
				arAxisInGroup[l]:= TRUE;
			END_IF
			IF stGroup[i].nQ1AxisId = arrAxis_Ref[l].NcToPlc.AxisId THEN
				arAxisInGroup[l]:= TRUE;
			END_IF
			IF stGroup[i].nQ2AxisId = arrAxis_Ref[l].NcToPlc.AxisId THEN
				arAxisInGroup[l]:= TRUE;
			END_IF
			IF stGroup[i].nQ3AxisId = arrAxis_Ref[l].NcToPlc.AxisId THEN
				arAxisInGroup[l]:= TRUE;
			END_IF
			IF stGroup[i].nQ4AxisId = arrAxis_Ref[l].NcToPlc.AxisId THEN
				arAxisInGroup[l]:= TRUE;
			END_IF
			IF stGroup[i].nQ5AxisId = arrAxis_Ref[l].NcToPlc.AxisId THEN
				arAxisInGroup[l]:= TRUE;
			END_IF
		END_FOR
	END_FOR
	nState := 3;


3: (* Stop all axis, that are not grouped in other groups *)
	bDone := TRUE;
	FOR i:=1 TO nMaxNumberOfAxis DO
		IF NOT arAxisInGroup[i] THEN
			fbMC_Stop[i](
				Execute:= bExecute ,
				Axis:= arrAxis_Ref[i],
				Done=> bDone,
				Error=> ,
				ErrorID=> );
			bDone := fbMC_Stop[i].Done AND bDone;
		END_IF
	END_FOR;
	IF bDone THEN
		nState := 0;
	END_IF
END_CASE



]]></ST>
    </Implementation>
    <ObjectProperties />
  </POU>
</TcPlcObject>