FUNCTION_BLOCK "FB_ILS_STRO_Vario"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_INPUT 
      stInSettings : "SettingsVario";   // Einstellungen Vario
      xInReleaseEdge : Bool;   // Flanke Carrier rausgelassen
      stInSenConvFingerInPos : "UDT_Sensor";   // Mitnehmerfinger in Position (FingerInPos)
      stInSenJam : "UDT_Sensor";   // Stausensor nach Vario (Jam)
      stInSenLastPos : "UDT_Sensor";   // Letzte Position erreicht (Full)
      stInSenCarrInPos : "UDT_Sensor";   // Carrier in Position (CarrInPos)
      xInRelease : Bool := false;   // Freigabe zum Entleeren
      xInRequest : Bool;   // Anfrage an Vario
      xInMotorProtection : Bool := false;   // Motorschutz
      xInErrorQuit : Bool;   // Fehler quittieren Überwachung Finger
      xInAutomatic : Bool;   // Automatik 
   END_VAR

   VAR_OUTPUT 
      xOutMotor : Bool := false;   // Antrieb raumgängiger Förderer 
      xOutConveyorReady : Bool := false;   // Vario bereit
      xOutConveyorReleaseReq : Bool := false;
      wOutErrorWord : Word;   // Fehler rausgeben
   END_VAR

   VAR_IN_OUT 
      arInOutJamFinger : Array[*] of "stCarrier";   // Daten Staubereich auf Vario
      stInOutHMI : "UDT_Vario";   // HMI Schnittstelle
      stInOutControlUnitCabinet : "UDT_MainState";   // Main State Schnittstelle
   END_VAR

   VAR 
      fbStateManager : "FB_StateManager";   // Schrittkette Manager
      fbFingerControl : "FB_SupervisionRasterSensor";   // Überwachung Finger 
      sStateText : String := '';   // Schritt Text (zum Beobachten)
   END_VAR
   VAR RETAIN
      nState : Int := 0;   // Schritt
      nStateLast : Int := 0;   // vorheriger Schritt (für State Manager)
      xRunMotor : Bool := false;   // Motor Start
      xConveyorReady : Bool := false;   // Förderer ist bereit
      tOnAllBtOut {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;   // Timer: Vario Entleerungsfahrt
      counterCarrier {InstructionName := 'CTU_INT'; LibVersion := '1.0'} : CTU_INT;   // Zum Eintakten von Carriern
      nCounterCatch : Int := 0;   // Zum Eintakten von Carriern
   END_VAR
   VAR 
      xErrorBtNotReaching : Bool := false;   // NIU
      tOn_ErrorConv {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;   // NIU
      tOn_WaitForStop {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;   // Für Testmodus
      tOnJamCarrierInPos {InstructionName := 'TON_TIME'; LibVersion := '1.0'} : TON_TIME;   // Prüfung: Vario dreht, aber Carrier in Position ist an
      xSensorError : Bool;   // Fehler Carrier in Position Sensor
      fbMonitoringFinger : "FB_Monitoring";   // Monitoring Finger Überwachung
      fbMonitoringMotorProtection : "FB_Monitoring";   // Motorschutzüberwachung 
      fbMonitoringCarrierInPos : "FB_Monitoring";   // Überwachung Sensor "CarrInPos"
      xClearDone : Bool;   // Prüffahrt um Finger leer zu fahren abgeschlossen
      "////////" : Bool;   // NIU
      xTestMode : Bool;   // Testmodus aktivieren
   END_VAR

   VAR_TEMP 
      tmpActUnivTon : Bool;   // Siehe State Manager
      nArrayMaxFinger : DInt;   // Array größe
   END_VAR

   VAR CONSTANT 
      c0000_StepOff : Int := 0;   // Aus
      c0100_StepUndefined : Int := 100;   // Undefiniert
      c0200_StepReceive : Int := 200;   // Förderer wartet auf Arbeit / Bereit aufzunehmen
      c1200_StepWaitTime : Int := 1200;   // Förderer wartet vor Fahrt
      c2000_StepJog : Int := 2000;   // Förderer eine Position weiter fahren (Jog Fw)
      c2200_StepNormalStop : Int := 2200;   // Normal anhalten
      c2250_StepQuickStop : Int := 2250;   // Sofort anhalten
      c2500_StepCheckVario : Int := 2500;   // Prüfen ob wirklich leer (NIU)
      c3000_StepEmptying : Int := 3000;   // Förderer entleeren
      c5000_StepEnding : Int := 5000;   // Förderer Ablauf beenden (Positionierung)
   END_VAR


BEGIN
	REGION Arraygrößen
	    #nArrayMaxFinger := UPPER_BOUND(ARR := #arInOutJamFinger, DIM := 1);
	END_REGION
	
	REGION State Machine
	    // Off
	    // Idle (keine Daten und Prüffahrt abgeschlossen)
	    //      Anforderung MTRO / Separator 
	    //      -> Entleeren
	    // Entleeren (Fahre bis Stau oder keine Daten) 
	    //      1. Anforderung MTRO / Separator
	    //      -> Entleeren Pausieren
	    //      2. Keine Daten mehr 
	    //      -> Idle
	    // Entleeren Pausieren
	    // 
	    
	    CASE #nState OF
	        #c0000_StepOff:
	            REGION 0000: Off
	                
	                // Aktueller Zustand
	                #sStateText := 'OFF';
	                
	                // Statics
	                #xRunMotor := FALSE;
	                #xConveyorReady := FALSE;
	                
	            END_REGION
	            
	        #c0100_StepUndefined:
	            REGION 0100: Undefined
	                
	                // Aktueller Zustand
	                #sStateText := 'UNDEFINED';
	                
	                // Statics
	                #xRunMotor := FALSE;
	                #xConveyorReady := FALSE;
	                
	                #nState := #c0200_StepReceive;
	            END_REGION
	            
	        #c0200_StepReceive:
	            REGION 0200: Receive
	                
	                // Aktueller Zustand
	                #sStateText := 'RECEIVE';
	                
	                // Statics
	                
	                #xRunMotor := FALSE;
	                #xConveyorReady := #xInMotorProtection;
	                
	                // Transition
	                // 
	                IF #xTestMode OR #stInOutHMI.stControl.xTestMode THEN
	                    #xConveyorReady := FALSE;
	                    #nState := #c2000_StepJog;
	                ELSE
	                    
	                    IF (#xConveyorReady AND #counterCarrier.QU) OR ((* #arInOutJamFinger[1].bStatus.%X0 AND *)NOT #xInRequest AND NOT #xClearDone AND #fbStateManager.tOutTimeInStep > T#5000ms) THEN
	                        #nState := #c1200_StepWaitTime;
	                        
	                        // ELSIF (#arInOutJamFinger[1].stCarrData.xOnline AND NOT #xClearDone AND NOT #xInRequest AND #fbStateManager.tOutTimeInStep > T#5000ms) AND
	                        //     (NOT #stInSenJam.xDirectSensor AND #stInSenJam.tDirectChangeLast > T#3000ms) THEN
	                        //     #nState := #c2500_StepCheckVario;
	                        // ELSIF #arInOutJamFinger[1].stCarrData.xOnline AND NOT #xInRequest AND #fbStateManager.tOutTimeInStep > T#5000ms THEN
	                        //     #nState := #c3000_StepEmptying;
	                    END_IF;
	                END_IF;
	                
	            END_REGION
	            
	        #c1200_StepWaitTime:
	            REGION 1200: Wait
	                // Aktueller Zustand
	                #sStateText := 'WAIT FOR TIMER';
	                
	                #xRunMotor := FALSE;
	                #xConveyorReady := FALSE;
	                
	                IF #fbStateManager.tOutTimeInStep > #stInSettings.tWaitForJog (* AND NOT #stInSenJam.xDirectSensor AND #stInSenJam.tDirectChangeLast > T#3000ms *) THEN
	                    IF #xInRequest THEN
	                        #xClearDone := FALSE;
	                        #nState := #c2000_StepJog;
	                    ELSIF NOT #stInSenJam.xDirectSensor AND #stInSenJam.tDirectChangeLast > T#2s THEN
	                        #nState := #c3000_StepEmptying;
	                   (* ELSE
	                        #nState := #c3000_StepEmptying; *)
	                    END_IF;
	                END_IF;
	            END_REGION
	            
	            
	        #c2000_StepJog:
	            REGION 2000: Jog
	                
	                // Aktueller Zustand
	                #sStateText := 'JOG';
	                
	                // Statics
	                #xRunMotor := TRUE;
	                #xConveyorReady := FALSE;
	                
	                IF #xTestMode OR #stInOutHMI.stControl.xTestMode THEN
	                    IF #stInSenConvFingerInPos.xDirectEdgePos THEN
	                        #nState := #c2200_StepNormalStop;
	                    END_IF;
	                ELSE
	                    IF ((* #fbStateManager.tOutTimeInStep > T#1000ms OR *)#fbFingerControl.xOutErrorRasterSensor) OR (NOT #stInSettings.xLongSlope AND #stInSenJam.xDirectSensor AND #stInSenLastPos.xDirectSensor)
	                        OR (#stInSettings.xLongSlope AND #stInSenJam.xDirectSensor AND #stInSenJam.tDirectChangeLast > #stInSettings.tJamSenDelay AND #stInSenLastPos.xDirectSensor)
	                    THEN
	                        #nState := #c2250_StepQuickStop;
	                    ELSIF (#stInSenJam.xDirectEdgePos AND NOT #stInSettings.xJamSenDelayActive)
	                        OR (#stInSettings.xJamSenDelayActive AND #stInSenJam.xDirectSensor AND #stInSenJam.tDirectChangeLast > #stInSettings.tJamSenDelay)
	                    THEN
	                        #nState := #c2200_StepNormalStop;
	                    ELSIF #stInSenConvFingerInPos.xDirectEdgePos THEN //////EMBI TEST
	                        #nState := #c0200_StepReceive;
	                    END_IF;
	                END_IF;
	                
	            END_REGION
	            
	        #c2200_StepNormalStop: //normal anhalten
	            REGION 2200: Normal Stop
	                
	                // Aktueller Zustand
	                #sStateText := 'NORMAL STOP';
	                
	                #xRunMotor := FALSE;
	                #xConveyorReady := FALSE;
	                
	                #xConveyorReady := FALSE;
	                
	                IF #xTestMode OR #stInOutHMI.stControl.xTestMode THEN
	                    
	                    IF #tOn_WaitForStop.Q THEN
	                        #nState := #c0200_StepReceive;
	                    END_IF;
	                    
	                ELSE
	                    
	                    IF (NOT #stInSenLastPos.xDirectSensor AND #stInSenLastPos.tDirectChangeLast > T#2s AND #stInSenJam.xDbncdSensor) OR
	                        (NOT #stInSenJam.xDirectSensor AND #stInSenJam.tDirectChangeLast > T#3000ms) THEN
	                        #nState := #c5000_StepEnding;
	                    END_IF;
	                END_IF;
	                
	            END_REGION
	            
	        #c2250_StepQuickStop:
	            REGION 2250: Quick Stop
	                
	                // Aktueller Zustand
	                #sStateText := 'QUICK STOP';
	                
	                #xRunMotor := FALSE;
	                #xConveyorReady := FALSE;
	                
	                IF ((NOT #stInSenJam.xDirectSensor AND #stInSenJam.tDirectChangeLast > T#3000ms) OR
	                    (NOT #stInSenLastPos.xDirectSensor AND #stInSenLastPos.tDirectChangeLast > T#3000ms)) AND 
	                    NOT #fbFingerControl.xOutErrorRasterSensor
	                THEN
	                    #nState := #c1200_StepWaitTime;
	                END_IF;
	            END_REGION
	            
	        #c3000_StepEmptying:
	            REGION 3000: Emptying
	                
	                // Aktueller Zustand
	                #sStateText := 'EMPTYING CONVEYOR';
	                
	                // Statics
	                
	                #xRunMotor := TRUE;
	                #xConveyorReady := FALSE;
	                
	                /////////////////////
	                
	                IF (NOT #stInSettings.xLongSlope AND #stInSenJam.xDirectSensor AND #stInSenLastPos.xDirectSensor)
	                    OR (#stInSettings.xLongSlope AND #stInSenJam.xDirectSensor AND #stInSenJam.tDirectChangeLast > #stInSettings.tJamSenDelay AND #stInSenLastPos.xDirectSensor)
	                THEN
	                    #nState := #c2250_StepQuickStop;
	                ELSIF (#stInSenJam.xDirectEdgePos AND NOT #stInSettings.xJamSenDelayActive)
	                    OR (#stInSettings.xJamSenDelayActive AND #stInSenJam.xDirectSensor AND #stInSenJam.tDirectChangeLast > #stInSettings.tJamSenDelay)
	                THEN
	                    #nState := #c2200_StepNormalStop;
	                ELSIF #xInRequest THEN
	                    #xClearDone := FALSE;
	                    #nState := #c5000_StepEnding;
	                ELSIF #tOnAllBtOut.Q THEN
	                    #xClearDone := TRUE;
	                    #nState := #c5000_StepEnding;
	                // ELSIF #tOnAllBtOut.Q THEN // Freigabe zum Entleeren ist wieder/noch da und Carousel-Motor läuft
	                //     // Wenn nach einer gewissen Zeit nichts mehr kommt --> Alle Bt draußen --> Kette leer
	                //     #nState := #c5000_StepEnding;                    // Weiter
	                END_IF;
	                ///////////////////
	                
	            END_REGION
	            
	        #c5000_StepEnding:
	            REGION 5000: Ending Step
	                
	                (*Dieser Schritt wird nur nach dem Entleeren angesprungen
	                 damit sich die Kette zum Schluss noch richtig positioniert*)
	                
	                //Aktueller Zustand
	                #sStateText := 'STOPPING CONVEYOR';
	                
	                //Statics
	                #xRunMotor := TRUE;
	                #xConveyorReady := FALSE;
	                
	                // Transition
	                IF ((* #fbStateManager.tOutTimeInStep > T#1000ms OR *)#fbFingerControl.xOutErrorRasterSensor) OR (NOT #stInSettings.xLongSlope AND #stInSenJam.xDirectSensor AND #stInSenLastPos.xDirectSensor)
	                    OR (#stInSettings.xLongSlope AND #stInSenJam.xDirectSensor AND #stInSenJam.tDirectChangeLast > #stInSettings.tJamSenDelay AND #stInSenLastPos.xDirectSensor)
	                THEN
	                    #xClearDone := FALSE;
	                    #nState := #c2250_StepQuickStop;
	                ELSIF #stInSenConvFingerInPos.xDirectEdgePos (*or #fbStateManager.tOutTimeInStep > T#800ms OR *) (* #stInSenLastPos.xDirectEdgePos *)(* #stInSenConvFingerInPos.xDirectSensor *)THEN
	                    #nState := #c0200_StepReceive;
	                ELSIF (#stInSenJam.xDirectEdgePos AND NOT #stInSettings.xJamSenDelayActive)
	                //    OR (#stInSettings.xJamSenDelayActive AND #stInSenJam.xDirectSensor AND #stInSenJam.tDirectChangeLast > #stInSettings.tJamSenDelay)
	                THEN
	                    #nState := #c2200_StepNormalStop;
	                END_IF;
	                
	            END_REGION
	            
	    END_CASE;
	END_REGION
	
	REGION Timer  
	    //Entleerungsfahrt Dauer
	    #tOnAllBtOut(IN := #nState = #c3000_StepEmptying,
	                  PT := #stInSettings.tConvEmpty);
	     
	     //Wird für Testmodus verwendet, Start Stopp Intervall
	    #tOn_WaitForStop(IN := #nState = #c2200_StepNormalStop,
	                     PT := #stInSettings.tWaitForStop);
	END_REGION
	
	REGION Carrier zählen
	    #counterCarrier(CU := #xInReleaseEdge,
	                    R := #nState > #c0200_StepReceive,
	                    PV := #stInSettings.nCountCarrier,
	                    CV => #nCounterCatch);
	END_REGION
	
	REGION Überwachung Finger
	    
	    #fbFingerControl.stInSettings.xInEnableSupervision := TRUE;
	    #fbFingerControl.stInSettings.tInDelayMotorRun := #stInSettings.tRasterDelayMotorRun;
	    #fbFingerControl.stInSettings.tInRasterHigh := #stInSettings.tRasterHigh;
	    #fbFingerControl.stInSettings.tInRasterLow := #stInSettings.tRasterLow;
	    #fbFingerControl.stInSettings.sInConveyorName := #stInOutHMI.stConveyor.sConveyorName;
	    #fbFingerControl(stInSenRaster := #stInSenConvFingerInPos,
	                     xInErrorQuit := #xInErrorQuit,
	                     xInMotorRun := #xRunMotor);
	    
	END_REGION
	
	REGION Überwachung Carrier in Pos Sensor
	    #tOnJamCarrierInPos(IN := #xRunMotor,
	                        PT := t#3600s);
	    
	    IF #tOnJamCarrierInPos.ET > T#1s AND #stInSenCarrInPos.xDirectSensor AND #stInSenCarrInPos.tDirectChangeLast > t#3s THEN
	        #xSensorError := TRUE;
	    END_IF;
	    
	    IF #xSensorError AND #xInErrorQuit THEN
	        #xSensorError := FALSE;
	    END_IF;
	END_REGION
	
	REGION StateManager
	    
	    #fbStateManager.stInSettings.nStartState := #c0200_StepReceive;
	    #fbStateManager.stInSettings.xActUnivTOn := TRUE;
	    #fbStateManager.stInSettings.xRestartAtStartState := FALSE;
	    #fbStateManager(xInFunctionEnabled := ((#xInAutomatic AND #stInOutControlUnitCabinet.xRunning) OR #stInOutHMI.stConveyor.xSemiAuto) AND NOT #stInOutHMI.stConveyor.xDisableConveyor AND NOT #fbFingerControl.xOutErrorRasterSensor AND NOT #xSensorError,
	                    xInRunUnivTOn := #tmpActUnivTon,
	                    nOutStateLast => #nStateLast,
	                    nInOutState := #nState);
	END_REGION
	
	REGION Ausgänge
	    
	    // Das ist der Motor vom Förderer
	    #xOutMotor := #xRunMotor OR #stInOutHMI.stConveyor.xManual;  // Förderer-Motor angefordert und kein Bereichshalt
	    #xOutConveyorReady := #xConveyorReady; //Förderer bereit (aus SK) und kein Bereichshalt Förderer
	    
	    //????????????????????????????
	    #xOutConveyorReleaseReq := #nState = #c3000_StepEmptying OR #nState = #c1200_StepWaitTime;
	    
	END_REGION
	
	REGION Visu
	    
	    #stInOutHMI.stConveyor.nType := 7; // Vario
	    
	    #stInOutHMI.stConveyor.nState := #nState;
	    #stInOutHMI.stConveyor.sStateText := #sStateText;
	    
	    #stInOutHMI.FingerSensor := #stInSenConvFingerInPos;
	    #stInOutHMI.JamSensor := #stInSenJam;
	    #stInOutHMI.LastPosSensor := #stInSenLastPos;
	    
	    REGION Status
	        IF #xInMotorProtection THEN
	            IF #fbStateManager.xInFunctionEnabled THEN
	                CASE #nState OF
	                    #c0000_StepOff, #c0100_StepUndefined:
	                        #stInOutHMI.stConveyor.bStatus := 0; // NOT_AVAILABLE
	                    #c0200_StepReceive, #c1200_StepWaitTime, #c2000_StepJog, #c2250_StepQuickStop, #c2200_StepNormalStop, #c3000_StepEmptying, #c5000_StepEnding:
	                        #stInOutHMI.stConveyor.bStatus := 1; // AVAILABLE
	                    ELSE  //Fallback
	                        #stInOutHMI.stConveyor.bStatus := 0; // NOT_AVAILABLE
	                END_CASE;
	            ELSE
	                #stInOutHMI.stConveyor.bStatus := 0; // NOT_AVAILABLE
	            END_IF;
	        ELSE
	            #stInOutHMI.stConveyor.bStatus := 2; // ERROR
	        END_IF;
	    END_REGION
	    REGION Modes
	        // Int16 Bit-codiert
	        #stInOutHMI.stConveyor.nMode.%X0 := (#nState = #c0000_StepOff) OR (#nState = #c0100_StepUndefined) OR (#nState = #c0200_StepReceive) OR (#nState = #c1200_StepWaitTime) OR (#nState = #c2200_StepNormalStop) OR (#nState = #c2250_StepQuickStop); // The device is turned off
	        #stInOutHMI.stConveyor.nMode.%X1 := (#nState = #c2000_StepJog) OR (#nState = #c3000_StepEmptying) OR (#nState = #c5000_StepEnding);
	        #stInOutHMI.stConveyor.nMode.%X2 := #stInOutHMI.stConveyor.xDisableConveyor OR #stInOutHMI.stConveyor.xManual OR #stInOutHMI.stConveyor.xSemiAuto OR #xTestMode OR #stInOutHMI.stControl.xTestMode (* OR #xViSuManualMode OR #xViSuSemiAutoMode *); // The device is being manually operated
	        #stInOutHMI.stConveyor.nMode.%X3 := FALSE;//(#nState = #STOPPED); //The device only is on when the device is needed (like standby)
	        #stInOutHMI.stConveyor.nMode.%X10 := FALSE; // Overflow Error is set for this device
	    END_REGION
	    #stInOutHMI.stConveyor.xIsInAutomatic := #stInOutControlUnitCabinet.xRunning;
	    #stInOutHMI.stConveyor.xEnergySaveReq := FALSE;
	    #stInOutHMI.stConveyor.xPowerContactor := #xOutMotor;
	    #stInOutHMI.stConveyor.xPluggedChainBreak := FALSE;
	    #stInOutHMI.stConveyor.xStatusChainBreak := TRUE;
	    #stInOutHMI.stConveyor.xStatusMotorProtect := #xInMotorProtection;
	    #stInOutHMI.stConveyor.xConveyorFull1 := FALSE;
	    #stInOutHMI.stConveyor.xConveyorFull2 := FALSE;
	    #stInOutHMI.stConveyor.xReady2Receive := TRUE;
	    #stInOutHMI.stConveyor.xNextConveyorReady := TRUE;
	    
	END_REGION
	
	REGION Monitoring   
	    REGION Fingerüberwachung
	        #fbMonitoringFinger.stSettings.nErrorType := 1;
	        #fbMonitoringFinger.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonitoringFinger.stSettings.xSelfQuit := TRUE;
	        #fbMonitoringFinger.stSettings.tDelay := T#1s;
	        #fbMonitoringFinger(wInTextListId_Function := 300,
	                            sInPrefix := #stInOutHMI.stConveyor.sConveyorName,
	                            wInTextListId_Message := 301,
	                            sInSuffix := #stInOutHMI.FingerSensor.sName,
	                            xInQuitError := #stInOutControlUnitCabinet.xQuitError OR #xInErrorQuit,
	                            xInSignal := NOT #fbFingerControl.xOutErrorRasterSensor,
	                            InOutMachineState := #stInOutControlUnitCabinet);
	    END_REGION
	    
	    REGION Motorschutz
	        #fbMonitoringMotorProtection.stSettings.nErrorType := 1;
	        #fbMonitoringMotorProtection.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonitoringMotorProtection.stSettings.xSelfQuit := TRUE;
	        #fbMonitoringMotorProtection.stSettings.tDelay := T#1s;
	        #fbMonitoringMotorProtection(wInTextListId_Function := 300,
	                                     sInPrefix := #stInOutHMI.stConveyor.sConveyorName,
	                                     wInTextListId_Message := 401,
	                                     sInSuffix := #stInOutHMI.stConveyor.sContactor,
	                                     xInQuitError := #stInOutControlUnitCabinet.xQuitError OR #xInErrorQuit,
	                                     xInSignal := #xInMotorProtection,
	                                     InOutMachineState := #stInOutControlUnitCabinet);
	    END_REGION
	    
	    REGION Carrier in Pos
	        #fbMonitoringCarrierInPos.stSettings.nErrorType := 1;
	        #fbMonitoringCarrierInPos.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonitoringCarrierInPos.stSettings.xSelfQuit := TRUE;
	        #fbMonitoringCarrierInPos.stSettings.tDelay := T#1s;
	        #fbMonitoringCarrierInPos(wInTextListId_Function := 300,
	                                     sInPrefix := #stInOutHMI.stConveyor.sConveyorName,
	                                     wInTextListId_Message := 302,
	                                     sInSuffix := #stInSenCarrInPos.sName,
	                                     xInQuitError := #stInOutControlUnitCabinet.xQuitError OR #xInErrorQuit,
	                                     xInSignal := NOT #xSensorError,
	                                     InOutMachineState := #stInOutControlUnitCabinet);
	        
	    END_REGION
	    
	END_REGION
	
	REGION Error 
	    #wOutErrorWord.%X0 := #stInOutHMI.stConveyor.bStatus = 2; //Error
	    #wOutErrorWord.%X1 := #fbFingerControl.xOutErrorRasterSensor; //Fingerfehler
	    #wOutErrorWord.%X2 := NOT #xInMotorProtection; //Motorschutzfehler
	    #wOutErrorWord.%X3 := #xSensorError;
	END_REGION
END_FUNCTION_BLOCK

