FUNCTION_BLOCK "FB_PreMain"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_IN_OUT 
      stInOutControlUnitCabinet : "UDT_MainState";
   END_VAR

   VAR 
      xAllMainContactorsOk { S7_SetPoint := 'True'} : Bool;
      fbMonPhaseFailure : "FB_Monitoring";
      fbMonMotorProtection : "FB_Monitoring";
      fbMonPreFuse : "FB_Monitoring";
      fbMonFuse400V : "FB_Monitoring";
      fbMonFuse24V : "FB_Monitoring";
      fbMonPressure : "FB_Monitoring";
      fbMonMainContactors : "FB_Monitoring";
      fbMonSafetyContactorsUH05toUH02 : "FB_Monitoring";
      fbMonSafetyContactorsUH05toUH07 : "FB_Monitoring";
      fbMonSafetyContactorsUH05toFORTNA : "FB_Monitoring";
      fbMonFAS : "FB_Monitoring";   // IF from FACP "fire alarm" DI0034
      fbMonCommFortnaWCS : "FB_Monitoring";   // WCS
      fbMonCommFortnaWES_DH : "FB_Monitoring";   // Device Hub
      xAllReadyToStart : Bool;
      xQuitNec : Bool;
      fbStateMain : "FB_StateMain";
      arESTOPAck : Array[0..30] of "FB_ESTOPhandling";
      xReInit : Bool;
      fTrigReIntTime {InstructionName := 'F_TRIG'; LibVersion := '1.0'} : F_TRIG;
      tOfReIntTime {InstructionName := 'TOF_TIME'; LibVersion := '1.0'} : TOF_TIME;   // nach Hochfahren vergeht diese Zeit bis erstmalig Quit
   END_VAR

   VAR_TEMP 
      tDebug : Int;
      nIdx : USInt;
   END_VAR

   VAR CONSTANT 
      c_UH05 : Int := 0;
      c_UZ0501 : Int := 1;
      c_UZ0502 : Int := 2;
      c_UZ0503 : Int := 3;
      c_UZ0504 : Int := 4;
      c_UZ0505 : Int := 5;
      c_UZ0506 : Int := 6;
      c_UZ0507 : Int := 7;
      c_UH05_Extern1 : Int := 8;
      c_UH05_Extern2 : Int := 9;
      c_UH05_Extern3 : Int := 10;
   END_VAR


