<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.0.26">
  <POU Name="PRG_SysMFunctions" Id="{d4222e29-c86d-42ff-9cd9-224da3415ef5}">
    <Declaration><![CDATA[PROGRAM PRG_SysMFunctions
VAR
i: INT;
	fbRTrigM0: 	ARRAY[1..nmaxNumberOfNciChannels] OF R_TRIG;
	fbRTrigM1: 	ARRAY[1..nmaxNumberOfNciChannels] OF R_TRIG;
	fbRTrigM30:    ARRAY[1..nmaxNumberOfNciChannels] OF R_TRIG;
	fbIsEStopActiveChannel: ARRAY[1..nmaxNumberOfNciChannels] OF FB_IsEStopActiveChannel;
	bEstop:		 ARRAY[1..nmaxNumberOfNciChannels] OF BOOL;


	NMUBER: DINT;
         EnableFeederBackup:ItpEnableFeederBackup;
	BackupEnabled:ItpIsFeederBackupEnabled;
	RetraceMoveBackward:ItpRetraceMoveBackward;
	RetraceMoveForward:ItpRetraceMoveForward;


	BackUpEnable: BOOL;
	BackUpEnableExe: BOOL;
	BackUpEnabledExe: BOOL;
	MoveBackwardEXE: BOOL;
	MoveForwardEXE: BOOL;
	bBackUpEnabled: BOOL;
       RtBackUpEnable:R_TRIG;
          ftBackUpEnable:F_TRIG;
(*G100*)
	FbItpDelDtgEx :ItpDelDtgEx;
         bDeltg:BOOL;
	

END_VAR
]]></Declaration>
    <Implementation>
      <ST><![CDATA[
(* M0 in every channel = Stop NC program *)
FOR i := 1 TO nmaxNumberOfNciChannels DO
	fbRTrigM0[i](CLK := bMFunc[i, 0]);
	IF fbRTrigM0[i].Q THEN
		PLCMachineMode[i + 1].Stop := TRUE;
	END_IF
	IF bMFunc[i, 0] AND bEstop[i] THEN
//	IF bMFunc[i, 0] THEN
		bQuitMFunc[i, 0] := TRUE;
	END_IF
END_FOR

(* M1 in every channel = Stop NC program if enabled in HMI (Wahlhalt) *)
FOR i := 1 TO nmaxNumberOfNciChannels DO
	fbRTrigM1[i](CLK := bMFunc[i, 1]);
	IF fbRTrigM1[i].Q THEN
		IF NOT PLCMachineMode[i + 1].M01Stop THEN	(* if not enabeld -> acknowledge immediately *)
			bQuitMFunc[i, 1] := TRUE;
		END_IF
		IF PLCMachineMode[i + 1].M01Stop THEN
			PLCMachineMode[i + 1].Stop := TRUE;			(* send STOP to channel *)
		END_IF
	END_IF
	IF bMFunc[i, 1] AND PLCMachineMode[i + 1].M01Stop AND bEstop[i] THEN	(* ich channel has stopped -> acknowledge M1 *)
		bQuitMFunc[i, 1] := TRUE;
	END_IF
END_FOR

(* M30 in every channel = end of program *)
FOR i := 1 TO nmaxNumberOfNciChannels DO
	fbRTrigM30[i](CLK := bMFunc[i, 30]);
	IF fbRTrigM30[i].Q THEN
		bQuitMFunc[i, 30] := TRUE;
	END_IF
END_FOR

(* check if EStop is active in channel and store information in bEstop *)

FOR i := 1 TO nmaxNumberOfNciChannels DO
	fbIsEStopActiveChannel[i](
		bExec:= NOT fbIsEStopActiveChannel[i].bBusy,
		nChan:= i + 1,
		bIsEstop=> bEstop[i]);
END_FOR
(*行号*)

NMUBER:=ItpGetBlockNumber(arrNCToPLC_NCIChannel_REF[1]);
(*回退 假如需要回退功能，需要在G代码运行之前就提前开启backup，那么运行到中间时才可以回退*)
(*1 开启backup 2 运行g代码 3 暂停 4 触发后退或前进*)
ftBackUpEnable(CLK:=BackUpEnable , Q=> );
RtBackUpEnable(CLK:=BackUpEnable , Q=> );
EnableFeederBackup(
	bEnable:=BackUpEnable ,
	bExecute:=ftBackUpEnable.Q OR  RtBackUpEnable.Q,
	tTimeOut:= ,
	sNciToPlc:=arrNCToPLC_NCIChannel_REF[1] ,
	bBusy=> ,
	bErr=> ,
	nErrId=> );
BackupEnabled(
	bExecute:=ftBackUpEnable.Q OR  RtBackUpEnable.Q ,
	tTimeOut:= ,
	sNciToPlc:=arrNCToPLC_NCIChannel_REF[1] ,
	bBusy=> ,
	bEnabled=>bBackUpEnabled ,
	bErr=> ,
	nErrId=> );
RetraceMoveBackward(
	bExecute:=MoveBackwardEXE ,
	tTimeOut:= ,
	sNciToPlc:=arrNCToPLC_NCIChannel_REF[1] ,
	bBusy=> ,
	bErr=> ,
	nErrId=> );
RetraceMoveForward(
	bExecute:=MoveForwardEXE ,
	tTimeOut:= ,
	sNciToPlc:=arrNCToPLC_NCIChannel_REF[1] ,
	bBusy=> ,
	bErr=> ,
	nErrId=> );
MoveBackwardEXE:=FALSE;
MoveForwardEXE:=FALSE;

(*G100*)
FbItpDelDtgEx(
	bExecute:=bDeltg ,
	tTimeOut:= ,
	sNciToPlc:=arrNCToPLC_NCIChannel_REF[1]  ,
	bBusy=> ,
	bErr=> ,
	nErrId=> );

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