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

   VAR 
      fbMonMotorProtection : "FB_Monitoring";
      fbMonPhaseFailure : "FB_Monitoring";
      fbMonFuse400V : "FB_Monitoring";
      fbMonFuse24V : "FB_Monitoring";
      fbMonPressure : "FB_Monitoring";
      fbMonMainContactorsUH04 : "FB_Monitoring";
      fbMonSafetyContactorsExternOmniflo : "FB_Monitoring";
      fbMonSafetyContactorsExternReserve : "FB_Monitoring";
      fbMonFAS1 : "FB_Monitoring";   // IF from FACP "fire alarm" DI0034
      fbMonFAS2 : "FB_Monitoring";   // IF from FACP "fire alarm" DI0033
      fbMonFPG_Open : "FB_Monitoring";   // Control from FPG
      fbMonFPG_Fault : "FB_Monitoring";   // Control from FPG
      fbMonFPG_Fire : "FB_Monitoring";   // Control from FPG
      fbMonCommFortnaWCS : "FB_Monitoring";
      fbMonCommFortnaWESDeviceHub : "FB_Monitoring";
      xAllReadyToStart { S7_SetPoint := 'True'} : Bool;
      fbStateMain : "FB_StateMain";
      arESTOPAck { S7_SetPoint := 'False'} : Array[0..4] 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_UH04 : Int := 0;   // Konstante für ESTOP
      c_UZ0409 : Int := 1;   // Konstante für ESTOP
      c_UH04_Extern1 : Int := 2;   // Konstante für ESTOP
      c_UH04_Extern2 : Int := 3;   // Konstante für ESTOP
   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 := stInOutControlUnitCabinet.nLogicCycle + 1;
	    #tDebug := RD_SYS_T("DB_MachineGlobal".TimePLC);
	    // #fbCycleTime("DB_MachineGlobal".nPrevCycle);
	END_REGION
	
	REGION Monitoring
	    REGION Motor protection
	        #fbMonMotorProtection.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonMotorProtection.stSettings.xSelfQuit := FALSE;
	        #fbMonMotorProtection(sInFctnName := 'Motorschutz',
	                              sInPrefix := 'UH04',
	                              sInAlarmMessage := 'Motorschutz ausgeloest',
	                              sInSuffix := 'FC0060-FC0074',
	                              wInTextListId_Function := 3,
	                              wInTextListId_Message := 1,
	                              xInQuitError := #stInOutControlUnitCabinet.xQuitError,
	                              xInSignal := "FC0060" AND "FC0061" AND "FC0062" AND "FC0063" AND "FC0064" AND "FC0065" AND "FC0066" AND
	                              "FC0070" AND "FC0071" AND "FC0072" AND "FC0073" AND "FC0074",
	                              InOutMachineState := #stInOutControlUnitCabinet,
	                              stOutHMI => "DB_Interface_HMI".stSystem.stMotorProtection.UH04);
	    END_REGION
	    
	    REGION Phase failure
	        #fbMonPhaseFailure.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonPhaseFailure.stSettings.xSelfQuit := FALSE;
	        #fbMonPhaseFailure(sInFctnName := 'Phasenausfall',
	                           sInPrefix := 'UH04',
	                           sInAlarmMessage := 'Phase ausgefallen',
	                           sInSuffix := 'DI0005',
	                           wInTextListId_Function := 6,
	                           wInTextListId_Message := 2,
	                           xInQuitError := #stInOutControlUnitCabinet.xQuitError,
	                           xInSignal := "DI0005",
	                           InOutMachineState := #stInOutControlUnitCabinet,
	                           stOutHMI => "DB_Interface_HMI".stSystem.stPhase.UH04_400V);
	    END_REGION
	    
	    REGION 400V
	        #fbMonFuse400V.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonFuse400V.stSettings.xSelfQuit := FALSE;
	        #fbMonFuse400V(sInFctnName := 'Sicherungsfall',
	                       sInPrefix := 'UH04 400V',
	                       sInAlarmMessage := 'Sicherung ausgeloest',
	                       sInSuffix := 'DI0016',
	                       wInTextListId_Function := 4,
	                       wInTextListId_Message := 3,
	                       xInQuitError := #stInOutControlUnitCabinet.xQuitError,
	                       xInSignal := "DI0016",
	                       InOutMachineState := #stInOutControlUnitCabinet,
	                       stOutHMI => "DB_Interface_HMI".stSystem.stFuse.UH04_400V);
	    END_REGION
	    
	    REGION 24V
	        #fbMonFuse24V.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonFuse24V.stSettings.xSelfQuit := FALSE;
	        #fbMonFuse24V(sInFctnName := 'Sicherungsfall',
	                      sInPrefix := 'UH04 24V',
	                      sInAlarmMessage := 'Sicherung ausgeloest',
	                      sInSuffix := 'DI0021',
	                      wInTextListId_Function := 4,
	                      wInTextListId_Message := 3,
	                      xInQuitError := #stInOutControlUnitCabinet.xQuitError,
	                      xInSignal := "DI0021",
	                      InOutMachineState := #stInOutControlUnitCabinet,
	                      stOutHMI => "DB_Interface_HMI".stSystem.stFuse.UH04_24V);
	    END_REGION
	    
	    
	    REGION Pressure
	        #fbMonPressure.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonPressure.stSettings.xSelfQuit := FALSE;
	        #fbMonPressure(sInFctnName := 'Druckluftueberwachung',
	                       sInPrefix := 'UH04',
	                       sInAlarmMessage := 'Druckluft zu niedrig',
	                       sInSuffix := 'BP0004',
	                       wInTextListId_Function := 5,
	                       wInTextListId_Message := 4,
	                       xInQuitError := #stInOutControlUnitCabinet.xQuitError,
	                       xInSignal := "BP0004",
	                       InOutMachineState := #stInOutControlUnitCabinet,
	                       stOutHMI => "DB_Interface_HMI".stSystem.stPressure.UH04);
	    END_REGION
	    
	    REGION Hauptschütze UH04
	        #fbMonMainContactorsUH04.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonMainContactorsUH04.stSettings.xSelfQuit := FALSE;
	        #fbMonMainContactorsUH04(sInFctnName := 'Hauptschuetzueberwachung',
	                                 sInPrefix := 'UH04',
	                                 sInAlarmMessage := 'Hauptschuetze Fehler',
	                                 sInSuffix := 'QA0610-QA0613',
	                                 wInTextListId_Function := 7,
	                                 wInTextListId_Message := 5,
	                                 xInQuitError := #stInOutControlUnitCabinet.xQuitError,
	                                 xInSignal := "DB_InterfaceSafety".stFromSafety.stMainContactorsUH04.xOk,
	                                 InOutMachineState := #stInOutControlUnitCabinet,
	                                 stOutHMI => "DB_Interface_HMI".stSystem.stMainContactor.UH04);
	    END_REGION
	    
	    REGION Safetyrelais Extern Omniflo
	        #fbMonSafetyContactorsExternOmniflo.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonSafetyContactorsExternOmniflo.stSettings.xSelfQuit := FALSE;
	        #fbMonSafetyContactorsExternOmniflo(sInFctnName := 'Relaisueberwachung',
	                                            sInPrefix := 'UH04->UH06',
	                                            sInAlarmMessage := 'Relais Fehler',
	                                            sInSuffix := 'QA0660/QA0661',
	                                            wInTextListId_Function := 9,
	                                            wInTextListId_Message := 9,
	                                            xInQuitError := #stInOutControlUnitCabinet.xQuitError,
	                                            xInSignal := "DB_InterfaceSafety".stFromSafety.stSafetyContactorsExternOmniflo.xOk,
	                                            InOutMachineState := #stInOutControlUnitCabinet,
	                                            stOutHMI => "DB_Interface_HMI".stSystem.stMainContactor.ExternOmniflo);
	    END_REGION
	    
	    REGION Safetyrelais Extern Reserve
	        #fbMonSafetyContactorsExternReserve.stSettings.xErrLedIfMachineIsOff := TRUE;
	        #fbMonSafetyContactorsExternReserve.stSettings.xSelfQuit := FALSE;
	        #fbMonSafetyContactorsExternReserve(sInFctnName := 'Relaisueberwachung',
	                                            sInPrefix := 'UH04',
	                                            sInAlarmMessage := 'Relais Fehler',
	                                            sInSuffix := 'QA0662/QA0663',
	                                            wInTextListId_Function := 9,
	                                            wInTextListId_Message := 9,
	                                            xInQuitError := #stInOutControlUnitCabinet.xQuitError,
	                                            xInSignal := "DB_InterfaceSafety".stFromSafety.stSafetyContactorsExternReserve.xOk,
	                                            InOutMachineState := #stInOutControlUnitCabinet,
	                                            stOutHMI => "DB_Interface_HMI".stSystem.stMainContactor.ExternReserve);
	    END_REGION
	    
	    REGION Brandschutz
	        
	        REGION FAS 1
	            #fbMonFAS1.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonFAS1.stSettings.xSelfQuit := FALSE;
	            #fbMonFAS1(sInFctnName := 'Feueralarm',
	                       sInPrefix := 'UH04/FAS1',
	                       sInAlarmMessage := 'Feueralarm Signal 1',
	                       sInSuffix := 'DI0034',
	                       wInTextListId_Function := 8,
	                       wInTextListId_Message := 6,
	                       xInQuitError := #stInOutControlUnitCabinet.xQuitError OR "SF0002",
	                       xInSignal := "DI0034",
	                       InOutMachineState := #stInOutControlUnitCabinet,
	                       stOutHMI => "DB_Interface_HMI".stSystem.stFireControl.NoFireAlarmFAS1);
	        END_REGION
	        
	        REGION FAS 2
	            #fbMonFAS2.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonFAS2.stSettings.xSelfQuit := FALSE;
	            #fbMonFAS2(sInFctnName := 'Feueralarm',
	                       sInPrefix := 'UH04/FAS2',
	                       sInAlarmMessage := 'Feueralarm Signal 2',
	                       sInSuffix := 'DI0033',
	                       wInTextListId_Function := 8,
	                       wInTextListId_Message := 6,
	                       xInQuitError := #stInOutControlUnitCabinet.xQuitError OR "SF0002",
	                       xInSignal := "DI0033" OR TRUE,
	                       InOutMachineState := #stInOutControlUnitCabinet,
	                       stOutHMI => "DB_Interface_HMI".stSystem.stFireControl.NoFireAlarmFAS2);
	        END_REGION
	        
	        REGION FPG open
	            #fbMonFPG_Open.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonFPG_Open.stSettings.xSelfQuit := FALSE;
	            #fbMonFPG_Open(sInFctnName := 'Feueralarm',
	                           sInPrefix := 'UH04/FD411',
	                           sInAlarmMessage := 'Tor nicht offen',
	                           sInSuffix := 'DI0037',
	                           wInTextListId_Function := 8,
	                           wInTextListId_Message := 7,
	                           xInQuitError := #stInOutControlUnitCabinet.xQuitError OR "SF0002",
	                           xInSignal := "DI0037",
	                           InOutMachineState := #stInOutControlUnitCabinet,
	                           stOutHMI => "DB_Interface_HMI".stSystem.stFireControl.FPCOpened);
	        END_REGION
	        
	        REGION FPG fault
	            #fbMonFPG_Fault.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonFPG_Fault.stSettings.xSelfQuit := FALSE;
	            #fbMonFPG_Fault(sInFctnName := 'Feueralarm',
	                            sInPrefix := 'UH04/FD411',
	                            sInAlarmMessage := 'Fehler',
	                            sInSuffix := 'DI0036',
	                            wInTextListId_Function := 8,
	                            wInTextListId_Message := 8,
	                            xInQuitError := #stInOutControlUnitCabinet.xQuitError OR "SF0002",
	                            xInSignal := "DI0036",
	                            InOutMachineState := #stInOutControlUnitCabinet,
	                            stOutHMI => "DB_Interface_HMI".stSystem.stFireControl.NoFault);
	        END_REGION
	        
	        REGION FPG Fire
	            #fbMonFPG_Fire.stSettings.xErrLedIfMachineIsOff := TRUE;
	            #fbMonFPG_Fire.stSettings.xSelfQuit := FALSE;
	            #fbMonFPG_Fire(sInFctnName := 'Feueralarm',
	                           sInPrefix := 'UH04/FD411',
	                           sInAlarmMessage := 'Feuer',
	                           sInSuffix := 'DI0035',
	                           wInTextListId_Function := 8,
	                           wInTextListId_Message := 6,
	                           xInQuitError := #stInOutControlUnitCabinet.xQuitError OR "SF0002",
	                           xInSignal := "DI0035",
	                           InOutMachineState := #stInOutControlUnitCabinet,
	                           stOutHMI => "DB_Interface_HMI".stSystem.stFireControl.NoFireAlarmFPG);
	        END_REGION
	        
	    END_REGION
	    
	    REGION MISC (nicht für AllReadyToStart)
	        
	        REGION TCP-Kommunikation
	            REGION Fortna WCS
	                #fbMonCommFortnaWCS.stSettings.xErrLedIfMachineIsOff := TRUE;
	                #fbMonCommFortnaWCS.stSettings.xSelfQuit := TRUE;
	                #fbMonCommFortnaWCS(sInFctnName := 'Kommunikationsfehler',
	                                    sInPrefix := 'UH04',
	                                    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 DeviceHub
	                #fbMonCommFortnaWESDeviceHub.stSettings.xErrLedIfMachineIsOff := TRUE;
	                #fbMonCommFortnaWESDeviceHub.stSettings.xSelfQuit := TRUE;
	                #fbMonCommFortnaWESDeviceHub(sInFctnName := 'Kommunikationsfehler',
	                                             sInPrefix := 'UH04',
	                                             sInSuffix := 'Fortna WES',
	                                             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);
	            END_REGION
	
	        END_REGION
	        
	    END_REGION
	    
	END_REGION
	
	REGION AllReadyToStart
	    
	    #xAllReadyToStart :=
	    #fbMonPhaseFailure.xOutOk AND
	    #fbMonFuse24V.xOutOk AND
	    #fbMonFuse400V.xOutOk AND
	    #fbMonPressure.xOutOk AND
	    #fbMonMotorProtection.xOutOk AND
	    #fbMonMainContactorsUH04.xOutOk AND
	    #fbMonSafetyContactorsExternOmniflo.xOutOk AND
	    #fbMonSafetyContactorsExternReserve.xOutOk AND
	    #fbMonFAS1.xOutOk AND
	    #fbMonFAS2.xOutOk AND
	    #fbMonFPG_Fire.xOutOk AND
	    #fbMonFPG_Fault.xOutOk AND
	    #fbMonFPG_Open.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_UH04.ACK_REQ AND NOT "Main_Safety_RTG1_DB".FDBACK_UH04.ERROR),
	                 xInAllInSafeState := "DB_InterfaceSafety".stFromSafety.EStopMain.Q, //("Main_Safety_RTG1_DB".ESTOP1_Main.Q AND NOT "Main_Safety_RTG1_DB".FDBACK_UH04.ACK_REQ AND NOT "Main_Safety_RTG1_DB".FDBACK_UH04.ERROR),
	                 stInOutControlUnitCabinet := #stInOutControlUnitCabinet,
	                 stInOutHMI := "DB_Interface_HMI".stStateMachine);
	END_REGION
	
	REGION Interface Safety
	    
	    REGION to Safety
	        "DB_InterfaceSafety".stToSafety.xAckGlob := "IBN".xAckGlob OR #fTrigReIntTime.Q;
	        "DB_InterfaceSafety".stToSafety.xMachineRunning := #stInOutControlUnitCabinet.xRunning;
	        "DB_InterfaceSafety".stToSafety.xMachineStarting := #stInOutControlUnitCabinet.xStarting;
	        "DB_InterfaceSafety".stToSafety.xQuitButtonHss := "SF0002" OR #stInOutControlUnitCabinet.xQuitError OR #fTrigReIntTime.Q;
	        "DB_InterfaceSafety".stToSafety.xQuitButtonUZ0409 := "SF0051" OR "IBN".xAckGlob OR #fTrigReIntTime.Q;
	        "DB_InterfaceSafety".stToSafety.stMainContactorsUH04.xFeedback := "DI0013";
	        "DB_InterfaceSafety".stToSafety.stSafetyContactorsExternOmniflo.xFeedback := "DI0014";
	        "DB_InterfaceSafety".stToSafety.stSafetyContactorsExternReserve.xFeedback := "DI0015";
	    END_REGION
	    
	    
	    REGION from Safety
	        ;
	    END_REGION
	    
	END_REGION
	
	REGION Outputs
	    
	    //E-Stop Signalsäule
	    "PF0030" := "SF0003" OR #fbMonFAS1.xOutError
	    OR #fbMonFAS2.xOutError
	    OR #fbMonFPG_Fire.xOutError
	    OR #fbMonFPG_Fault.xOutError
	    OR #fbMonFPG_Open.xOutError
	    OR NOT "DB_InterfaceSafety".stFromSafety.EStopMain.Q;
	    
	    //Anfahrwarnung Signalsäule
	    "PF0033" := #stInOutControlUnitCabinet.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
	    #fbMonMainContactorsUH04.xOutLedError OR
	    #fbMonSafetyContactorsExternOmniflo.xOutLedError OR
	    #fbMonSafetyContactorsExternReserve.xOutLedError;
	    
	    //LED Ein + Signalsäule grün
	    "PF0001" := "PF0032" := "PF0050" := "PF0052" := "PF0054" := "PF0056" := "SF0003" OR (#stInOutControlUnitCabinet.xRunning AND NOT #stInOutControlUnitCabinet.xStartUpWarning) OR
	    (NOT #stInOutControlUnitCabinet.xRunning AND #stInOutControlUnitCabinet.xStartUpWarning);
	    
	    //LED Start nach Störung
	    "PF0002" := "SF0003" OR #arESTOPAck[0].xOutLed (* OR NOT #xAllReadyToStart *)OR
	    (#fbMonMotorProtection.xOutAckReq AND "Clock_1Hz") 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
	    ("DB_InterfaceSafety".stFromSafety.stMainContactorsUH04.xAckReq AND "Clock_1Hz") OR
	    ("DB_InterfaceSafety".stFromSafety.stSafetyContactorsExternOmniflo.xAckReq AND "Clock_1Hz") OR
	    ("DB_InterfaceSafety".stFromSafety.stSafetyContactorsExternReserve.xAckReq AND "Clock_1Hz") OR
	    (#fbMonFAS1.xOutAckReq AND "Clock_1Hz") OR
	    (#fbMonFAS2.xOutAckReq AND "Clock_1Hz") OR
	    (#fbMonFPG_Fire.xOutAckReq AND "Clock_1Hz") OR
	    (#fbMonFPG_Fault.xOutAckReq AND "Clock_1Hz") OR
	    (#fbMonFPG_Open.xOutAckReq AND "Clock_1Hz") OR
	    ("fbMain_DB".fbCarousel4003.xOutGridError 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 #fbMonFAS1.xOutError
	    OR #fbMonFAS2.xOutError
	    OR #fbMonFPG_Fire.xOutError
	    OR #fbMonFPG_Fault.xOutError
	    OR #fbMonFPG_Open.xOutError;
	    
	END_REGION
	
	REGION Not-Halt Tableaues
	    REGION UH04
	        #arESTOPAck[#c_UH04](sInAlarmFunction := 'HSS',
	                             sInAlarmDevice := 'UH04',
	                             sInAlarmMessage := 'Not-Halt aktiv',
	                             sInAlarmSuffix := 'PF0002',
	                             xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopUH04.AckReq,
	                             xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopUH04.Q,
	                             xInAckReqGlobal := (* #arESTOPAck[1].xOutAckReq OR *)
	                             #arESTOPAck[#c_UH04_Extern1].xOutAckReq OR
	                             #arESTOPAck[#c_UH04_Extern2].xOutAckReq,
	                             //#arESTOPAck[4].xOutAckReq OR
	                             xInSafetyNotOkGlobal := (* #arESTOPAck[1].xOutSafetyNotOk OR *)
	                             #arESTOPAck[#c_UH04_Extern1].xOutSafetyNotOk OR
	                             #arESTOPAck[#c_UH04_Extern2].xOutSafetyNotOk,
	                             // #arESTOPAck[4].xOutSafetyNotOk OR
	                             xInMainCabinet := TRUE,
	                             //        xOutLed => "PF0002",
	                             stInOutControlUnitCabinet := #stInOutControlUnitCabinet,
	                             stInOutHmiEstopPanel := "DB_Interface_HMI".arEstops[#c_UH04]);
	    END_REGION
	    
	    REGION UH04 Extern1
	        #arESTOPAck[#c_UH04_Extern1](sInAlarmDevice := 'UH04_Ext1/UH06',
	                                     sInAlarmSuffix := 'PF0002',
	                                     stInOutHmiEstopPanel := "DB_Interface_HMI".arEstops[#c_UH04_Extern1],
	                                     stInOutControlUnitCabinet := #stInOutControlUnitCabinet,
	                                     xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopExternOmniflo.AckReq,
	                                     xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopExternOmniflo.Q);
	        
	    END_REGION
	    
	    REGION UH04 Extern2
	        #arESTOPAck[#c_UH04_Extern2](sInAlarmDevice := 'UH04_Ext2/Res',
	                                     sInAlarmSuffix := 'PF0002',
	                                     stInOutHmiEstopPanel := "DB_Interface_HMI".arEstops[#c_UH04_Extern2],
	                                     stInOutControlUnitCabinet := #stInOutControlUnitCabinet,
	                                     xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopExternReserve.AckReq,
	                                     xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopExternReserve.Q);
	        
	    END_REGION
	    
	    REGION UZ0409
	        #arESTOPAck[#c_UZ0409](sInAlarmFunction := 'Bedientableau',
	                               sInAlarmDevice := 'UZ0409',
	                               sInAlarmMessage := 'Not-Halt aktiv',
	                               sInAlarmSuffix := 'PF0051',
	                               wInTextListId_Function := 1,
	                               wInTextListId_Message := 0,
	                               stInOutHmiEstopPanel := "DB_Interface_HMI".arEstops[#c_UZ0409],
	                               stInOutControlUnitCabinet := #stInOutControlUnitCabinet,
	                               xInAckReqLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0409.AckReq,
	                               xInEstopOkLocal := "DB_InterfaceSafety".stFromSafety.EStopUZ0409.Q);
	        
	        "PF0051" := #arESTOPAck[#c_UZ0409].xOutLed OR "SF0003";
	    END_REGION
	END_REGION
	
	REGION SCADA-Interface
	    "FB-OPC_UA_System-Stat_DB"(nInSystemStat := #fbStateMain.nState, //State Main (Running, Idle, Stopped...)
	                               xInFireAlarm := (#fbMonFAS1.xOutError OR #fbMonFAS2.xOutError OR #fbMonFPG_Fire.xOutError), // Nur Feueralarm
	                               xInSafetyStop := NOT "DB_InterfaceSafety".stFromSafety.EStopMain.Q, // Not-Halt
	                               xInError := "DB_Interface_HMI".nActiveAlarms > 0, //Alle aktiven Meldungen über HMI Interface
	                               xInCommunicationError := #fbMonCommFortnaWCS.xOutError OR #fbMonCommFortnaWESDeviceHub.xOutError,
	                               nOutScadaStatus => "DB_Status".System.Status);
	END_REGION
END_FUNCTION_BLOCK