BEGIN
	
	REGION Reinitialisieren
	    #tOfReIntTime(IN := NOT #xReInit,
	                  PT := T#10s);
	    
	    IF NOT #xReInit THEN
	        #xReInit := TRUE;
	    END_IF;
	    
	    #fTrigReIntTime(CLK := #tOfReIntTime.Q);
	    
	END_REGION
	
	REGION CycleTime
	    // "DB_MachineGlobal".nLogicCycle := "DB_MachineGlobal".nLogicCycle + 1;
	    #tDebug := RD_SYS_T("DB_MachineGlobal".TimePLC);
	    // #fbCycleTime("DB_MachineGlobal".nPrevCycle);
	END_REGION
	
	REGION Alarmnummern zurücksetzten
	    IF "DB_MachineGlobal".Cold_Restart THEN
	        "DB_AlarmGlobal".nAlarmNoOffsetGlobal := 10;
	    END_IF;
	END_REGION
	
	REGION Monitoring
	    REGION Pressure
	        #fbMonPressure.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonPressure.stSettings.xSelfQuit := FALSE;
	        #fbMonPressure(sInPrefix := 'UH05',
	                       sInSuffix := 'BP0004',
	                       wInTextListId_Function := 5,
	                       wInTextListId_Message := 4,
	                       xInQuitError := #stInOutControlUnitCabinet.xQuitError,
	                       xInSignal := "BP0004",
	                       InOutMachineState := #stInOutControlUnitCabinet,
	                       stOutHMI => "DB_Interface_HMI".stSystem.stPressure.UH05);
	    END_REGION
	    
	    REGION Phase failure
	        #fbMonPhaseFailure.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonPhaseFailure.stSettings.xSelfQuit := FALSE;
	        #fbMonPhaseFailure(sInPrefix := 'UH05',
	                           sInSuffix := 'KF0005/DI0005',
	                           wInTextListId_Function := 6,
	                           wInTextListId_Message := 2,
	                           xInQuitError := #stInOutControlUnitCabinet.xQuitError,
	                           xInSignal := "DI0005",
	                           InOutMachineState := #stInOutControlUnitCabinet,
	                           stOutHMI => "DB_Interface_HMI".stSystem.stPhase.UH05_400V);
	    END_REGION
	    
	    REGION 400V
	        #fbMonFuse400V.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonFuse400V.stSettings.xSelfQuit := FALSE;
	        #fbMonFuse400V(sInPrefix := 'UH05 400V',
	                       sInSuffix := 'FC006/DI0006',
	                       wInTextListId_Function := 4,
	                       wInTextListId_Message := 3,
	                       xInQuitError := #stInOutControlUnitCabinet.xQuitError,
	                       xInSignal := "DI0006",
	                       InOutMachineState := #stInOutControlUnitCabinet,
	                       stOutHMI => "DB_Interface_HMI".stSystem.stFuse.UH05_400V);
	    END_REGION
	    
	    REGION Vorsicherung
	        #fbMonPreFuse.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonPreFuse.stSettings.xSelfQuit := FALSE;
	        #fbMonPreFuse(sInPrefix := 'UH05 PreFuse',
	                      sInSuffix := 'FC005/DI0016',
	                      wInTextListId_Function := 4,
	                      wInTextListId_Message := 3,
	                      xInQuitError := #stInOutControlUnitCabinet.xQuitError,
	                      xInSignal := "DI0016",
	                      InOutMachineState := #stInOutControlUnitCabinet,
	                      stOutHMI => "DB_Interface_HMI".stSystem.stFuse.UH05_PreFuse);
	    END_REGION
	    
	    REGION 24V
	        #fbMonFuse24V.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonFuse24V.stSettings.xSelfQuit := FALSE;
	        #fbMonFuse24V(sInPrefix := 'UH05 24V',
	                      sInSuffix := 'FC0021-FC0023',
	                      wInTextListId_Function := 4,
	                      wInTextListId_Message := 3,
	                      xInQuitError := #stInOutControlUnitCabinet.xQuitError,
	                      xInSignal := "DI0021" AND "DI0022" AND "DI0023",
	                      InOutMachineState := #stInOutControlUnitCabinet,
	                      stOutHMI => "DB_Interface_HMI".stSystem.stFuse.UH05_24V);
	    END_REGION
	    
	    REGION Hauptschütze
	        #fbMonMainContactors.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonMainContactors.stSettings.xSelfQuit := FALSE;
	        #fbMonMainContactors(sInPrefix := 'UH05',
	                             sInSuffix := 'QA0610/QA0611',
	                             wInTextListId_Function := 7,
	                             wInTextListId_Message := 5,
	                             xInQuitError := #stInOutControlUnitCabinet.xQuitError,
	                             xInSignal := "DB_InterfaceSafety".stFromSafety.stMainContactorsUH05.xOk,
	                             InOutMachineState := #stInOutControlUnitCabinet,
	                             stOutHMI => "DB_Interface_HMI".stSystem.stMainContactor.UH05);
	    END_REGION
	    
	    REGION Sicherheitsrelais UH05 to UH02
	        #fbMonSafetyContactorsUH05toUH02.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonSafetyContactorsUH05toUH02.stSettings.xSelfQuit := FALSE;
	        #fbMonSafetyContactorsUH05toUH02(sInPrefix := 'UH05/UH02',
	                                         sInSuffix := 'QA0660/QA0660',
	                                         wInTextListId_Function := 9,
	                                         wInTextListId_Message := 9,
	                                         xInQuitError := #stInOutControlUnitCabinet.xQuitError,
	                                         xInSignal := "DB_InterfaceSafety".stFromSafety.stSafetyContactorsUH05toUH02.xOk,
	                                         InOutMachineState := #stInOutControlUnitCabinet,
	                                         stOutHMI => "DB_Interface_HMI".stSystem.stMainContactor.UH05toUH02);
	    END_REGION
	    
	    REGION Sicherheitsrelais UH05 to UH07
	        #fbMonSafetyContactorsUH05toUH07.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonSafetyContactorsUH05toUH07.stSettings.xSelfQuit := FALSE;
	        #fbMonSafetyContactorsUH05toUH07(sInPrefix := 'UH05/UH07',
	                                         sInSuffix := 'QA0612/QA0613',
	                                         wInTextListId_Function := 9,
	                                         wInTextListId_Message := 9,
	                                         xInQuitError := #stInOutControlUnitCabinet.xQuitError,
	                                         xInSignal := "DB_InterfaceSafety".stFromSafety.stSafetyContactorsUH05toUH07.xOk,
	                                         InOutMachineState := #stInOutControlUnitCabinet,
	                                         stOutHMI => "DB_Interface_HMI".stSystem.stMainContactor.UH05toUH07);
	    END_REGION
	    
	    REGION Sicherheitsrelais UH05 to FORTNA
	        #fbMonSafetyContactorsUH05toFORTNA.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonSafetyContactorsUH05toFORTNA.stSettings.xSelfQuit := FALSE;
	        #fbMonSafetyContactorsUH05toFORTNA(sInPrefix := 'UH05/FortnaC',
	                                           sInSuffix := 'QA0662/QA0663',
	                                           wInTextListId_Function := 9,
	                                           wInTextListId_Message := 9,
	                                           xInQuitError := #stInOutControlUnitCabinet.xQuitError,
	                                           xInSignal := "DB_InterfaceSafety".stFromSafety.stsafetyContactorsUH05toFORTNA.xOk,
	                                           InOutMachineState := #stInOutControlUnitCabinet,
	                                           stOutHMI => "DB_Interface_HMI".stSystem.stMainContactor.UH05toFORTNA);
	    END_REGION
	    
	    REGION Motor protection
	        #fbMonMotorProtection.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonMotorProtection.stSettings.xSelfQuit := FALSE;
	        #fbMonMotorProtection(sInPrefix := 'UH05',
	                              sInSuffix := 'FC0060-FC0072',
	                              wInTextListId_Function := 3,
	                              wInTextListId_Message := 1,
	                              xInQuitError := #stInOutControlUnitCabinet.xQuitError,
	                              xInSignal := "FC0060" AND "FC0061" AND "FC0062" AND "FC0063" AND
	                              "FC0064" AND "FC0065" AND "FC0066" AND "FC0067" AND "FC0070" AND "FC0071" AND "FC0072",
	                              InOutMachineState := #stInOutControlUnitCabinet,
	                              stOutHMI => "DB_Interface_HMI".stSystem.stMotorProtection.UH05);
	    END_REGION
	    
	    REGION Fire Alarm
	        #fbMonFAS.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonFAS.stSettings.xSelfQuit := FALSE;
	        #fbMonFAS(sInPrefix := 'UH05/FAS',
	                  sInSuffix := 'DI0034',
	                  wInTextListId_Function := 8,
	                  wInTextListId_Message := 6,
	                  xInQuitError := "DB_MachineGlobal".stStateMain.xQuitError,
	                  xInSignal := "DI0034",
	                  InOutMachineState := "DB_MachineGlobal".stStateMain,
	                  stOutHMI => "DB_Interface_HMI".stSystem.stFireControl.stNoFireAlarmFAS);
	        
	    END_REGION
	    
	    REGION MISC (nicht für AllReadyToStart)
	        
	        REGION TCP-Kommunikation
	            REGION Fortna WCS
	                #fbMonCommFortnaWCS.stSettings.xErrLedIfMachineIsOff := TRUE;
	                #fbMonCommFortnaWCS.stSettings.xSelfQuit := TRUE;
	                #fbMonCommFortnaWCS(sInPrefix := 'UH05',
	                                    sInSuffix := 'Fortna WCS',
	                                    wInTextListId_Function := 20000,
	                                    wInTextListId_Message := 20000,
	                                    xInQuitError := #stInOutControlUnitCabinet.xQuitError,
	                                    xInSignal := "FB_CommunicationWCSBL_DB".fbTeleHandler.xOutConnectionActive,
	                                    InOutMachineState := #stInOutControlUnitCabinet,
	                                    stOutHMI => "DB_Interface_HMI".stSystem.stExternal.TCPFortnaWCS);
	            END_REGION
	            
	            REGION Fortna WES
	                #fbMonCommFortnaWES_DH.stSettings.xErrLedIfMachineIsOff := TRUE;
	                #fbMonCommFortnaWES_DH.stSettings.xSelfQuit := TRUE;
	                #fbMonCommFortnaWES_DH(sInPrefix := 'UH05',
	                                       sInSuffix := 'Fortna WES DeviceHub',
	                                       wInTextListId_Function := 20000,
	                                       wInTextListId_Message := 20000,
	                                       xInQuitError := #stInOutControlUnitCabinet.xQuitError,
	                                       xInSignal := "FB_CommunicationWES_DeviceHub_DB".fbTeleHandler.xOutConnectionActive,
	                                       InOutMachineState := #stInOutControlUnitCabinet,
	                                       stOutHMI => "DB_Interface_HMI".stSystem.stExternal.TCPFortnaWES_DH);
	            END_REGION
	        END_REGION
	    END_REGION
	END_REGION
	
	REGION AllReadyToStart
	    
	    #xAllReadyToStart := #fbMonPhaseFailure.xOutOk AND
	    #fbMonFuse24V.xOutOk AND
	    #fbMonFuse400V.xOutOk AND
	    #fbMonPreFuse.xOutOk AND
	    #fbMonPressure.xOutOk AND
	    #fbMonMotorProtection.xOutOk AND
	    #fbMonMainContactors.xOutOk AND
	    #fbMonSafetyContactorsUH05toFORTNA.xOutOk AND
	    #fbMonSafetyContactorsUH05toUH02.xOutOk AND
	    #fbMonSafetyContactorsUH05toUH07.xOutOk AND
	    #fbMonFAS.xOutOk;
	    
	END_REGION
	
	REGION StateMain
	    
	    #fbStateMain.stSettings.xEnableStartUpWarning := TRUE;
	    #fbStateMain.stSettings.tStartUpTime := T#5s;
	    #fbStateMain(xInBtnMachineOn := "SF0001",
	                 xInBtnMachineNotOff := "SF0000",
	                 xInBtnTrigMot := "SF0002",
	                 xInBtnQuitError := "SF0002",
	                 xInAllReadyToStart := #xAllReadyToStart,
	                 xInAllInExecute := TRUE,
	                 xInAllStarted := TRUE,
	                 xInSafetyActive := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,//("Main_Safety_RTG1_DB".ESTOP1_Main.Q AND NOT "Main_Safety_RTG1_DB".FDBACK_UH05.ACK_REQ AND NOT "Main_Safety_RTG1_DB".FDBACK_UH05.ERROR),
	                 xInAllInSafeState := "DB_InterfaceSafety".stFromSafety.EStopMain.Q,//("Main_Safety_RTG1_DB".ESTOP1_Main.Q AND NOT "Main_Safety_RTG1_DB".FDBACK_UH05.ACK_REQ AND NOT "Main_Safety_RTG1_DB".FDBACK_UH05.ERROR),
	                 stInOutControlUnitCabinet := "DB_MachineGlobal".stStateMain,
	                 stInOutHMI := "DB_Interface_HMI".stStateMachine);
	END_REGION
	
	REGION SCADA-Interface
	    "FB-OPC_UA_System-Stat_DB"(nInSystemStat := #fbStateMain.nState,
	                               xInFireAlarm := #fbMonFAS.xOutError,
	                               xInSafetyStop := NOT "DB_InterfaceSafety".stFromSafety.EStopMain.Q,
	                               xInError := "DB_Interface_HMI".nActiveAlarms > 0,
	                               xInCommunicationError := #fbMonCommFortnaWCS.xOutError OR #fbMonCommFortnaWES_DH.xOutError,
	                               nOutScadaStatus => "DB_Status".System.Status);
	END_REGION
	
	REGION Interface Safety
	    
	    REGION to Safety
	        
	        "DB_InterfaceSafety".stToSafety.xAckGlob := "IBN".xAckGlob OR #fTrigReIntTime.Q;
	        
	        "DB_InterfaceSafety".stToSafety.xQuitButtonHss := "SF0002" OR "IBN".xQuitGlob OR #stInOutControlUnitCabinet.xQuitError OR #fTrigReIntTime.Q;
	        "DB_InterfaceSafety".stToSafety.xQuitButtonUZ0501 := "SF0041" OR #fTrigReIntTime.Q;
	        "DB_InterfaceSafety".stToSafety.xQuitButtonUZ0502 := "SF0043" OR #fTrigReIntTime.Q;
	        
	        "DB_InterfaceSafety".stToSafety.xQuitButtonUZ0504 := "SF0047" OR #fTrigReIntTime.Q;
	        
	        "DB_InterfaceSafety".stToSafety.xQuitButtonUZ0506 := "SF0053" OR #fTrigReIntTime.Q;
	        "DB_InterfaceSafety".stToSafety.xQuitButtonUZ0507 := "SF0055" OR #fTrigReIntTime.Q;
	        "DB_InterfaceSafety".stToSafety.xQuitButtonUZ0508 := "SF0057" OR #fTrigReIntTime.Q;
	        
	        "DB_InterfaceSafety".stToSafety.stMainContactorsUH05.xFeedback := "DI0013";
	        "DB_InterfaceSafety".stToSafety.stSafetyContactorsUH05toUH02.xFeedback := "DI0014";
	        "DB_InterfaceSafety".stToSafety.stSafetyContactorsUH05toUH07.xFeedback := "DI0012";
	        "DB_InterfaceSafety".stToSafety.stSafetyContactorsUH05toFORTNA.xFeedback := "DI0015";
	        
	        "DB_InterfaceSafety".stToSafety.xMachineRunning := #stInOutControlUnitCabinet.xRunning;
	        "DB_InterfaceSafety".stToSafety.xMachineStarting := #stInOutControlUnitCabinet.xStarting;
	        
	    END_REGION
	    
	END_REGION
	
	REGION Outputs
	    
	    //E-Stop Signalsäule
	    "PF0030" := "SF0003" OR NOT "DB_InterfaceSafety".stFromSafety.EStopMain.Q
	    OR #fbMonFAS.xOutError;
	    
	    //Anfahrwarnung Signalsäule
	    "PF0033" := "DB_MachineGlobal".stStateMain.xStartUpWarning AND "Clock_1Hz";
	    
	    //LED Störung + Signalsäule gelb
	    "PF0000" := "PF0031" := "SF0003" OR
	    #fbMonFuse24V.xOutLedError OR
	    #fbMonFuse400V.xOutLedError OR
	    #fbMonMotorProtection.xOutLedError OR
	    #fbMonPhaseFailure.xOutLedError OR
	    #fbMonPressure.xOutLedError OR
	    #fbMonMainContactors.xOutLedError OR
	    #fbMonSafetyContactorsUH05toFORTNA.xOutLedError OR
	    #fbMonSafetyContactorsUH05toUH02.xOutLedError OR
	    #fbMonSafetyContactorsUH05toUH07.xOutLedError;
	    
	    //LED Ein + Signalsäule grün
	    "PF0001" := "PF0032" := "PF0054" := "SF0003" OR ("DB_MachineGlobal".stStateMain.xRunning AND NOT "DB_MachineGlobal".stStateMain.xStartUpWarning) OR
	    (NOT "DB_MachineGlobal".stStateMain.xRunning AND "DB_MachineGlobal".stStateMain.xStartUpWarning);
	    
	    //LED Start nach Störung
	    "PF0002" := "SF0003" OR #arESTOPAck[0].xOutLed (* OR NOT #xAllReadyToStart *)OR
	    (#fbMonPhaseFailure.xOutAckReq AND "Clock_1Hz") OR
	    (#fbMonFuse24V.xOutAckReq AND "Clock_1Hz") OR
	    (#fbMonFuse400V.xOutAckReq AND "Clock_1Hz") OR
	    (#fbMonPressure.xOutAckReq AND "Clock_1Hz") OR
	    (#fbMonMainContactors.xOutAckReq AND "Clock_1Hz") OR
	    (#fbMonSafetyContactorsUH05toFORTNA.xOutAckReq AND "Clock_1Hz") OR
	    (#fbMonSafetyContactorsUH05toUH02.xOutAckReq AND "Clock_1Hz") OR
	    (#fbMonSafetyContactorsUH05toUH07.xOutAckReq AND "Clock_1Hz") OR
	    (#fbMonFAS.xOutAckReq AND "Clock_1Hz");
	    
	    //LED Druckluft
	    "PF0003" := "SF0003" OR #fbMonPressure.xOutLedError;
	    
	    //LED Motorschutz
	    "PF0004" := "SF0003" OR #fbMonMotorProtection.xOutLedError;
	    
	    //LED Sicherung
	    "PF0005" := "SF0003" OR #fbMonFuse24V.xOutLedError OR #fbMonFuse400V.xOutLedError;
	    
	    //LED Brandfall
	    "PF0006" := "SF0003" OR #fbMonFAS.xOutError;
	    
	    REGION UZ0501
	        //Ready for use
	        "PF0040" := ("DB_MachineGlobal".stStateMain.xRunning AND NOT "DB_MachineGlobal".stStateMain.xStartUpWarning) OR
	        (NOT "DB_MachineGlobal".stStateMain.xRunning AND "DB_MachineGlobal".stStateMain.xStartUpWarning) OR "SF0003";
	        //Release
	        "PF0056" := "fbMain_DB".TRO529.nState > 1000 OR "SF0003";
	        
	        //Reset
	        "PF0041" := ("fbMain_DB".fbCarousel5002.xOutGridError AND "Clock_1Hz") OR
	        #arESTOPAck[#c_UZ0501].xOutLed OR "SF0003";
	    END_REGION
	    
	    REGION UZ0502
	        //Ready for use
	        "PF0042" := ("DB_MachineGlobal".stStateMain.xRunning AND NOT "DB_MachineGlobal".stStateMain.xStartUpWarning) OR
	        (NOT "DB_MachineGlobal".stStateMain.xRunning AND "DB_MachineGlobal".stStateMain.xStartUpWarning) OR "SF0003";
	        //Release
	        "PF0073" := "fbMain_DB".TRO508.nState > 1000 OR "SF0003";
	    END_REGION
	    
	    (*  REGION UZ0503
	          //Ready for use
	          "PF0044" := ("DB_MachineGlobal".stStateMain.xRunning AND NOT"DB_MachineGlobal".stStateMain.xStartUpWarning) OR
	          (NOT "DB_MachineGlobal".stStateMain.xRunning AND "DB_MachineGlobal".stStateMain.xStartUpWarning);
	          //Release
	          "PF0074" := "fbMain_DB".TRO512.nState > 1000;
	      END_REGION *)
	    
	    REGION UZ0504
	        //Ready for use
	        "PF0046" := ("DB_MachineGlobal".stStateMain.xRunning AND NOT "DB_MachineGlobal".stStateMain.xStartUpWarning) OR
	        (NOT "DB_MachineGlobal".stStateMain.xRunning AND "DB_MachineGlobal".stStateMain.xStartUpWarning) OR "SF0003";
	        //Release
	        "PF0075" := "fbMain_DB".TRO516.nState > 1000 OR "SF0003";
	    END_REGION
	    
	    (*  REGION UZ0505
	          //Ready for use
	          "PF0050"  := ("DB_MachineGlobal".stStateMain.xRunning AND NOT"DB_MachineGlobal".stStateMain.xStartUpWarning) OR
	          (NOT "DB_MachineGlobal".stStateMain.xRunning AND "DB_MachineGlobal".stStateMain.xStartUpWarning);
	          //Release
	          "PF0076" := "fbMain_DB".TRO520.nState > 1000;
	      END_REGION *)
	    
	    REGION UZ0506
	        //Ready for use
	        "PF0052" := ("DB_MachineGlobal".stStateMain.xRunning AND NOT "DB_MachineGlobal".stStateMain.xStartUpWarning) OR
	        (NOT "DB_MachineGlobal".stStateMain.xRunning AND "DB_MachineGlobal".stStateMain.xStartUpWarning) OR "SF0003";
	        //Release
	        "PF0077" := "fbMain_DB".TRO524.nState > 1000 OR "SF0003";
	    END_REGION
	END_REGION
	
	REGION Not-Halt Tableaus
	    REGION UH05 Hauptschaltschrank
	        #arESTOPAck[#c_UH05](sInAlarmFunction := 'HSS',
	                             sInAlarmDevice := 'UH05',
	                             sInAlarmMessage := 'Not-Halt aktiv',
	                             sInAlarmSuffix := 'PF0002',
	                             wInTextListId_Function := 0,
	                             wInTextListId_Message := 0,
	                             xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopUH05.AckReq,
	                             xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopUH05.Q,
	                             xInAckReqGlobal :=
	                             #arESTOPAck[#c_UZ0501].xOutAckReq OR
	                             #arESTOPAck[#c_UZ0502].xOutAckReq OR
	                             #arESTOPAck[#c_UZ0504].xOutAckReq OR
	                             #arESTOPAck[#c_UZ0506].xOutAckReq OR
	                             #arESTOPAck[#c_UZ0507].xOutAckReq OR
	                             #arESTOPAck[#c_UH05_Extern1].xOutAckReq OR
	                             #arESTOPAck[#c_UH05_Extern2].xOutAckReq OR
	                             #arESTOPAck[#c_UH05_Extern3].xOutAckReq,
	                             xInSafetyNotOkGlobal :=
	                             #arESTOPAck[#c_UZ0501].xOutSafetyNotOk OR
	                             #arESTOPAck[#c_UZ0502].xOutSafetyNotOk OR
	                             #arESTOPAck[#c_UZ0504].xOutSafetyNotOk OR
	                             #arESTOPAck[#c_UZ0506].xOutSafetyNotOk OR
	                             #arESTOPAck[#c_UZ0507].xOutSafetyNotOk OR
	                             #arESTOPAck[#c_UH05_Extern1].xOutSafetyNotOk OR
	                             #arESTOPAck[#c_UH05_Extern2].xOutSafetyNotOk OR
	                             #arESTOPAck[#c_UH05_Extern3].xOutSafetyNotOk,
	                             xInMainCabinet := TRUE,
	                             //        xOutLed => "PF0002",
	                             stInOutControlUnitCabinet := "DB_MachineGlobal".stStateMain,
	                             stInOutHmiEstopPanel := "DB_Interface_HMI".arEstops[0]);
	    END_REGION
	    
	    REGION UH05 Extern1 / UH02
	        #arESTOPAck[#c_UH05_Extern1](sInAlarmDevice := 'UH05_Ext1/UH02',
	                                     sInAlarmSuffix := 'SF0541',
	                                     wInTextListId_Function := 20,
	                                     wInTextListId_Message := 20,
	                                     stInOutHmiEstopPanel := "DB_Interface_HMI".arEstops[#c_UH05_Extern1],
	                                     stInOutControlUnitCabinet := #stInOutControlUnitCabinet,
	                                     xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopExternUH02.AckReq,
	                                     xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopExternUH02.Q);
	        
	    END_REGION
	    REGION UH05 Extern2 / Fortna
	        #arESTOPAck[#c_UH05_Extern2](sInAlarmDevice := 'UH05_Ext2/Fortna',
	                                     sInAlarmSuffix := 'SF0542',
	                                     wInTextListId_Function := 20,
	                                     wInTextListId_Message := 20,
	                                     stInOutHmiEstopPanel := "DB_Interface_HMI".arEstops[#c_UH05_Extern2],
	                                     stInOutControlUnitCabinet := #stInOutControlUnitCabinet,
	                                     xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopExternFortnaC.AckReq,
	                                     xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopExternFortnaC.Q);
	        
	    END_REGION
	    REGION UH05 Extern3 / UH07
	        #arESTOPAck[#c_UH05_Extern3](sInAlarmDevice := 'UH05_Ext3/UH07',
	                                     sInAlarmSuffix := 'SF0543',
	                                     wInTextListId_Function := 20,
	                                     wInTextListId_Message := 20,
	                                     stInOutHmiEstopPanel := "DB_Interface_HMI".arEstops[#c_UH05_Extern3],
	                                     stInOutControlUnitCabinet := #stInOutControlUnitCabinet,
	                                     xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopExternUH07.AckReq,
	                                     xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopExternUH07.Q);
	        
	    END_REGION
	    REGION UZ0501
	        #arESTOPAck[#c_UZ0501](sInAlarmFunction := 'Bedientableau',
	                               sInAlarmDevice := 'UZ0501',
	                               sInAlarmMessage := 'Not-Halt aktiv',
	                               sInAlarmSuffix := 'PF0041',
	                               wInTextListId_Function := 1,
	                               wInTextListId_Message := 0,
	                               stInOutHmiEstopPanel := "DB_Interface_HMI".arEstops[#c_UZ0501],
	                               stInOutControlUnitCabinet := #stInOutControlUnitCabinet,
	                               xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0501.AckReq,
	                               xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0501.Q);
	        // xOutLed => "PF0041");
	    END_REGION
	    REGION UZ0502
	        #arESTOPAck[#c_UZ0502](sInAlarmFunction := 'Bedientableau',
	                               sInAlarmDevice := 'UZ0502',
	                               sInAlarmMessage := 'Not-Halt aktiv',
	                               sInAlarmSuffix := 'PF0043',
	                               wInTextListId_Function := 1,
	                               wInTextListId_Message := 0,
	                               stInOutHmiEstopPanel := "DB_Interface_HMI".arEstops[#c_UZ0502],
	                               stInOutControlUnitCabinet := #stInOutControlUnitCabinet,
	                               xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0502.AckReq,
	                               xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0502.Q);
	        // xOutLed => "PF0043");
	        "PF0043" := #arESTOPAck[#c_UZ0502].xOutLed OR "SF0003";
	    END_REGION
	    
	    REGION UZ0504
	        #arESTOPAck[#c_UZ0504](sInAlarmFunction := 'Bedientableau',
	                               sInAlarmDevice := 'UZ0504',
	                               sInAlarmMessage := 'Not-Halt aktiv',
	                               sInAlarmSuffix := 'PF0047',
	                               wInTextListId_Function := 1,
	                               wInTextListId_Message := 0,
	                               stInOutHmiEstopPanel := "DB_Interface_HMI".arEstops[#c_UZ0504],
	                               stInOutControlUnitCabinet := #stInOutControlUnitCabinet,
	                               xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0504.AckReq,
	                               xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0504.Q);
	        // xOutLed => "PF0047");
	        "PF0047" := #arESTOPAck[#c_UZ0504].xOutLed OR "SF0003";
	    END_REGION
	    
	    REGION UZ0506
	        #arESTOPAck[#c_UZ0506](sInAlarmFunction := 'Bedientableau',
	                               sInAlarmDevice := 'UZ0506',
	                               sInAlarmMessage := 'Not-Halt aktiv',
	                               sInAlarmSuffix := 'PF0053',
	                               wInTextListId_Function := 1,
	                               wInTextListId_Message := 0,
	                               stInOutHmiEstopPanel := "DB_Interface_HMI".arEstops[#c_UZ0506],
	                               stInOutControlUnitCabinet := #stInOutControlUnitCabinet,
	                               xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0506.AckReq,
	                               xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0506.Q);
	        // xOutLed => "PF0053");
	        "PF0053" := #arESTOPAck[#c_UZ0506].xOutLed OR "SF0003";
	    END_REGION
	    REGION UZ0507
	        #arESTOPAck[#c_UZ0507](sInAlarmFunction := 'Bedientableau',
	                               sInAlarmDevice := 'UZ0507',
	                               sInAlarmMessage := 'Not-Halt aktiv',
	                               sInAlarmSuffix := 'PF0055',
	                               wInTextListId_Function := 1,
	                               wInTextListId_Message := 0,
	                               stInOutHmiEstopPanel := "DB_Interface_HMI".arEstops[#c_UZ0507],
	                               stInOutControlUnitCabinet := #stInOutControlUnitCabinet,
	                               xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0507.AckReq,
	                               xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0507.Q);
	        // xOutLed => "PF0055");
	        "PF0055" := #arESTOPAck[#c_UZ0507].xOutLed OR "SF0003";
	    END_REGION
	    
	END_REGION
END_FUNCTION_BLOCK

